Skip to content

ICE librustc/ty/subst.rs:462: Type parameter DST/#0 (DST/0) out of range when substituting (root type=Some(DST)) substs=[ReErased, T, DST] #55265

New issue

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

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

Already on GitHub? # to your account

Closed
SimonSapin opened this issue Oct 22, 2018 · 4 comments
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.

Comments

@SimonSapin
Copy link
Contributor

struct VTable<DST: ?Sized> {
 _to_dst_ptr: fn(*mut ()) -> *mut DST,
}

trait HasVTableFor<'a, DST: ?Sized 'a> {
 const VTABLE: &'a VTable<DST>;
}

impl<'a, T, DST: ?Sized 'a> HasVTableFor<'a, DST> for T {
 const VTABLE: &'a VTable<DST> = &VTable {
 _to_dst_ptr: |_: *mut ()| unsafe { std::mem::zeroed() },
 };
}

pub fn push<DST: ?Sized, T>() {
 <T as HasVTableFor<DST>>::VTABLE;
}

(Playground)

Errors:

 Compiling playground v0.0.1 (/playground)
warning: path statement with no effect
 --> src/lib.rs:16:5
 |
16 | <T as HasVTableFor<DST>>::VTABLE;
 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 |
 = note: #[warn(path_statements)] on by default

error: internal compiler error: librustc/ty/subst.rs:462: Type parameter `DST/#0` (DST/0) out of range when substituting (root type=Some(DST)) substs=[ReErased, T, DST]

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:538:9
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:71
 at libstd/sys_common/backtrace.rs:59
 2: std::panicking::default_hook::{{closure}}
 at libstd/panicking.rs:211
 3: std::panicking::default_hook
 at libstd/panicking.rs:227
 4: rustc::util::common::panic_hook
 5: std::panicking::rust_panic_with_hook
 at libstd/panicking.rs:480
 6: std::panicking::begin_panic
 7: rustc_errors::Handler::span_bug
 8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
 9: rustc::ty::context::tls::with_opt::{{closure}}
 10: rustc::ty::context::tls::with_context_opt
 11: rustc::ty::context::tls::with_opt
 12: rustc::util::bug::opt_span_bug_fmt
 13: rustc::util::bug::span_bug_fmt
 14: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
 15: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
 16: rustc::ty::fold::TypeFoldable::fold_with
 17: rustc_mir::interpret::cast::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::cast
 18: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::run
 19: rustc_mir::const_eval::eval_body_using_ecx
 20: rustc_mir::const_eval::const_eval_provider
 21: rustc::ty::query::__query_compute::const_eval
 22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
 23: rustc::dep_graph::graph::DepGraph::with_task_impl
 24: rustc::ty::context::tls::with_related_context
 25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
 26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
 27: rustc::ty::query::TyCtxtAt::const_eval
 28: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::global_to_op
 29: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_value_to_op
 30: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_to_op
 31: rustc_mir::transform::const_prop::ConstPropagator::eval_constant
 32: rustc_mir::transform::const_prop::ConstPropagator::const_prop
 33: <rustc_mir::transform::const_prop::ConstPropagator<'b, 'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_statement
 34: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
 35: rustc_mir::transform::optimized_mir::{{closure}}
 36: rustc_mir::transform::optimized_mir
 37: rustc::ty::query::__query_compute::optimized_mir
 38: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::optimized_mir<'tcx>>::compute
 39: rustc::dep_graph::graph::DepGraph::with_task_impl
 40: rustc::ty::context::tls::with_related_context
 41: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
 42: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query
 43: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::optimized_mir
 44: rustc_metadata::encoder::<impl rustc_metadata::isolated_encoder::IsolatedEncoder<'a, 'b, 'tcx>>::encode_optimized_mir
 45: rustc_metadata::encoder::<impl rustc_metadata::isolated_encoder::IsolatedEncoder<'a, 'b, 'tcx>>::encode_info_for_item
 46: rustc::ty::context::tls::with_context
 47: <rustc_metadata::encoder::EncodeVisitor<'a, 'b, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
 48: rustc::hir::Crate::visit_all_item_likes
 49: rustc_metadata::encoder::encode_metadata
 50: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
 51: rustc::ty::context::TyCtxt::encode_metadata
 52: rustc_codegen_llvm::base::write_metadata
 53: rustc::util::common::time
 54: rustc_codegen_llvm::base::codegen_crate
 55: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
 56: rustc::util::common::time
 57: rustc_driver::driver::phase_4_codegen
 58: rustc_driver::driver::compile_input::{{closure}}
 59: rustc::ty::context::tls::enter_context
 60: <std::thread::local::LocalKey<T>>::with
 61: rustc::ty::context::TyCtxt::create_and_enter
 62: rustc_driver::driver::compile_input
 63: rustc_driver::run_compiler_with_pool
 64: rustc_driver::driver::spawn_thread_pool
 65: rustc_driver::run_compiler
 66: <scoped_tls::ScopedKey<T>>::set
 67: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
 68: __rust_maybe_catch_panic
 at libpanic_unwind/lib.rs:102
 69: rustc_driver::run
 70: rustc_driver::main
 71: std::rt::lang_start::{{closure}}
 72: std::panicking::try::do_call
 at libstd/rt.rs:59
 at libstd/panicking.rs:310
 73: __rust_maybe_catch_panic
 at libpanic_unwind/lib.rs:102
 74: std::rt::lang_start_internal
 at libstd/panicking.rs:289
 at libstd/panic.rs:392
 at libstd/rt.rs:58
 75: main
 76: __libc_start_main
 77: <unknown>
query stack during panic:
#0 [const_eval] const-evaluating `<T as HasVTableFor<'a, DST>>::VTABLE`
 --> src/lib.rs:16:5
 |
16 | <T as HasVTableFor<DST>>::VTABLE;
 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#1 [optimized_mir] processing `push`
end of query stack
error: aborting due to previous error


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.31.0-nightly (424a749a0 2018-10-21) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@SimonSapin SimonSapin added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 22, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Oct 22, 2018

Probably a special case of #43408

@SimonSapin
Copy link
Contributor Author

Is it? There is no array involved here, and some very similar code does compile without error: #55266 (comment)

@JohnTitor
Copy link
Member

This is no longer reproduced via the above playground link. We added similar tests in #61666, should we also add tests for this?

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@JohnTitor
Copy link
Member

JohnTitor commented Aug 9, 2019

I tested with this example and grammar fixed one ('a, DST: ?Sized + 'a) but cannot reproduce an ICE on my local (nightly-2018-10-23 and latest) in #63397 (comment). So I'm going to close this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.
Projects
None yet
Development

No branches or pull requests

4 participants