Closed
Description
Code
pub trait TestTrait {
type MyType;
fn func() -> Option<Self> where Self: Sized;
}
impl<T> dyn TestTrait<MyType = T> where Self: Sized {
fn other_func() -> Option<Self> {
match Self::func() {
Some(me) => Some(me),
None => None
}
}
}
This only happens when compiled in a library, not an executable.
The associated type MyType
, both of the where Self: Sized
's, the Option<Self>
(instead of just Self
), and the match statement are all needed to make it panic.
Replacing the match statement with Some(Self::func().unwrap())
errors gracefully, and says that I cannot call unwrap on a trait object; so I assume the error that should have been emitted for the match statement is that I cannot destructure a trait object.
Replacing the match with Self::func()
compiles successfully.
Meta
This happens on stable, nightly, and beta.
rustc --version --verbose
:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0
Error output
error: internal compiler error: compiler/rustc_mir/src/interpret/place.rs:44:17: expected wide pointer extra data (e.g. slice length or trait object vtable)
thread 'rustc' panicked at 'Box<Any>', /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:59:5
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.52.1 (9bc8c42bb 2021-05-09) running on x86_64-apple-darwin
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at src/lib.rs:6:1: 13:2>::other_func`
end of query stack
Backtrace
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::bug
3: rustc_errors::Handler::bug
4: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
5: rustc_middle::ty::context::tls::with_opt::{{closure}}
6: rustc_middle::ty::context::tls::with_opt
7: rustc_middle::util::bug::opt_span_bug_fmt
8: rustc_middle::util::bug::bug_fmt
9: rustc_mir::interpret::eval_context::InterpCx<M>::size_and_align_of
10: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::place_field
11: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_place
12: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
13: <rustc_mir::transform::const_prop::ConstPropagator as rustc_middle::mir::visit::MutVisitor>::visit_statement
14: <rustc_mir::transform::const_prop::ConstPropagator as rustc_middle::mir::visit::MutVisitor>::visit_body
15: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
16: rustc_mir::transform::run_passes
17: rustc_mir::transform::optimized_mir
18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
19: rustc_data_structures::stack::ensure_sufficient_stack
20: rustc_query_system::query::plumbing::force_query_with_job
21: rustc_query_system::query::plumbing::get_query_impl
22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::optimized_mir
23: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
24: rustc_metadata::rmeta::encoder::encode_metadata_impl
25: rustc_data_structures::sync::join
26: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc_middle::middle::cstore::CrateStore for rustc_metadata::creader::CStore>::encode_metadata
27: rustc_middle::ty::context::TyCtxt::encode_metadata
28: rustc_interface::passes::QueryContext::enter
29: rustc_interface::queries::Queries::ongoing_codegen
30: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
31: rustc_span::with_source_map
32: rustc_interface::interface::create_compiler_and_run
33: scoped_tls::ScopedKey<T>::set
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.