rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.23k stars 12.7k forks source link

ICE: `type variables should not be hashed?` #123953

Open matthiaskrgr opened 6 months ago

matthiaskrgr commented 6 months ago

snippet:

pub trait A {}
pub trait B: A {}

pub trait Mirror {
    type Assoc: ?Sized;
}
impl<T: ?Sized> Mirror for A {
    type Assoc = T;
}

pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
    static
}

Version information

rustc 1.79.0-nightly (29b120740 2024-04-14)
binary: rustc
commit-hash: 29b120740b55aaf2f75e659ba34c4e30977e5fed
commit-date: 2024-04-14
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2

Program output

``` error: expected identifier, found `}` --> /tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs:13:1 | 13 | } | ^ expected identifier error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs:13:2 | 13 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs` warning: trait objects without an explicit `dyn` are deprecated --> /tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs:7:28 | 7 | impl Mirror for A { | ^ | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `#[warn(bare_trait_objects)]` on by default help: if this is an object-safe trait, use `dyn` | 7 | impl Mirror for dyn A { | +++ help: alternatively use a blanket implementation to implement `Mirror` for all types that also implement `A` | 7 | impl Mirror for U { | ++++++ ~ error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates --> /tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs:7:6 | 7 | impl Mirror for A { | ^ unconstrained type parameter error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied --> /tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs:11:62 | 11 | pub fn foo<'a>(x: &'a ::Assoc) -> &'a ::Assoc { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)` | = help: the trait `Mirror` is implemented for `(dyn A + 'static)` error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied --> /tmp/icemaker_global_tempdir.vwQKa8bWL0Ay/rustc_testrunner_tmpdir_reporting.fL12BrT1pnde/mvce.rs:11:101 | 11 | pub fn foo<'a>(x: &'a ::Assoc) -> &'a ::Assoc { | _____________________________________________________________________________________________________^ 12 | | static 13 | | } | |_^ the trait `Mirror` is not implemented for `(dyn B + 'static)` | = help: the trait `Mirror` is implemented for `(dyn A + 'static)` thread 'rustc' panicked at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/compiler/rustc_type_ir/src/ty_kind.rs:709:17: type variables should not be hashed: ?0t stack backtrace: 0: 0x71b7480b6cd5 - std::backtrace_rs::backtrace::libunwind::trace::h53271ac0753cf55e at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x71b7480b6cd5 - std::backtrace_rs::backtrace::trace_unsynchronized::h69024d0ed74410f1 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x71b7480b6cd5 - std::sys_common::backtrace::_print_fmt::h1260662ae5cf245c at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/sys_common/backtrace.rs:68:5 3: 0x71b7480b6cd5 - ::fmt::h364005bab7842cc8 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/sys_common/backtrace.rs:44:22 4: 0x71b748105fbb - core::fmt::rt::Argument::fmt::ha2c788a2abe0d825 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/core/src/fmt/rt.rs:165:63 5: 0x71b748105fbb - core::fmt::write::h54cd3decdbcdebc8 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/core/src/fmt/mod.rs:1157:21 6: 0x71b7480ab85f - std::io::Write::write_fmt::h4b84255e56f703b1 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/io/mod.rs:1832:15 7: 0x71b7480b6aae - std::sys_common::backtrace::_print::hb23c9aa181f7f786 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/sys_common/backtrace.rs:47:5 8: 0x71b7480b6aae - std::sys_common::backtrace::print::h7c2868c5903babcd at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/sys_common/backtrace.rs:34:9 9: 0x71b7480b9429 - std::panicking::default_hook::{{closure}}::h67cd91a3362f6bd2 10: 0x71b7480b916d - std::panicking::default_hook::h863722b1089490b2 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/panicking.rs:291:9 11: 0x71b744a78a1c - std[b6640f56223542f]::panicking::update_hook::>::{closure#0} 12: 0x71b7480b9b2c - as core::ops::function::Fn>::call::h520ed6384e121f6e at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/alloc/src/boxed.rs:2032:9 13: 0x71b7480b9b2c - std::panicking::rust_panic_with_hook::h76677ece9796b2ab at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/panicking.rs:792:13 14: 0x71b7480b98d6 - std::panicking::begin_panic_handler::{{closure}}::h0b1380178bfeecce at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/panicking.rs:657:13 15: 0x71b7480b7199 - std::sys_common::backtrace::__rust_end_short_backtrace::he036971bc710a6c2 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/sys_common/backtrace.rs:171:18 16: 0x71b7480b9607 - rust_begin_unwind at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/panicking.rs:645:5 17: 0x71b748102466 - core::panicking::panic_fmt::hed7cf21e6e33bf06 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/core/src/panicking.rs:72:14 18: 0x71b746256d62 - > as rustc_data_structures[75eb361af5794fb5]::stable_hasher::HashStable>::hash_stable 19: 0x71b746254aeb - > as rustc_data_structures[75eb361af5794fb5]::stable_hasher::HashStable>::hash_stable 20: 0x71b745f59bc8 - rustc_query_system[fadd9b9860a96126]::query::plumbing::try_execute_query::, rustc_middle[f5c2acecf7d1e61]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[89b1cc2b228f800b]::plumbing::QueryCtxt, true> 21: 0x71b745f5939e - rustc_query_impl[89b1cc2b228f800b]::query_impl::try_normalize_generic_arg_after_erasing_regions::get_query_incr::__rust_end_short_backtrace 22: 0x71b7461e2095 - >::try_fold_ty 23: 0x71b7436ae697 - ::run_pass 24: 0x71b745e0188d - rustc_mir_transform[696b6d9cac9f4fe9]::pass_manager::run_passes_inner 25: 0x71b74664a002 - rustc_mir_transform[696b6d9cac9f4fe9]::mir_drops_elaborated_and_const_checked 26: 0x71b74664993d - rustc_query_impl[89b1cc2b228f800b]::plumbing::__rust_begin_short_backtrace::> 27: 0x71b745fd0f52 - rustc_query_system[fadd9b9860a96126]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[89b1cc2b228f800b]::plumbing::QueryCtxt, true> 28: 0x71b74636cbd3 - rustc_query_impl[89b1cc2b228f800b]::query_impl::mir_drops_elaborated_and_const_checked::get_query_incr::__rust_end_short_backtrace 29: 0x71b7466ca5d3 - rustc_interface[7cece484144cab9d]::passes::analysis 30: 0x71b7466c93d5 - rustc_query_impl[89b1cc2b228f800b]::plumbing::__rust_begin_short_backtrace::> 31: 0x71b746bd604a - rustc_query_system[fadd9b9860a96126]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[89b1cc2b228f800b]::plumbing::QueryCtxt, true> 32: 0x71b746bd5c5c - rustc_query_impl[89b1cc2b228f800b]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 33: 0x71b746a7d213 - rustc_interface[7cece484144cab9d]::interface::run_compiler::, rustc_driver_impl[1eded89cf714ec14]::run_compiler::{closure#0}>::{closure#0} 34: 0x71b746b5225d - std[b6640f56223542f]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[1eded89cf714ec14]::run_compiler::{closure#0}>::{closure#0}, core[67782cd00b4ae476]::result::Result<(), rustc_span[67999189de00f189]::ErrorGuaranteed>>::{closure#0}, core[67782cd00b4ae476]::result::Result<(), rustc_span[67999189de00f189]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[67782cd00b4ae476]::result::Result<(), rustc_span[67999189de00f189]::ErrorGuaranteed>> 35: 0x71b746b5206a - <::spawn_unchecked_, rustc_driver_impl[1eded89cf714ec14]::run_compiler::{closure#0}>::{closure#0}, core[67782cd00b4ae476]::result::Result<(), rustc_span[67999189de00f189]::ErrorGuaranteed>>::{closure#0}, core[67782cd00b4ae476]::result::Result<(), rustc_span[67999189de00f189]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[67782cd00b4ae476]::result::Result<(), rustc_span[67999189de00f189]::ErrorGuaranteed>>::{closure#2} as core[67782cd00b4ae476]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 36: 0x71b7480c3a1b - as core::ops::function::FnOnce>::call_once::h44537915e24e94b0 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/alloc/src/boxed.rs:2018:9 37: 0x71b7480c3a1b - as core::ops::function::FnOnce>::call_once::h23d4047ab6dcc0a1 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/alloc/src/boxed.rs:2018:9 38: 0x71b7480c3a1b - std::sys::pal::unix::thread::Thread::new::thread_start::h3b8c7af00c7c77e5 at /rustc/29b120740b55aaf2f75e659ba34c4e30977e5fed/library/std/src/sys/pal/unix/thread.rs:108:17 39: 0x71b7418a955a - 40: 0x71b741926a3c - 41: 0x0 - 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.79.0-nightly (29b120740 2024-04-14) running on x86_64-unknown-linux-gnu note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 query stack during panic: #0 [try_normalize_generic_arg_after_erasing_regions] normalizing `&::Assoc` #1 [mir_drops_elaborated_and_const_checked] elaborating drops for `foo` #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 5 previous errors; 1 warning emitted Some errors have detailed explanations: E0207, E0277, E0601. For more information about an error, try `rustc --explain E0207`. ```

cushionbadak commented 6 months ago

searched nightlies: from nightly-2024-01-01 to nightly-2024-04-16 regressed nightly: nightly-2024-03-08 searched commit range: https://github.com/rust-lang/rust/compare/7d3702e472b99be0f5de6608dd87af1df8f99428...9c3ad802d9b9633d60d3a74668eb1be819212d34 regressed commit: https://github.com/rust-lang/rust/commit/8c9a75b3238b66592779d6b240dbf78eacefebb8

bisected with cargo-bisect-rustc v0.6.8 Host triple: x86_64-apple-darwin Reproduce with: ```bash cargo bisect-rustc --start=2024-01-01 --end=2024-04-16 --preserve --regress=ice ```

The regressed commit points to #121154

By the way, I suggest we consider closing issue #109864 if we're good to go

pacak commented 5 months ago

One more example for the same ICE

use std::ops::Mul;

struct Matrix <const M: usize, const N: usize>;
impl<'a,  const M: usize, const P: usize> Mul for &'a Matrix<M, M> {
    type Output = Matrix<M, P>;

    fn mul(self, other: &Matrix<M, P>) -> Self::Output {
        loop {}
    }
}