rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.09k stars 12.79k forks source link

[1.22.0-nightly, 2017-09-01] ICE during regular compilation #44309

Closed jjpe closed 7 years ago

jjpe commented 7 years ago

I'm pretty sure this bug is somehow related to the impl trait feature as I was implementing a fn that returns an impl std::iter::Iterator<Item=&Node> for some struct Node. It also seems related to lifetime elision rules, as that is the differentiating factor.

Interestingly, this compiles:

    /// Return a left-to-right iterator over this `Node`'s children
    pub fn child_iter_left<'l>(&'l self) -> impl std::iter::Iterator<Item = &'l Node> {
        self.children_ref().iter()
    }

While this does not:

    /// Return a left-to-right iterator over this `Node`'s children
    pub fn child_iter_left(&self) -> impl std::iter::Iterator<Item = &Node> {
        self.children_ref().iter()
    }

In fact, when I compile using the latter form, I get an ICE:


error: internal compiler error: src/librustc_typeck/check/mod.rs:633: escaping regions in predicate Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: Slice([_]), item_def_id: DefId { krate: CrateNum(2), node: DefIndex(1599) => core/3881d98::iter[0]::iterator[0]::Iterator[0]::Item[0] } }, &Node)),depth=0)
   --> src/lib.rs:432:38
    |
432 |     pub fn child_iter_left(&self) -> impl Iterator<Item = &Node> {
    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.22.0-nightly (f861b6ee4 2017-09-01) running on x86_64-apple-darwin

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

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:439:8
stack backtrace:
   0:        0x11096f113 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::hf3df301931ac253f
   1:        0x11097c25a - std::panicking::default_hook::{{closure}}::hee0e66cc82965672
   2:        0x11097bd58 - std::panicking::default_hook::h5054e86e839146af
   3:        0x11097e522 - std::panicking::rust_panic_with_hook::h1dee2d7c82b5ceee
   4:        0x10b4b244b - std::panicking::begin_panic::h09e56ab400815d26
   5:        0x10b4ae653 - rustc_errors::Handler::span_bug::ha2663d448d325043
   6:        0x10b4e0b46 - rustc::session::opt_span_bug_fmt::{{closure}}::h4f7a07cb5e9cd375
   7:        0x10b4e09d9 - rustc::session::span_bug_fmt::h319de7e2e251bfa5
   8:        0x10b555467 - rustc_typeck::check::Inherited::register_predicate::hcc33038078365417
   9:        0x10b4af7ca - <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty::habae7658bbd2b5ea
  10:        0x10b55eea4 - rustc_typeck::check::check_fn::hef972f534bc9c8cb
  11:        0x10b557a13 - rustc_typeck::check::typeck_tables_of::{{closure}}::h7d04f6d697a6871b
  12:        0x10b557377 - rustc_typeck::check::typeck_tables_of::h1bedb534ea6db1ea
  13:        0x10f38d06f - rustc::dep_graph::graph::DepGraph::with_task::h95c1546b77181f18
  14:        0x10f5da7cb - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get::h676a3a86d08f1aaf
  15:        0x10f63c72f - rustc::ty::maps::TyCtxtAt::typeck_tables_of::hcd86d7eb90e362d3
  16:        0x10f63926e - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of::hb5b76b6f2aef9693
  17:        0x10b55647d - rustc_typeck::check::typeck_item_bodies::h1a9685f9dc12cdaa
  18:        0x10f38f7c3 - rustc::dep_graph::graph::DepGraph::with_task::hfde30d2142cdd51d
  19:        0x10f5d84f7 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get::h76f719d0a195f620
  20:        0x10f63c5dd - rustc::ty::maps::TyCtxtAt::typeck_item_bodies::hb8b8738afcc26d5c
  21:        0x10f63922e - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies::hcd397e46878fb05a
  22:        0x10b5b57ea - rustc_typeck::check_crate::hfd9e5ae323fc4748
  23:        0x10ae1ec2c - rustc::ty::context::TyCtxt::create_and_enter::h2e0d847fa32e4bd0
  24:        0x10ae92424 - rustc_driver::driver::compile_input::ha84eacbdb0971b90
  25:        0x10aeab411 - rustc_driver::run_compiler::h114a92f75300796f
  26:        0x10addb273 - std::sys_common::backtrace::__rust_begin_short_backtrace::hc3473cc726902e01
  27:        0x1109b0ccc - __rust_maybe_catch_panic
  28:        0x10ae11fef - <F as alloc::boxed::FnBox<A>>::call_box::hd9a152e6940302a2
  29:        0x11097b1bb - std::sys::imp::thread::Thread::new::thread_start::h569ec0b87c0a0af3
  30:     0x7fff8efbd059 - _pthread_body
  31:     0x7fff8efbcfd6 - _pthread_start

error: Could not compile `sbr-xquery-parser-api`.
kennytm commented 7 years ago

Duplicate of #42479

Mark-Simulacrum commented 7 years ago

Closing as a duplicate of https://github.com/rust-lang/rust/issues/42479.