rust-lang / rust

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

ICE: `layout mismatch for result of MulWithOverflow` #125772

Open matthiaskrgr opened 3 months ago

matthiaskrgr commented 3 months ago

snippet:

#![feature(generic_const_exprs)]

struct Outer<const A: i64, const B: i64>();
impl<const A: usize, const B: usize> Outer<A, B>
where
    [(); A + (B * 2)]:,
{
    fn i() -> Self {
        Self
    }
}

fn main() {
    Outer::<1, 1>::o();
}

Version information

rustc 1.80.0-nightly (32a3ed229 2024-05-30)
binary: rustc
commit-hash: 32a3ed229caaaa6476ee1b0e644dd53579454536
commit-date: 2024-05-30
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

Program output

``` warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:1:12 | 1 | #![feature(generic_const_exprs)] | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 for more information = note: `#[warn(incomplete_features)]` on by default error: the constant `A` is not of type `i64` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:4:38 | 4 | impl Outer | ^^^^^^^^^^^ expected `i64`, found `usize` | note: required by a bound in `Outer` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:3:14 | 3 | struct Outer(); | ^^^^^^^^^^^^ required by this bound in `Outer` error: the constant `B` is not of type `i64` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:4:38 | 4 | impl Outer | ^^^^^^^^^^^ expected `i64`, found `usize` | note: required by a bound in `Outer` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:3:28 | 3 | struct Outer(); | ^^^^^^^^^^^^ required by this bound in `Outer` error: the constant `A` is not of type `i64` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:8:15 | 8 | fn i() -> Self { | ^^^^ expected `i64`, found `usize` | note: required by a bound in `Outer` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:3:14 | 3 | struct Outer(); | ^^^^^^^^^^^^ required by this bound in `Outer` error: the constant `B` is not of type `i64` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:8:15 | 8 | fn i() -> Self { | ^^^^ expected `i64`, found `usize` | note: required by a bound in `Outer` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:3:28 | 3 | struct Outer(); | ^^^^^^^^^^^^ required by this bound in `Outer` error[E0308]: mismatched types --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:9:9 | 3 | struct Outer(); | ---------------------------------------- `Outer` defines a struct constructor here, which should be called ... 8 | fn i() -> Self { | ---- expected `Outer` because of return type 9 | Self | ^^^^ expected `Outer`, found struct constructor | = note: expected struct `Outer` found struct constructor `fn() -> Outer {Outer::}` help: use parentheses to construct this tuple struct | 9 | Self() | ++ error: the constant `A` is not of type `i64` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:9:9 | 9 | Self | ^^^^ expected `i64`, found `usize` | note: required by a bound in `Outer` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:3:14 | 3 | struct Outer(); | ^^^^^^^^^^^^ required by this bound in `Outer` error: the constant `B` is not of type `i64` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:9:9 | 9 | Self | ^^^^ expected `i64`, found `usize` | note: required by a bound in `Outer` --> /tmp/icemaker_global_tempdir.xEoM7KSB6Agf/rustc_testrunner_tmpdir_reporting.hKrmBMgX97mb/mvce.rs:3:28 | 3 | struct Outer(); | ^^^^^^^^^^^^ required by this bound in `Outer` thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/step.rs:172:17: assertion `left == right` failed: layout mismatch for result of MulWithOverflow left: TyAndLayout { ty: (i64, bool), layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: ScalarPair(Initialized { value: Int(I64, true), valid_range: 0..=18446744073709551615 }, Initialized { value: Int(I8, false), valid_range: 0..=1 }), fields: Arbitrary { offsets: [Size(0 bytes), Size(8 bytes)], memory_index: [0, 1] }, largest_niche: Some(Niche { offset: Size(8 bytes), value: Int(I8, false), valid_range: 0..=1 }), variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes) } } right: TyAndLayout { ty: (usize, bool), layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: ScalarPair(Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }, Initialized { value: Int(I8, false), valid_range: 0..=1 }), fields: Arbitrary { offsets: [Size(0 bytes), Size(8 bytes)], memory_index: [0, 1] }, largest_niche: Some(Niche { offset: Size(8 bytes), value: Int(I8, false), valid_range: 0..=1 }), variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes) } } stack backtrace: 0: 0x778b941d5cc5 - std::backtrace_rs::backtrace::libunwind::trace::h678682a49ad9b996 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x778b941d5cc5 - std::backtrace_rs::backtrace::trace_unsynchronized::hee6fa95bb2553111 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x778b941d5cc5 - std::sys_common::backtrace::_print_fmt::h95e0b5b079a7d050 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/sys_common/backtrace.rs:68:5 3: 0x778b941d5cc5 - ::fmt::h5ef0519e3348f4b3 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/sys_common/backtrace.rs:44:22 4: 0x778b942266bb - core::fmt::rt::Argument::fmt::h351d794db9ebf8d4 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/core/src/fmt/rt.rs:165:63 5: 0x778b942266bb - core::fmt::write::hf6a10f4e291514d0 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/core/src/fmt/mod.rs:1168:21 6: 0x778b941ca99f - std::io::Write::write_fmt::h3774e539b39c6176 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/io/mod.rs:1835:15 7: 0x778b941d5a9e - std::sys_common::backtrace::_print::h0766b9d4e4e1a2a5 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/sys_common/backtrace.rs:47:5 8: 0x778b941d5a9e - std::sys_common::backtrace::print::hf85a15b68fc127ec at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/sys_common/backtrace.rs:34:9 9: 0x778b941d84d9 - std::panicking::default_hook::{{closure}}::hba9aa02e8bae00f0 10: 0x778b941d827a - std::panicking::default_hook::h1795c37d9b50a345 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/panicking.rs:298:9 11: 0x778b90940d00 - std[fbc7945dfe4e847c]::panicking::update_hook::>::{closure#0} 12: 0x778b941d8c0b - as core::ops::function::Fn>::call::hb26c638276518655 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/alloc/src/boxed.rs:2077:9 13: 0x778b941d8c0b - std::panicking::rust_panic_with_hook::h9450536fa6827029 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/panicking.rs:799:13 14: 0x778b941d8984 - std::panicking::begin_panic_handler::{{closure}}::ha4d0dbca7355d76a at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/panicking.rs:664:13 15: 0x778b941d6189 - std::sys_common::backtrace::__rust_end_short_backtrace::h20e49e7e3e79da68 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/sys_common/backtrace.rs:171:18 16: 0x778b941d86b7 - rust_begin_unwind at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/panicking.rs:652:5 17: 0x778b94222c53 - core::panicking::panic_fmt::h731c162467d8bd18 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/core/src/panicking.rs:72:14 18: 0x778b9422324f - core::panicking::assert_failed_inner::h6f0656104af613d4 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/core/src/panicking.rs:403:23 19: 0x778b908b74a3 - core[6d46e2ae36dee942]::panicking::assert_failed::, rustc_target[2bf76cb8f83944e7]::abi::TyAndLayout> 20: 0x778b928a58f3 - >::eval_rvalue_into_place 21: 0x778b8fd37a4d - rustc_const_eval[d725f5dd974c28ec]::const_eval::eval_queries::eval_to_allocation_raw_provider 22: 0x778b923b763c - rustc_query_impl[c0e0181520bdf354]::plumbing::__rust_begin_short_backtrace::> 23: 0x778b923b6e59 - rustc_query_system[a635211d769013fd]::query::plumbing::try_execute_query::, rustc_middle[be94168a967605d5]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[c0e0181520bdf354]::plumbing::QueryCtxt, false> 24: 0x778b923b6a30 - rustc_query_impl[c0e0181520bdf354]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace 25: 0x778b92b6aaf6 - rustc_middle[be94168a967605d5]::query::plumbing::query_get_at::, rustc_middle[be94168a967605d5]::query::erase::Erased<[u8; 24usize]>>> 26: 0x778b92b6adb5 - rustc_const_eval[d725f5dd974c28ec]::const_eval::valtrees::eval_to_valtree 27: 0x778b92b6ad49 - )>>::call_once 28: 0x778b92b6ad00 - rustc_query_impl[c0e0181520bdf354]::plumbing::__rust_begin_short_backtrace::> 29: 0x778b92b6acc1 - )>>::call_once 30: 0x778b923b6f34 - rustc_query_system[a635211d769013fd]::query::plumbing::try_execute_query::, rustc_middle[be94168a967605d5]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[c0e0181520bdf354]::plumbing::QueryCtxt, false> 31: 0x778b923b6858 - rustc_query_impl[c0e0181520bdf354]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace 32: 0x778b927c86f1 - rustc_middle[be94168a967605d5]::query::plumbing::query_get_at::, rustc_middle[be94168a967605d5]::query::erase::Erased<[u8; 24usize]>>> 33: 0x778b928e0bf3 - ::const_eval_global_id_for_typeck 34: 0x778b928e11c2 - ::const_eval_resolve_for_typeck 35: 0x778b90ca0162 - ::const_eval_resolve 36: 0x778b936bde47 - rustc_trait_selection[294db240007bd44b]::traits::const_evaluatable::is_const_evaluatable.cold 37: 0x778b8e8eb8d3 - ::process_obligation 38: 0x778b91e05cf6 - >::process_obligations:: 39: 0x778b9221176b - , ::consider_candidates::{closure#0}>, ::consider_candidates::{closure#1}> as core[6d46e2ae36dee942]::iter::traits::iterator::Iterator>::next 40: 0x778b9220d220 - ::pick_all_method 41: 0x778b90b80290 - ::pick_core 42: 0x778b90b19c25 - , ::probe_for_similar_candidate::{closure#0}::{closure#1}> as core[6d46e2ae36dee942]::iter::traits::iterator::Iterator>::next 43: 0x778b90b81afa - ::probe_for_similar_candidate 44: 0x778b9283dacc - ::probe_for_name 45: 0x778b92846267 - ::check_expr_path 46: 0x778b927e8e0a - ::check_expr_with_expectation_and_args 47: 0x778b927e9c47 - ::check_expr_with_expectation_and_args 48: 0x778b927e57f3 - ::check_block_with_expected 49: 0x778b927ea937 - ::check_expr_with_expectation_and_args 50: 0x778b9219e0d4 - rustc_hir_typeck[27bfc99261d6777a]::check::check_fn 51: 0x778b9219386c - rustc_hir_typeck[27bfc99261d6777a]::typeck 52: 0x778b921932d1 - rustc_query_impl[c0e0181520bdf354]::plumbing::__rust_begin_short_backtrace::> 53: 0x778b9205a86e - rustc_query_system[a635211d769013fd]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[c0e0181520bdf354]::plumbing::QueryCtxt, false> 54: 0x778b92059395 - rustc_query_impl[c0e0181520bdf354]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 55: 0x778b92058fcb - ::par_body_owners::::{closure#0} 56: 0x778b92057a8b - rustc_hir_analysis[9feabfd3ed563fae]::check_crate 57: 0x778b928275fe - rustc_interface[c870be2efde3492c]::passes::analysis 58: 0x778b9282715b - rustc_query_impl[c0e0181520bdf354]::plumbing::__rust_begin_short_backtrace::> 59: 0x778b92b8f725 - rustc_query_system[a635211d769013fd]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[c0e0181520bdf354]::plumbing::QueryCtxt, false> 60: 0x778b92b8f48f - rustc_query_impl[c0e0181520bdf354]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 61: 0x778b92a2120e - rustc_interface[c870be2efde3492c]::interface::run_compiler::, rustc_driver_impl[4c120566f3914dcc]::run_compiler::{closure#0}>::{closure#1} 62: 0x778b929e23c9 - std[fbc7945dfe4e847c]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[4c120566f3914dcc]::run_compiler::{closure#0}>::{closure#1}, core[6d46e2ae36dee942]::result::Result<(), rustc_span[41e37a1bb73e38bc]::ErrorGuaranteed>>::{closure#0}, core[6d46e2ae36dee942]::result::Result<(), rustc_span[41e37a1bb73e38bc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6d46e2ae36dee942]::result::Result<(), rustc_span[41e37a1bb73e38bc]::ErrorGuaranteed>> 63: 0x778b929e2172 - <::spawn_unchecked_, rustc_driver_impl[4c120566f3914dcc]::run_compiler::{closure#0}>::{closure#1}, core[6d46e2ae36dee942]::result::Result<(), rustc_span[41e37a1bb73e38bc]::ErrorGuaranteed>>::{closure#0}, core[6d46e2ae36dee942]::result::Result<(), rustc_span[41e37a1bb73e38bc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6d46e2ae36dee942]::result::Result<(), rustc_span[41e37a1bb73e38bc]::ErrorGuaranteed>>::{closure#2} as core[6d46e2ae36dee942]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 64: 0x778b941e2bfb - as core::ops::function::FnOnce>::call_once::h5d22407a994a8dd7 at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/alloc/src/boxed.rs:2063:9 65: 0x778b941e2bfb - as core::ops::function::FnOnce>::call_once::he08091f4f7e587cf at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/alloc/src/boxed.rs:2063:9 66: 0x778b941e2bfb - std::sys::pal::unix::thread::Thread::new::thread_start::h4ffcec4576023b2b at /rustc/32a3ed229caaaa6476ee1b0e644dd53579454536/library/std/src/sys/pal/unix/thread.rs:108:17 67: 0x778b8d6aa1cf - 68: 0x778b8d72b6ec - 69: 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.80.0-nightly (32a3ed229 2024-05-30) running on x86_64-unknown-linux-gnu query stack during panic: #0 [eval_to_allocation_raw] const-evaluating + checking `::{constant#0}` #1 [eval_to_valtree] evaluating type-level constant end of query stack error: aborting due to 7 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0308`. ```

@rustbot label +F-generic_const_exprs

matthiaskrgr commented 3 months ago

bisects to https://github.com/rust-lang/rust/pull/120847