Skip to content

Lifetimes on nested impl Trait causes ICE #47724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Osspial opened this issue Jan 24, 2018 · 1 comment
Closed

Lifetimes on nested impl Trait causes ICE #47724

Osspial opened this issue Jan 24, 2018 · 1 comment

Comments

@Osspial
Copy link

Osspial commented Jan 24, 2018

Compiling this code:

fn foo<'a>() -> impl Iterator<Item = impl 'a + Iterator<Item=()>> {
    // Body is irrelevant but needed to create a properly-typed return value
    Some(None.into_iter()).into_iter()
}

Crashes the compiler, with the given error message:

error: internal compiler error: librustc\ty\subst.rs:424: Region parameter out of range when substituting in region 'a (root type=None) (index=1)

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.25.0-nightly (4e3901d35 2018-01-23) running on x86_64-pc-windows-msvc

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

thread 'rustc' panicked at 'Box<Any>', librustc_errors\lib.rs:456:9
stack backtrace:
   0: <std::sync::condvar::Condvar as core::fmt::Debug>::fmt
   1: std::panicking::Location::column
   2: std::panicking::Location::column
   3: std::panicking::rust_panic_with_hook
   4: rustc::ty::context::TyCtxt::_intern_substs
   5: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
   6: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
   7: rustc::ty::context::tls::span_debug
   8: rustc::session::bug_fmt
   9: rustc::session::bug_fmt
  10: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_region
  11: rustc::ty::error::<impl rustc::ty::TyS<'tcx>>::sort_string
  12: rustc::middle::lang_items::LanguageItems::items
  13: rustc::ty::GenericPredicates::instantiate_own
  14: rustc::infer::anon_types::Instantiator::fold_anon_ty
  15: rustc::ty::error::<impl rustc::ty::TyS<'tcx>>::sort_string
  16: rustc::ty::error::<impl rustc::ty::TyS<'tcx>>::sort_string
  17: rustc::ty::error::<impl rustc::ty::TyS<'tcx>>::sort_string
  18: rustc::ty::error::<impl rustc::ty::TyS<'tcx>>::sort_string
  19: rustc::infer::anon_types::Instantiator::fold_anon_ty
  20: <rustc_typeck::namespace::Namespace as core::fmt::Debug>::fmt
  21: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_pat
  22: <rustc::hir::Arm as rustc_typeck::check::coercion::AsCoercionSite>::as_coercion_site
  23: <unknown>
  24: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  25: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  26: rustc::dep_graph::graph::DepGraph::assert_ignored
  27: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
  28: <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx
  29: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  30: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  31: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  32: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  33: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  34: rustc::dep_graph::graph::DepGraph::assert_ignored
  35: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
  36: <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx
  37: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::ensure
  38: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  39: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  40: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  41: rustc_typeck::check_crate
  42: <env_logger::filter::Filter as core::fmt::Display>::fmt
  43: <env_logger::filter::Filter as core::fmt::Display>::fmt
  44: rustc_driver::driver::compile_input
  45: rustc_driver::run_compiler
  46: <unknown>
  47: _rust_maybe_catch_panic
  48: <unknown>
  49: <std::sync::condvar::Condvar as core::fmt::Debug>::fmt
  50: std::sys::windows::thread::Thread::new
  51: BaseThreadInitThunk

Removing the lifetime on the inner impl Trait, like so, lets it compile without error:

fn foo<'a>() -> impl Iterator<Item = impl Iterator<Item=()>> {
    Some(None.into_iter()).into_iter()
}

Meta

> rustc --version --verbose
rustc 1.25.0-nightly (4e3901d35 2018-01-23)
binary: rustc
commit-hash: 4e3901d35f6a8652f67111e7272263c9e62ab3e1
commit-date: 2018-01-23
host: x86_64-pc-windows-msvc
release: 1.25.0-nightly
LLVM version: 4.0

Related to #34511 .

@cramertj
Copy link
Member

Dup of #46464

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants