Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Trait upcasting ICE with projection in (duplicate) supertrait bound #135463

Closed
steffahn opened this issue Jan 13, 2025 · 5 comments · Fixed by #135498
Closed

Trait upcasting ICE with projection in (duplicate) supertrait bound #135463

steffahn opened this issue Jan 13, 2025 · 5 comments · Fixed by #135498
Assignees
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-trait-objects Area: trait objects, vtable layout C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Jan 13, 2025

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();
}

(playground)

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

@steffahn steffahn added the C-bug Category: This is a bug. label Jan 13, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. A-coercions Area: implicit and explicit `expr as Type` coercions A-trait-objects Area: trait objects, vtable layout F-trait_upcasting `#![feature(trait_upcasting)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 13, 2025
@compiler-errors compiler-errors self-assigned this Jan 14, 2025
@compiler-errors
Copy link
Member

Ty for breaking this out into a separate issue.

@steffahn
Copy link
Member Author

@compiler-errors just to avoid confusion: this is different from #135318 (comment) 😉.

@compiler-errors
Copy link
Member

Nah, it has the same root cause.

@compiler-errors
Copy link
Member

Actually 🤔 wait, this has to do with MIR validation.

@steffahn
Copy link
Member Author

I’ll happily open an issue for #135318 (comment), too, once it actually ICEs on nightly [or if I find a variant of it that already ICEs before #135318].

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 15, 2025
…leteness, r=lcnr

Prefer lower `TraitUpcasting` candidates in selection

Fixes rust-lang#135463. The underlying cause is this ambiguity, but it's more clear (and manifests as a coercion error, rather than a MIR validation error) when it's written the way I did in the UI test.

Sorry this is cursed r? lcnr
@bors bors closed this as completed in b1035d7 Jan 15, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 15, 2025
Rollup merge of rust-lang#135498 - compiler-errors:dyn-upcasting-completeness, r=lcnr

Prefer lower `TraitUpcasting` candidates in selection

Fixes rust-lang#135463. The underlying cause is this ambiguity, but it's more clear (and manifests as a coercion error, rather than a MIR validation error) when it's written the way I did in the UI test.

Sorry this is cursed r? lcnr
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-trait-objects Area: trait objects, vtable layout C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants