Skip to content

ICE in conservative_impl_trait over VecDeque<String> Iterator #42399

@Ruin0x11

Description

@Ruin0x11

The following produces an ICE on nightly:

#![feature(conservative_impl_trait)]

use std::collections::VecDeque;

struct Dude {
    pets: VecDeque<String>
}

impl Dude {
    pub fn new() -> Self {
        let mut pets = VecDeque::new();
        pets.push_front("Ardo".to_string());
        pets.push_front("Jamie".to_string());
        pets.push_front("Bowser".to_string());

        Dude {
            pets: pets
        }
    }

    pub fn iter_pets(&self) -> impl Iterator<Item=&str> {
        self.pets.iter()
    }
}

fn main() {
    let dude = Dude::new();
    for pet in dude.iter_pets() {
        println!("Pet: {}", pet);
    }
}

Backtrace:

error: internal compiler error: src/librustc_typeck/check/mod.rs:582: escaping regions in predicate Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { trait_ref: <_ as std::iter::Iterator>, item_name: Item(100) }, &str)),depth=0)
  --> /var/folders/ps/gxj98yzj1hl7s0nbh2p67yrh0000gn/T/scratch.rs18590rMs:21:32
   |
21 |     pub fn iter_pets(&self) -> impl Iterator<Item=&str> {
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^

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

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:421
stack backtrace:
   0:        0x10e7591a3 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h884a721e113c3303
   1:        0x10e766b78 - std::panicking::default_hook::{{closure}}::h7a7d734b2824d103
   2:        0x10e76673f - std::panicking::default_hook::h3eb11bd6cbfdc331
   3:        0x10e768fc7 - std::panicking::rust_panic_with_hook::h8b9b25777425677b
   4:        0x10cf92a9b - std::panicking::begin_panic::h061689b360c0bfb1
   5:        0x10cf8e566 - rustc_errors::Handler::span_bug::h2b4146ff57268dfc
   6:        0x10cfb764e - rustc::session::opt_span_bug_fmt::{{closure}}::h34cfa07f23f68d87
   7:        0x10cfb74ca - rustc::session::span_bug_fmt::h4f2cfdfd2015bbe7
   8:        0x10d02dc14 - rustc_typeck::check::Inherited::register_predicate::h75c22e95f0c57291
   9:        0x10cf8f671 - <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty::hfc1c4aa50b73a811
  10:        0x10d033131 - rustc_typeck::check::check_fn::hb3437296de08eb34
  11:        0x10d02fc2c - rustc_typeck::check::typeck_tables_of::{{closure}}::h1b6d5d70ecf6005f
  12:        0x10d02f6e5 - rustc_typeck::check::typeck_tables_of::h4c463db39374b891
  13:        0x10d5c5b87 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get::hfdb673b8a48ec6b9
  14:        0x10d5e686a - rustc::ty::maps::TyCtxtAt::typeck_tables_of::hdf5c872430b487bf
  15:        0x10d5e2a3e - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of::h306d67d8b4c45cea
  16:        0x10d02ea5f - rustc_typeck::check::typeck_item_bodies::h8dfd9fcfc53b0892
  17:        0x10d5c4fe0 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get::hf3e901ad43954fdf
  18:        0x10d5e66f6 - rustc::ty::maps::TyCtxtAt::typeck_item_bodies::hc4d4754d193e0320
  19:        0x10d5e2a02 - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies::hc8ecc5004e34ae46
  20:        0x10d08b8c0 - rustc_typeck::check_crate::h775d5fd81d3a9471
  21:        0x109062998 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h0ecedd6aa323696d
  22:        0x1090533ca - rustc_driver::driver::phase_3_run_analysis_passes::h7d4e4be12a652e17
  23:        0x109041910 - rustc_driver::driver::compile_input::h348e0421a5ad9950
  24:        0x109087818 - rustc_driver::run_compiler::hcb92b90602044806
  25:        0x108fb3c8b - std::sys_common::backtrace::__rust_begin_short_backtrace::h77667a403996a54f
  26:        0x10e76c15a - __rust_maybe_catch_panic
  27:        0x108fda02f - <F as alloc::boxed::FnBox<A>>::call_box::hf344d772b8631f42
  28:        0x10e765bf5 - std::sys::imp::thread::Thread::new::thread_start::h993b7e5cb7871f66
  29:        0x10f02baaa - _pthread_body
  30:        0x10f02b9f6 - _pthread_start

$ rustc --version
rustc 1.19.0-nightly (e0cc22b4b 2017-05-31)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions