ICE: librustc/ty/subst.rs:424: Region parameter out of range when substituting in region 'a (root type=None) (index=2)
Started getting an ICE on nightly linux builds in travis for my crate while building various integration tests (I've seen builds fail on different integration tests each time). The ICE has reliably occurred on travis during each restart, however, I've been unable to reproduce it locally via travis docker image (so I can't even begin to attempt to minify my source to something that triggers the error). As far as I can tell, this started with rustc 1.24.0-nightly (8e7a609e6 2018-01-04).
Sample build log can be found here.
Happy to provide more logs build info as needed!
rustc 1.25.0-nightly (61452e506 2018-01-09)
Backtrace:
thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:455:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:68
at libstd/sys_common/backtrace.rs:57
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:381
3: std::panicking::default_hook
at libstd/panicking.rs:391
4: std::panicking::rust_panic_with_hook
at 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::opt_span_bug_fmt
10: rustc::session::span_bug_fmt
11: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_region
12: rustc::ty::fold::TypeFoldable::fold_with
13: rustc::ty::fold::TypeFoldable::fold_with
14: rustc::traits::substitute_normalize_and_test_predicates
15: rustc::ty::maps::<impl rustc::ty::maps::queries::substitute_normalize_and_test_predicates<'tcx>>::compute_result
16: rustc::dep_graph::graph::DepGraph::with_task_impl
17: rustc_errors::Handler::track_diagnostics
18: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
19: rustc::ty::maps::<impl rustc::ty::maps::queries::substitute_normalize_and_test_predicates<'tcx>>::force
20: rustc::ty::maps::<impl rustc::ty::maps::queries::substitute_normalize_and_test_predicates<'tcx>>::try_get
21: rustc::ty::maps::TyCtxtAt::substitute_normalize_and_test_predicates
22: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::substitute_normalize_and_test_predicates
23: <rustc_mir::monomorphize::collector::RootCollector<'b, 'a, 'v> as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
24: rustc::hir::Crate::visit_all_item_likes
25: rustc_mir::monomorphize::collector::collect_crate_mono_items
26: rustc::util::common::time
27: rustc_trans::base::collect_and_partition_translation_items
28: rustc::dep_graph::graph::DepGraph::with_task_impl
29: rustc_errors::Handler::track_diagnostics
30: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
31: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force
32: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get
33: rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items
34: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items
35: rustc_trans::base::trans_crate
36: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
37: rustc::util::common::time
38: rustc_driver::driver::phase_4_translate_to_llvm
39: rustc_driver::driver::compile_input::{{closure}}
40: <std::thread::local::LocalKey<T>>::with
41: <std::thread::local::LocalKey<T>>::with
42: rustc::ty::context::TyCtxt::create_and_enter
43: rustc_driver::driver::compile_input
44: rustc_driver::run_compiler
I've encountered this issue while trying to use cargo-kcov. It looks like it's easily triggered by building openssl v0.10.2 with RUSTFLAGS='-C link-dead-code'.
Build log
⋊> /t/r/openssl on master env RUSTFLAGS='-C link-dead-code' cargo build
Compiling openssl v0.10.2 (file:///tmp/rust-openssl/openssl)
error: internal compiler error: librustc/ty/subst.rs:424: Region parameter out of range when substituting in region 'a (root type=Some(unsafe fn(*mut <Self as foreign_types::ForeignTypeRef>::CType) -> &'a mut Self {<Self as foreign_types::ForeignTypeRef>::from_ptr_mut::<'a>})) (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 (5965b7901 2018-01-19) running on x86_64-unknown-linux-gnu
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:456:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:68
at libstd/sys_common/backtrace.rs:57
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:380
3: std::panicking::default_hook
at libstd/panicking.rs:390
4: std::panicking::rust_panic_with_hook
at libstd/panicking.rs:576
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::opt_span_bug_fmt
10: rustc::session::span_bug_fmt
11: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_region
12: rustc::ty::fold::TypeFoldable::fold_with
13: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
14: rustc::ty::fold::TypeFoldable::fold_with
15: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
16: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
17: rustc::traits::trans::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::trans_apply_param_substs
18: rustc::ty::instance::Instance::ty
19: rustc_trans::trans_item::predefine_fn
20: rustc_trans::trans_item::MonoItemExt::predefine
21: rustc_trans::base::compile_codegen_unit
22: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::compute_result
23: rustc::dep_graph::graph::DepGraph::with_task_impl
24: rustc_errors::Handler::track_diagnostics
25: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
26: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::force
27: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::try_get
28: rustc::ty::maps::TyCtxtAt::compile_codegen_unit
29: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
30: rustc_trans::base::trans_crate
31: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
32: rustc::util::common::time
33: rustc_driver::driver::phase_4_translate_to_llvm
34: rustc_driver::driver::compile_input::{{closure}}
35: <std::thread::local::LocalKey<T>>::with
36: <std::thread::local::LocalKey<T>>::with
37: rustc::ty::context::TyCtxt::create_and_enter
38: rustc_driver::driver::compile_input
39: rustc_driver::run_compiler
error: Could not compile `openssl`.
Thanks for the insight @Mrmaxmeier! I've confirmed that removing the -C link-dead-code flag avoids the ICE, and I can consistently reproduce the issue locally with the flag enabled.
After several false starts, I was able to boil down the ICE to the following case:
pub trait EnvFuture {
type Item;
fn boxed_result<'a>(self) where Self: Sized, Self::Item: 'a, {
}
}
struct Foo;
impl<'a> EnvFuture for &'a Foo {
type Item = ();
}
This will ICE on nightly when run with the -C link-dead-code flag passed to rustc. Same invocation on stable exits with no error, so this is definitely a regression.
another repro that might be related:
on rust playground nightly:
note: rustc 1.25.0-nightly (4e3901d35 2018-01-23) running on x86_64-unknown-linux-gnu
#![feature(generic_associated_types)]
pub trait Foo<'a> {}
pub trait Bar {
type Foo<'a> : Foo<'a>;
fn foo<'a>(&'a self) -> Self::Foo;
}
fn main() {}
EDIT: sorry unrelated theres's another ticket about it #46793
This bug has now regressed into stable 1.24: https://travis-ci.org/ipetkov/conch-runtime/jobs/342033538
triage: P-high
This slipped under the radar. @rust-lang/release -- do you think somebody could bisect this example to get a sense for when the error was introduced? Note that it requires -Clink-dead-code
I bisected across rust-nightly channel. Here is result:
tl;dr: bug appears injected somewhere between commits 0a3761e63 and 8e7a609e6
% rustc +nightly-2018-01-03 --crate-type lib issue-47309.rs -C link-dead-code
% rustc +nightly-2018-01-04 --crate-type lib issue-47309.rs -C link-dead-code
% rustc +nightly-2018-01-05 --crate-type lib issue-47309.rs -C link-dead-code
error: internal compiler error: /checkout/src/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.24.0-nightly (8e7a609e6 2018-01-04) running on x86_64-unknown-linux-gnu
thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:451:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
% rustc +nightly-2018-01-04 --version
rustc 1.24.0-nightly (0a3761e63 2018-01-03)
% rustc +nightly-2018-01-05 --version
rustc 1.24.0-nightly (8e7a609e6 2018-01-04)
%
i guess at least 8e7a609 (#46916) appears relevant ... (and it was backported to beta even...)
That PR fixed another regression (https://github.com/rust-lang/rust/issues/46467), so I don't think we can just revert it...
@pnkfelix yes I remember that change
I've confirmed @pnkfelix's suspicion for sure in that this ICE is caused by https://github.com/rust-lang/rust/pull/46916
triage: assigning to @michaelwoerister to figure out more.
https://github.com/rust-lang/rust/pull/48818 implements a tentative fix for this. The problem is that the monomorphization collector does not account for method lifetime parameters in create_mono_items_for_default_impls().
Most helpful comment
I've encountered this issue while trying to use
cargo-kcov. It looks like it's easily triggered by buildingopenssl v0.10.2withRUSTFLAGS='-C link-dead-code'.Build log