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

ICE: None in traits/vtable.rs #131027

Closed
matthiaskrgr opened this issue Sep 29, 2024 · 1 comment · Fixed by #131042
Closed

ICE: None in traits/vtable.rs #131027

matthiaskrgr opened this issue Sep 29, 2024 · 1 comment · Fixed by #131042
Assignees
Labels
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Sep 29, 2024

auto-reduced (treereduce-rust):

#![feature(trait_upcasting)]
trait Supertrait<'a, 'b> {}

trait Subtrait<'a, 'b>: Supertrait<'a, 'b> {}

pub fn ok(x: &dyn for<'a, 'b> Subtrait<'a, 'b>) -> &dyn for<'a> Supertrait<'a, 'a> {
    x
}

pub fn main() {}

original:

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// We should be able to instantiate a binder during trait upcasting.
// This test could be `check-pass`, but we should make sure that we
// do so in both trait solvers.
#![feature(trait_upcasting)]
#![crate_type = "rlib"]
trait Supertrait<'a, 'b> {}

trait Subtrait<'a, 'b>: Supertrait<'a, 'b> {}

impl<'a> Supertrait<'a, 'a> for () {}
impl<'a> Subtrait<'a, 'a> for () {}
fn ok(x: &dyn for<'a, 'b> Subtrait<'a, 'b>) -> &dyn for<'a> Supertrait<'a, 'a> {
    x //~ ERROR mismatched types
    //[current]~^ ERROR mismatched types
}

Version information

rustc 1.83.0-nightly (d194948e5 2024-09-29)
binary: rustc
commit-hash: d194948e50e90f98c62fb64183bce4d866a665af
commit-date: 2024-09-29
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Clink-dead-code=true

Program output

warning: trait `Supertrait` is never used
 --> /tmp/icemaker_global_tempdir.J8Vr9e4vti8H/rustc_testrunner_tmpdir_reporting.0UEEGoO5Wkhs/mvce.rs:3:7
  |
3 | trait Supertrait<'a, 'b> {}
  |       ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: trait `Subtrait` is never used
 --> /tmp/icemaker_global_tempdir.J8Vr9e4vti8H/rustc_testrunner_tmpdir_reporting.0UEEGoO5Wkhs/mvce.rs:5:7
  |
5 | trait Subtrait<'a, 'b>: Supertrait<'a, 'b> {}
  |       ^^^^^^^^

warning: function `ok` is never used
 --> /tmp/icemaker_global_tempdir.J8Vr9e4vti8H/rustc_testrunner_tmpdir_reporting.0UEEGoO5Wkhs/mvce.rs:7:4
  |
7 | fn ok(x: &dyn for<'a, 'b> Subtrait<'a, 'b>) -> &dyn for<'a> Supertrait<'a, 'a> {
  |    ^^

thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/vtable.rs:426:77:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7402f1ccf4ca - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h9a066335bbf3c70b
   1:     0x7402f24033e6 - core::fmt::write::h4d7b6dcfa06e4b7a
   2:     0x7402f35b5bd1 - std::io::Write::write_fmt::h4eb2f351153c62f5
   3:     0x7402f1ccf322 - std::sys::backtrace::BacktraceLock::print::h61d14380f524de24
   4:     0x7402f1cd1841 - std::panicking::default_hook::{{closure}}::hee65cb92729f1c6f
   5:     0x7402f1cd1674 - std::panicking::default_hook::h10225ef2c1ae2cf5
   6:     0x7402f0d9cacf - std[48a393fc970d1838]::panicking::update_hook::<alloc[639799fc786021ce]::boxed::Box<rustc_driver_impl[72d45a44622a3bfe]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7402f1cd1f58 - std::panicking::rust_panic_with_hook::hb124b874e22ff2c5
   8:     0x7402f1cd1cf6 - std::panicking::begin_panic_handler::{{closure}}::h69c13d865db3420d
   9:     0x7402f1ccf979 - std::sys::backtrace::__rust_end_short_backtrace::h435b1bbccf81cd41
  10:     0x7402f1cd19ec - rust_begin_unwind
  11:     0x7402ef5f5bd0 - core::panicking::panic_fmt::haafd805879858244
  12:     0x7402ef4357ec - core::panicking::panic::hc1dd6eb7439635bd
  13:     0x7402efe0cdf9 - core::option::unwrap_failed::heaa361f2da5b5d1a
  14:     0x7402f1b6e761 - rustc_trait_selection[fa1246763012ec30]::traits::vtable::supertrait_vtable_slot
  15:     0x7402f17e5946 - rustc_query_impl[ec7eda03afdf420d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ec7eda03afdf420d]::query_impl::supertrait_vtable_slot::dynamic_query::{closure#2}::{closure#0}, rustc_middle[192bdac49f720747]::query::erase::Erased<[u8; 16usize]>>
  16:     0x7402f17ca559 - <rustc_query_impl[ec7eda03afdf420d]::query_impl::supertrait_vtable_slot::dynamic_query::{closure#2} as core[a5e590a05170c700]::ops::function::FnOnce<(rustc_middle[192bdac49f720747]::ty::context::TyCtxt, (rustc_middle[192bdac49f720747]::ty::Ty, rustc_middle[192bdac49f720747]::ty::Ty))>>::call_once
  17:     0x7402f1741ddc - rustc_query_system[4eeeb108be8c1cc5]::query::plumbing::try_execute_query::<rustc_query_impl[ec7eda03afdf420d]::DynamicConfig<rustc_query_system[4eeeb108be8c1cc5]::query::caches::DefaultCache<(rustc_middle[192bdac49f720747]::ty::Ty, rustc_middle[192bdac49f720747]::ty::Ty), rustc_middle[192bdac49f720747]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[ec7eda03afdf420d]::plumbing::QueryCtxt, false>
  18:     0x7402f18063e2 - rustc_query_impl[ec7eda03afdf420d]::query_impl::supertrait_vtable_slot::get_query_non_incr::__rust_end_short_backtrace
  19:     0x7402f2a3c1b6 - rustc_codegen_ssa[3c131d82a17c56d8]::base::unsized_info::<rustc_codegen_llvm[808d3172d33b3fe]::builder::Builder>
  20:     0x7402f2a3c4d1 - rustc_codegen_ssa[3c131d82a17c56d8]::base::unsize_ptr::<rustc_codegen_llvm[808d3172d33b3fe]::builder::Builder>
  21:     0x7402f2a42ba9 - <rustc_codegen_ssa[3c131d82a17c56d8]::mir::FunctionCx<rustc_codegen_llvm[808d3172d33b3fe]::builder::Builder>>::codegen_rvalue_operand
  22:     0x7402f324c8fe - rustc_codegen_ssa[3c131d82a17c56d8]::mir::codegen_mir::<rustc_codegen_llvm[808d3172d33b3fe]::builder::Builder>
  23:     0x7402f322d335 - rustc_codegen_llvm[808d3172d33b3fe]::base::compile_codegen_unit::module_codegen
  24:     0x7402f31c9553 - <rustc_codegen_llvm[808d3172d33b3fe]::LlvmCodegenBackend as rustc_codegen_ssa[3c131d82a17c56d8]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  25:     0x7402f31c604d - <rustc_codegen_llvm[808d3172d33b3fe]::LlvmCodegenBackend as rustc_codegen_ssa[3c131d82a17c56d8]::traits::backend::CodegenBackend>::codegen_crate
  26:     0x7402f33fc770 - <rustc_interface[c07a9da7023f0850]::queries::Linker>::codegen_and_build_linker
  27:     0x7402f3131e8b - rustc_interface[c07a9da7023f0850]::interface::run_compiler::<core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>, rustc_driver_impl[72d45a44622a3bfe]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7402f31bcc10 - std[48a393fc970d1838]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c07a9da7023f0850]::util::run_in_thread_with_globals<rustc_interface[c07a9da7023f0850]::util::run_in_thread_pool_with_globals<rustc_interface[c07a9da7023f0850]::interface::run_compiler<core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>, rustc_driver_impl[72d45a44622a3bfe]::run_compiler::{closure#0}>::{closure#1}, core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>>::{closure#0}, core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>>
  29:     0x7402f31bd2f0 - <<std[48a393fc970d1838]::thread::Builder>::spawn_unchecked_<rustc_interface[c07a9da7023f0850]::util::run_in_thread_with_globals<rustc_interface[c07a9da7023f0850]::util::run_in_thread_pool_with_globals<rustc_interface[c07a9da7023f0850]::interface::run_compiler<core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>, rustc_driver_impl[72d45a44622a3bfe]::run_compiler::{closure#0}>::{closure#1}, core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>>::{closure#0}, core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a5e590a05170c700]::result::Result<(), rustc_span[28a6cfa051eff088]::ErrorGuaranteed>>::{closure#1} as core[a5e590a05170c700]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7402f31bd6eb - std::sys::pal::unix::thread::Thread::new::thread_start::h8fe6ba811b9bdf93
  31:     0x7402f484739d - <unknown>
  32:     0x7402f48cc49c - <unknown>
  33:                0x0 - <unknown>

error: 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: please make sure that you have updated to the latest nightly

note: rustc 1.83.0-nightly (d194948e5 2024-09-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C link-dead-code=true -Z dump-mir-dir=dir

query stack during panic:
#0 [supertrait_vtable_slot] finding the slot within vtable for trait object `dyn for<'a> Supertrait<'a, 'a>` vtable ptr during trait upcasting coercion from `dyn for<'a, 'b> Subtrait<'a, 'b>` vtable
end of query stack
warning: 3 warnings emitted


@rustbot label +F-trait_upcasting

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. 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. labels Sep 29, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-trait_upcasting `#![feature(trait_upcasting)]` labels Sep 29, 2024
@matthiaskrgr
Copy link
Member Author

bisects to #130866

@compiler-errors compiler-errors self-assigned this Sep 29, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 29, 2024
@bors bors closed this as completed in bf38cae Oct 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 1, 2024
Rollup merge of rust-lang#131042 - compiler-errors:supertrait-vtable, r=lcnr

Instantiate binders in `supertrait_vtable_slot`

`supertrait_vtable_slot` was previously using structural equality when probing for the vtable slot, which led to an ICE since we need a *subtype* match, not an exact match.

Fixes rust-lang#131027

r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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) ❄️ 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