Closed
Description
This code ICEs only in release mode:
#![feature(trait_upcasting)]
trait Supertrait<T> {
fn method(&self) {}
}
impl<T> Supertrait<T> for () {}
trait Identity {
type Selff;
}
impl<Selff> Identity for Selff {
type Selff = Selff;
}
trait Trait<P>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}
impl<P> Trait<P> for () {}
fn upcast<P>(x: &dyn Trait<P>) -> &dyn Supertrait<()> {
x
}
fn main() {
upcast::<()>(&()).method();
}
It doesn't ICE on debug builds. It also doesn't ICE, if P
doesn't match the ()
type, e.g. if the call is changed to upcast::<u8>…
.
Tested on nightly, and also on #135318:
(As of this writing) this ICE is not fixed in #135318 either.
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:646:17:
`trimmed_def_paths` called, diagnostics were expected but none were emitted. Use `with_no_trimmed_paths` for debugging. Backtraces are currently disabled: set `RUST_BACKTRACE=1` and re-run to see where it happened.
stack backtrace:
0: 0x74fb568f872a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::heeeab96efd312504
1: 0x74fb57012d26 - core::fmt::write::hc5affe1a961fb87a
2: 0x74fb57f98d91 - std::io::Write::write_fmt::h8190bce8dcf4a154
3: 0x74fb568f8582 - std::sys::backtrace::BacktraceLock::print::h8064f6c690594717
4: 0x74fb568fab27 - std::panicking::default_hook::{{closure}}::h733c6fe54345b370
5: 0x74fb568fa910 - std::panicking::default_hook::h4e4a01d045e6d2c7
6: 0x74fb55a5fc68 - std[d57b542980c61ed0]::panicking::update_hook::<alloc[99f5d28b839bf241]::boxed::Box<rustc_driver_impl[4a0a86913583d400]::install_ice_hook::{closure#1}>>::{closure#0}
7: 0x74fb568fb3b3 - std::panicking::rust_panic_with_hook::he9f7cf885214d25c
8: 0x74fb568fb0aa - std::panicking::begin_panic_handler::{{closure}}::h4d6c5fb80f85e7bb
9: 0x74fb568f8c09 - std::sys::backtrace::__rust_end_short_backtrace::hffa8d1b42ba446b2
10: 0x74fb568fad6d - rust_begin_unwind
11: 0x74fb535a56d0 - core::panicking::panic_fmt::hc170e60ce3249b4f
12: 0x74fb57e88031 - <rustc_errors[7e07cb41e763bd24]::DiagCtxtInner as core[7cf2ec004b4a7e06]::ops::drop::Drop>::drop
13: 0x74fb57e88b5c - core[7cf2ec004b4a7e06]::ptr::drop_in_place::<rustc_errors[7e07cb41e763bd24]::DiagCtxt>
14: 0x74fb5800f05a - core[7cf2ec004b4a7e06]::ptr::drop_in_place::<rustc_session[8075de0c713ecf73]::parse::ParseSess>
15: 0x74fb5800ffe0 - core[7cf2ec004b4a7e06]::ptr::drop_in_place::<rustc_interface[18d7993094f7ee66]::interface::Compiler>
16: 0x74fb5800452d - rustc_interface[18d7993094f7ee66]::interface::run_compiler::<(), rustc_driver_impl[4a0a86913583d400]::run_compiler::{closure#0}>::{closure#1}
17: 0x74fb57e8b755 - std[d57b542980c61ed0]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[18d7993094f7ee66]::util::run_in_thread_with_globals<rustc_interface[18d7993094f7ee66]::util::run_in_thread_pool_with_globals<rustc_interface[18d7993094f7ee66]::interface::run_compiler<(), rustc_driver_impl[4a0a86913583d400]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
18: 0x74fb57e8bc04 - <<std[d57b542980c61ed0]::thread::Builder>::spawn_unchecked_<rustc_interface[18d7993094f7ee66]::util::run_in_thread_with_globals<rustc_interface[18d7993094f7ee66]::util::run_in_thread_pool_with_globals<rustc_interface[18d7993094f7ee66]::interface::run_compiler<(), rustc_driver_impl[4a0a86913583d400]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7cf2ec004b4a7e06]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
19: 0x74fb57e8d1c1 - std::sys::pal::unix::thread::Thread::new::thread_start::hf232c9576e29b140
20: 0x74fb59758a94 - <unknown>
21: 0x74fb597e5a34 - clone
22: 0x0 - <unknown>
error: the compiler unexpectedly panicked. this is a bug.
@rustbot label requires-nightly, T-compiler, I-ICE, F-trait_upcasting, A-trait-objects, A-coercions
Metadata
Metadata
Assignees
Labels
Area: implicit and explicit `expr as Type` coercionsArea: trait objects, vtable layoutCategory: This is a bug.`#![feature(trait_upcasting)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.