Skip to content

Compiler panic when using impl Iterator<Item = &PathBuf> #46178

Closed
@linclelinkpart5

Description

@linclelinkpart5

In my impl for a struct I'm working on, I have this:

    pub fn get_contains_dir<P: AsRef<Path>>(&self, rel_item_path: P) -> Option<PathBuf> {
        if let Ok((rel, abs)) = self.co_norm(rel_item_path) {
            if abs.is_dir() {
                return Some(rel)
            }
        }

        None
    }

    pub fn iter_contains_dir<P: AsRef<Path>>(&self, rel_item_path: P) -> impl Iterator<Item = &PathBuf> {
        self.get_contains_dir(rel_item_path).iter()
    }

When attempting to compile, I get this error (backtrace also included):

error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:634: escaping regions in predicate Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: Slice([_]), item_def_id: DefId { krate: CrateNum(2), index: DefIndex(0:1693) => core[373c]::iter[0]::iterator[0]::Iterator[0]::Item[0] } }, &std::path::PathBuf)),depth=0)
   --> src/library.rs:191:74
    |
191 |     pub fn iter_contains_dir<P: AsRef<Path>>(&self, rel_item_path: P) -> impl Iterator<Item = &PathBuf> {
    |                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.23.0-nightly (33374fa9d 2017-11-20) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:418:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:68
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:57
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: <std::thread::local::LocalKey<T>>::with
   8: rustc::ty::context::tls::with_opt
   9: rustc::session::span_bug_fmt
  10: rustc_typeck::check::Inherited::register_predicate
  11: <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  12: rustc_typeck::check::check_fn
  13: <std::thread::local::LocalKey<T>>::with
  14: rustc::ty::context::GlobalCtxt::enter_local
  15: _ZN12rustc_typeck5check16typeck_tables_of17h25d2aec5684f9308E.llvm.7E26391B
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute_result
  17: _ZN5rustc9dep_graph5graph8DepGraph14with_task_impl17h47839a3014380fe2E.llvm.9C4F6362
  18: rustc_errors::Handler::track_diagnostics
  19: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  22: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  23: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  24: rustc::session::Session::track_errors
  25: _ZN12rustc_typeck5check18typeck_item_bodies17hd21b7190cdf37897E.llvm.7E26391B
  26: _ZN5rustc9dep_graph5graph8DepGraph14with_task_impl17hbd23d0600cb4f79bE.llvm.9C4F6362
  27: rustc_errors::Handler::track_diagnostics
  28: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  29: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force
  30: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  31: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  32: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  33: rustc_typeck::check_crate
  34: <std::thread::local::LocalKey<T>>::with
  35: <std::thread::local::LocalKey<T>>::with
  36: rustc::ty::context::TyCtxt::create_and_enter
  37: rustc_driver::driver::compile_input
  38: rustc_driver::run_compiler

Output of rustc --version --verbose:

rustc 1.23.0-nightly (33374fa9d 2017-11-20)
binary: rustc
commit-hash: 33374fa9d09e2a790979b31e61100dfed4b44139
commit-date: 2017-11-20
host: x86_64-unknown-linux-gnu
release: 1.23.0-nightly
LLVM version: 4.0

Activity

cramertj

cramertj commented on Nov 22, 2017

@cramertj
Member

Lifetime elision isn't handled properly for impl Trait types right now. It's sort of an open question how this should behave (see #43396), however it definitely shouldn't ICE 😄.

kennytm

kennytm commented on Nov 22, 2017

@kennytm
Member

Closing as duplicate of #42479 and #43396.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kennytm@linclelinkpart5@cramertj

        Issue actions

          Compiler panic when using `impl Iterator<Item = &PathBuf>` · Issue #46178 · rust-lang/rust