Closed
Description
The following code creates a trait (creatively named Trait
) that has an associated type (creatively named Type
). An default implementation of this trait is given for all types, with Type = [u8; 1]
. Specializing the trait (for *const T
, for example) works, except that doing size_of::<<T as Trait>::Type>()
causes an ICE.
#![feature(specialization)]
pub trait Trait {
type Type;
}
impl<T: ?Sized> Trait for T {
default type Type = [u8; 1];
}
impl<T: Trait> Trait for *const T {
type Type = [u8; std::mem::size_of::<<T as Trait>::Type>()];
}
Expected behavior: I believe this code should compile just fine, with *const T
's Trait::Type
being equivalent to to T
's Trait::Type
.
Actual behavior: ICE: error: internal compiler error: librustc/ty/subst.rs:479: Type parameter
T/#0 (T/0) out of range when substituting (root type=Some(fn() -> usize {std::mem::size_of::<<T as Trait>::Type>})) substs=[]
Rust version: rustc --version --verbose:
rustc 1.28.0-nightly (cd494c1f0 2018-06-27)
binary: rustc
commit-hash: cd494c1f0915da00a63c03454a96d504afe764ff
commit-date: 2018-06-27
host: x86_64-apple-darwin
release: 1.28.0-nightly
LLVM version: 6.0
Backtrace:
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499:9
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
6: std::panicking::begin_panic
7: rustc_errors::Handler::span_bug
8: rustc::session::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::session::opt_span_bug_fmt
13: rustc::session::span_bug_fmt
14: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
15: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
16: rustc::ty::fold::TypeFoldable::fold_with
17: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
18: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
19: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
20: rustc::ty::fold::TypeFoldable::fold_with
21: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
22: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
23: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_operand
24: rustc_mir::interpret::terminator::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_terminator
25: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::step
26: rustc_mir::interpret::const_eval::eval_body_using_ecx
27: rustc_mir::interpret::const_eval::const_eval_provider
28: rustc::ty::query::__query_compute::const_eval
29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
30: rustc::ty::context::tls::with_context
31: rustc::dep_graph::graph::DepGraph::with_task_impl
32: rustc::ty::context::tls::with_related_context
33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
35: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
36: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
37: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
38: rustc::traits::project::opt_normalize_projection_type
39: rustc::traits::project::normalize_projection_type
40: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
41: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
42: rustc::ty::fold::TypeFoldable::fold_with
43: rustc::ty::fold::TypeFoldable::fold_with
44: rustc::ty::fold::TypeFoldable::fold_with
45: rustc::traits::project::normalize
46: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once
47: <core::iter::FlatMap<I, U, F> as core::iter::iterator::Iterator>::next
48: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
49: rustc::ty::wf::WfPredicates::normalize
50: rustc::ty::wf::trait_obligations
51: rustc::ty::context::tls::with_related_context
52: rustc::infer::InferCtxtBuilder::enter
53: rustc_typeck::check::wfcheck::check_item_well_formed
54: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_item_well_formed<'tcx>>::compute
55: rustc::ty::context::tls::with_context
56: rustc::dep_graph::graph::DepGraph::with_task_impl
57: rustc::ty::context::tls::with_related_context
58: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
61: rustc::hir::Crate::visit_all_item_likes
62: rustc::session::Session::track_errors
63: rustc::util::common::time
64: rustc_typeck::check_crate
65: rustc::ty::context::tls::enter_context
66: <std::thread::local::LocalKey<T>>::with
67: rustc::ty::context::TyCtxt::create_and_enter
68: rustc_driver::driver::compile_input
69: rustc_driver::run_compiler_with_pool
70: <scoped_tls::ScopedKey<T>>::set
71: syntax::with_globals
72: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
73: __rust_maybe_catch_panic
74: rustc_driver::run
75: rustc_driver::main
76: std::rt::lang_start::{{closure}}
77: std::panicking::try::do_call
78: __rust_maybe_catch_panic
79: std::rt::lang_start_internal
80: main
query stack during panic:
#0 [const_eval] const-evaluating `<*const T as TypeEncoding>::Type::{{constant}}`
#1 [check_item_well_formed] processing `<*const T as TypeEncoding>`
end of query stack
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Trait impl specializationCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(specialization)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.