Skip to content
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

ICE: src\librustc\ty\subst.rs:496: Region parameter out of range when substituting in region 'a #69136

Closed
steffahn opened this issue Feb 13, 2020 · 0 comments · Fixed by #72080
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Feb 13, 2020

Code

#![feature(type_alias_impl_trait)]

trait SomeTrait where {}

trait WithAssoc<A> where {
	type AssocType;
}

type Return<A> // 'a is not in scope
 = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;

fn my_fun() -> Return<()> {}

fn main() {}

Meta

Appears since nightly-2020-02-14. More precisely, the ICE appears since #69008 was merged.
Possibly related to #67844.
Note that the code should not compile.

Error output

error[E0261]: use of undeclared lifetime name `'a`
  --> src/main.rs:11:51
   |
10 | type Return<A> // 'a is not in scope
   |             - help: consider introducing lifetime `'a` here: `'a,`
11 |  = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
   |                                                   ^^ undeclared lifetime

error: internal compiler error: src/librustc/ty/subst.rs:496: Region parameter out of range when substituting in region 'a (root type=None) (index=0)

thread 'rustc' panicked at 'Box<Any>', <::std::macros::panic macros>:2:4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.43.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0261`.

Backtrace

error[E0261]: use of undeclared lifetime name `'a`
  --> src/main.rs:11:51
   |
10 | type Return<A> // 'a is not in scope
   |             - help: consider introducing lifetime `'a` here: `'a,`
11 |  = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
   |                                                   ^^ undeclared lifetime

error: internal compiler error: src/librustc/ty/subst.rs:496: Region parameter out of range when substituting in region 'a (root type=None) (index=0)

thread 'rustc' panicked at 'Box<Any>', <::std::macros::panic macros>:2:4
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::sys_common::backtrace::print
   4: std::panicking::default_hook::{{closure}}
   5: std::panicking::default_hook
   6: rustc_driver::report_ice
   7: std::panicking::rust_panic_with_hook
   8: std::panicking::begin_panic
   9: rustc_errors::HandlerInner::span_bug
  10: rustc_errors::Handler::span_bug
  11: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  12: rustc::ty::context::tls::with_opt::{{closure}}
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::span_bug_fmt
  16: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_region
  17: rustc::ty::fold::TypeFoldable::fold_with
  18: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_binder
  19: rustc::ty::subst::Subst::subst
  20: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  21: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::spec_extend
  22: rustc::ty::GenericPredicates::instantiate_into
  23: rustc::ty::GenericPredicates::instantiate
  24: rustc::infer::opaque_types::Instantiator::fold_opaque_ty
  25: <rustc::ty::fold::BottomUpFolder<F,G,H> as rustc::ty::fold::TypeFolder>::fold_ty
  26: rustc::ty::fold::TypeFoldable::fold_with
  27: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for rustc::ty::sty::Binder<T>>::fold_with
  28: rustc::ty::fold::TypeFoldable::fold_with
  29: rustc::infer::opaque_types::Instantiator::instantiate_opaque_types_in_map
  30: rustc::infer::opaque_types::Instantiator::fold_opaque_ty
  31: <rustc::ty::fold::BottomUpFolder<F,G,H> as rustc::ty::fold::TypeFolder>::fold_ty
  32: rustc::infer::opaque_types::Instantiator::instantiate_opaque_types_in_map
  33: rustc::infer::opaque_types::<impl rustc::infer::InferCtxt>::instantiate_opaque_types
  34: rustc_typeck::check::FnCtxt::instantiate_opaque_types_from_value
  35: rustc_typeck::check::check_fn
  36: rustc::ty::context::GlobalCtxt::enter_local
  37: rustc::infer::InferCtxtBuilder::enter
  38: rustc_typeck::check::typeck_tables_of_with_fallback
  39: rustc_typeck::check::typeck_tables_of
  40: rustc::ty::query::__query_compute::typeck_tables_of
  41: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  42: rustc::dep_graph::graph::DepGraph::with_task_impl
  43: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  44: rustc_typeck::collect::find_opaque_ty_constraints::ConstraintLocator::check
  45: <rustc_typeck::collect::find_opaque_ty_constraints::ConstraintLocator as rustc_hir::intravisit::Visitor>::visit_item
  46: rustc_hir::intravisit::walk_crate
  47: rustc_typeck::collect::find_opaque_ty_constraints
  48: rustc_typeck::collect::type_of
  49: rustc::ty::query::__query_compute::type_of
  50: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::type_of>::compute
  51: rustc::dep_graph::graph::DepGraph::with_task_impl
  52: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  53: <rustc_typeck::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_item
  54: rustc::hir::map::Map::visit_item_likes_in_module
  55: rustc_typeck::collect::collect_mod_item_types
  56: rustc::ty::query::__query_compute::collect_mod_item_types
  57: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_mod_item_types>::compute
  58: rustc::dep_graph::graph::DepGraph::with_task_impl
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  61: rustc_session::session::Session::track_errors
  62: rustc_typeck::check_crate
  63: rustc_interface::passes::analysis
  64: rustc::ty::query::__query_compute::analysis
  65: rustc::dep_graph::graph::DepGraph::with_eval_always_task
  66: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  67: rustc::ty::context::tls::enter_global
  68: rustc_interface::interface::run_compiler_in_existing_thread_pool
  69: scoped_tls::ScopedKey<T>::set
  70: syntax::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.43.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck_tables_of] processing `my_fun`
#1 [type_of] processing `Return`
#2 [collect_mod_item_types] collecting item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0261`.

@steffahn steffahn added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 13, 2020
@jonas-schievink jonas-schievink added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Feb 13, 2020
@steffahn steffahn changed the title ICE: Region parameter out of range when substituting in region 'a ICE: src\librustc\ty\subst.rs:496: Region parameter out of range when substituting in region 'a Feb 14, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 14, 2020
Aaron1011 added a commit to Aaron1011/rust that referenced this issue Feb 17, 2020
Fixes rust-lang#69136

Previously, lifetime resolution errors would cause an error to be
emitted, but would not mark the parent type as 'tainted' in any way.
We usually abort compilation before this becomes an issue - however,
opaque types can cause us to type-check function bodies before such an
abort occurs. Ths can result in trying to instantiate opaque types that
have invalid computed generics. Currently, this only causes issues for
nested opaque types, but there's no reason to expect the computed
generics to be sane when we had unresolved lifetimes (which can result
in extra lifetime parameters getting added to the generics).

This commit tracks 'unresolved lifetime' errors that occur during
lifetime resolution. When we type-check an item, we bail out and return
`tcx.types.err` if a lifetime error was reported for that type. This
causes us to skip type-checking of types affected by the lifetime error,
while still checking unrelated types.

Additionally, we now check for errors in 'parent' opaque types (if such
a 'parent' exists) when collecting constraints for opaque types. This
reflects the fact that opaque types inherit generics from 'parent'
opaque types - if an error ocurred while type-checking the parent,
we don't attempt to type-check the child.
RalfJung added a commit to RalfJung/rust that referenced this issue Jun 11, 2020
…=nikomatsakis

Clean up type alias impl trait implementation

- Removes special case for top-level impl trait
- Removes associated opaque types
- Forbid lifetime elision in let position impl trait. This is consistent with the behavior for inferred types.
- Handle lifetimes in type alias impl trait more uniformly with other parameters

cc rust-lang#69323
cc rust-lang#63063
Closes rust-lang#57188
Closes rust-lang#62988
Closes rust-lang#69136
@bors bors closed this as completed in ce6d3a7 Jun 15, 2020
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 23, 2020
…ikomatsakis

Clean up type alias impl trait implementation

- Removes special case for top-level impl trait
- Removes associated opaque types
- Forbid lifetime elision in let position impl trait. This is consistent with the behavior for inferred types.
- Handle lifetimes in type alias impl trait more uniformly with other parameters

cc rust-lang#69323
cc rust-lang#63063
Closes rust-lang#57188
Closes rust-lang#62988
Closes rust-lang#69136
Closes rust-lang#73061
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
3 participants