Skip to content

assertion left == right failed: layout mismatch for result of SubWithOverflow #139246

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

Closed
jjl9807 opened this issue Apr 2, 2025 · 1 comment · May be fixed by #139316
Closed

assertion left == right failed: layout mismatch for result of SubWithOverflow #139246

jjl9807 opened this issue Apr 2, 2025 · 1 comment · May be fixed by #139316
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@jjl9807
Copy link

jjl9807 commented Apr 2, 2025

Code

#![feature(generic_const_exprs)]

type Arr<const N: usize> = [u8; N - 1];

fn test<const N: i64>() -> Arr<N>
where
    [u8; N - 1]: Sized,
{
    todo!()
}

fn main() {
    test::<0>();
}

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (e2014e876 2025-04-01)
binary: rustc
commit-hash: e2014e876e3efaa69bf51c19579adb16c3df5f81
commit-date: 2025-04-01
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.1

Error output

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/step.rs:191:17:
assertion `left == right` failed: layout mismatch for result of SubWithOverflow
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/step.rs:191:17:
assertion `left == right` failed: layout mismatch for result of SubWithOverflow
  left: TyAndLayout { ty: (i64, bool), layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, backend_repr: 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 }), uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 4294967303 } }
 right: TyAndLayout { ty: (usize, bool), layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, backend_repr: 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 }), uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 8589934599 } }
stack backtrace:
   0:     0x7f6d524cce25 - std::backtrace::Backtrace::create::h38afe53d7dc2ee8a
   1:     0x7f6d50862495 - std::backtrace::Backtrace::force_capture::h23772f3a350b6c5f
   2:     0x7f6d4f8ee79f - std[43c66c29bb2da0cf]::panicking::update_hook::<alloc[9d6af472d28301be]::boxed::Box<rustc_driver_impl[2a6f85d55f84b44d]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x7f6d5087bd13 - std::panicking::rust_panic_with_hook::hec08a623892d81df
   4:     0x7f6d5087ba0a - std::panicking::begin_panic_handler::{{closure}}::hb834b9141c0f2230
   5:     0x7f6d50878019 - std::sys::backtrace::__rust_end_short_backtrace::h1dafc29f13d910f2
   6:     0x7f6d5087b6cd - __rustc[e22706cb8dde8ca2]::rust_begin_unwind
   7:     0x7f6d4d29dc90 - core::panicking::panic_fmt::h3e60cc11c74279b0
   8:     0x7f6d4f2ce68a - core::panicking::assert_failed_inner::hc3a4d54eaeabdbdc
   9:     0x7f6d4f82a322 - core[64194c3d1231b2c8]::panicking::assert_failed::<rustc_abi[c759ef77f9aec3cd]::layout::ty::TyAndLayout<rustc_middle[cbfbdec2b42921ad]::ty::Ty>, rustc_abi[c759ef77f9aec3cd]::layout::ty::TyAndLayout<rustc_middle[cbfbdec2b42921ad]::ty::Ty>>
  10:     0x7f6d51f1c317 - <rustc_const_eval[9beadfa2b01a94fc]::interpret::eval_context::InterpCx<rustc_const_eval[9beadfa2b01a94fc]::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
  11:     0x7f6d51ebe70c - rustc_const_eval[9beadfa2b01a94fc]::const_eval::eval_queries::eval_to_allocation_raw_provider
  12:     0x7f6d51ebd24a - rustc_query_impl[514e88206e175c88]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[514e88206e175c88]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 24usize]>>
  13:     0x7f6d51ea26e2 - rustc_query_system[6bf3121dceac80f2]::query::plumbing::try_execute_query::<rustc_query_impl[514e88206e175c88]::DynamicConfig<rustc_query_system[6bf3121dceac80f2]::query::caches::DefaultCache<rustc_middle[cbfbdec2b42921ad]::ty::PseudoCanonicalInput<rustc_middle[cbfbdec2b42921ad]::mir::interpret::GlobalId>, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[514e88206e175c88]::plumbing::QueryCtxt, false>
  14:     0x7f6d51ea22b4 - rustc_query_impl[514e88206e175c88]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  15:     0x7f6d51e9cb76 - rustc_const_eval[9beadfa2b01a94fc]::const_eval::valtrees::eval_to_valtree
  16:     0x7f6d51e9c918 - <rustc_const_eval[9beadfa2b01a94fc]::provide::{closure#0} as core[64194c3d1231b2c8]::ops::function::FnOnce<(rustc_middle[cbfbdec2b42921ad]::ty::context::TyCtxt, rustc_middle[cbfbdec2b42921ad]::ty::PseudoCanonicalInput<rustc_middle[cbfbdec2b42921ad]::mir::interpret::GlobalId>)>>::call_once
  17:     0x7f6d51e9c8c2 - rustc_query_impl[514e88206e175c88]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[514e88206e175c88]::query_impl::eval_to_valtree::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 24usize]>>
  18:     0x7f6d51e9c87b - <rustc_query_impl[514e88206e175c88]::query_impl::eval_to_valtree::dynamic_query::{closure#2} as core[64194c3d1231b2c8]::ops::function::FnOnce<(rustc_middle[cbfbdec2b42921ad]::ty::context::TyCtxt, rustc_middle[cbfbdec2b42921ad]::ty::PseudoCanonicalInput<rustc_middle[cbfbdec2b42921ad]::mir::interpret::GlobalId>)>>::call_once
  19:     0x7f6d51ea27c8 - rustc_query_system[6bf3121dceac80f2]::query::plumbing::try_execute_query::<rustc_query_impl[514e88206e175c88]::DynamicConfig<rustc_query_system[6bf3121dceac80f2]::query::caches::DefaultCache<rustc_middle[cbfbdec2b42921ad]::ty::PseudoCanonicalInput<rustc_middle[cbfbdec2b42921ad]::mir::interpret::GlobalId>, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[514e88206e175c88]::plumbing::QueryCtxt, false>
  20:     0x7f6d51ea21b4 - rustc_query_impl[514e88206e175c88]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7f6d51ba8080 - <rustc_middle[cbfbdec2b42921ad]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  22:     0x7f6d51ba7c31 - <rustc_middle[cbfbdec2b42921ad]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  23:     0x7f6d51ba9a7e - rustc_trait_selection[d9b12b4bf70ffad7]::traits::try_evaluate_const
  24:     0x7f6d52d9d946 - rustc_trait_selection[d9b12b4bf70ffad7]::traits::const_evaluatable::is_const_evaluatable.cold
  25:     0x7f6d51963cad - <rustc_trait_selection[d9b12b4bf70ffad7]::traits::fulfill::FulfillProcessor as rustc_data_structures[af9d6d584b86a654]::obligation_forest::ObligationProcessor>::process_obligation
  26:     0x7f6d51007d29 - <rustc_data_structures[af9d6d584b86a654]::obligation_forest::ObligationForest<rustc_trait_selection[d9b12b4bf70ffad7]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[d9b12b4bf70ffad7]::traits::fulfill::FulfillProcessor>
  27:     0x7f6d511605d4 - <rustc_hir_typeck[f143b67fdfdef807]::fn_ctxt::FnCtxt>::confirm_builtin_call
  28:     0x7f6d51d475a4 - <rustc_hir_typeck[f143b67fdfdef807]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7f6d51d40776 - <rustc_hir_typeck[f143b67fdfdef807]::fn_ctxt::FnCtxt>::check_expr_block
  30:     0x7f6d51d482c6 - <rustc_hir_typeck[f143b67fdfdef807]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x7f6d515b9099 - rustc_hir_typeck[f143b67fdfdef807]::check::check_fn
  32:     0x7f6d515a5fa3 - rustc_hir_typeck[f143b67fdfdef807]::typeck_with_inspect::{closure#0}
  33:     0x7f6d515a4d36 - rustc_query_impl[514e88206e175c88]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[514e88206e175c88]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 8usize]>>
  34:     0x7f6d512ee4ec - rustc_query_system[6bf3121dceac80f2]::query::plumbing::try_execute_query::<rustc_query_impl[514e88206e175c88]::DynamicConfig<rustc_data_structures[af9d6d584b86a654]::vec_cache::VecCache<rustc_span[fb0caa589edbc834]::def_id::LocalDefId, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[6bf3121dceac80f2]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[514e88206e175c88]::plumbing::QueryCtxt, false>
  35:     0x7f6d512ede8b - rustc_query_impl[514e88206e175c88]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7f6d512ec9dc - rustc_hir_analysis[93d6ba5a7e3de542]::check_crate
  37:     0x7f6d518adddd - rustc_interface[ad1617c32d4bf039]::passes::run_required_analyses
  38:     0x7f6d5189c25e - rustc_interface[ad1617c32d4bf039]::passes::analysis
  39:     0x7f6d5189c22d - rustc_query_impl[514e88206e175c88]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[514e88206e175c88]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 0usize]>>
  40:     0x7f6d51fc177d - rustc_query_system[6bf3121dceac80f2]::query::plumbing::try_execute_query::<rustc_query_impl[514e88206e175c88]::DynamicConfig<rustc_query_system[6bf3121dceac80f2]::query::caches::SingleCache<rustc_middle[cbfbdec2b42921ad]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[514e88206e175c88]::plumbing::QueryCtxt, false>
  41:     0x7f6d51fc1478 - rustc_query_impl[514e88206e175c88]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7f6d522e474d - rustc_interface[ad1617c32d4bf039]::passes::create_and_enter_global_ctxt::<core[64194c3d1231b2c8]::option::Option<rustc_interface[ad1617c32d4bf039]::queries::Linker>, rustc_driver_impl[2a6f85d55f84b44d]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  43:     0x7f6d521950ea - rustc_interface[ad1617c32d4bf039]::interface::run_compiler::<(), rustc_driver_impl[2a6f85d55f84b44d]::run_compiler::{closure#0}>::{closure#1}
  44:     0x7f6d521367d2 - std[43c66c29bb2da0cf]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[ad1617c32d4bf039]::util::run_in_thread_with_globals<rustc_interface[ad1617c32d4bf039]::util::run_in_thread_pool_with_globals<rustc_interface[ad1617c32d4bf039]::interface::run_compiler<(), rustc_driver_impl[2a6f85d55f84b44d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  45:     0x7f6d521370b4 - <<std[43c66c29bb2da0cf]::thread::Builder>::spawn_unchecked_<rustc_interface[ad1617c32d4bf039]::util::run_in_thread_with_globals<rustc_interface[ad1617c32d4bf039]::util::run_in_thread_pool_with_globals<rustc_interface[ad1617c32d4bf039]::interface::run_compiler<(), rustc_driver_impl[2a6f85d55f84b44d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[64194c3d1231b2c8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  46:     0x7f6d521384ab - std::sys::pal::unix::thread::Thread::new::thread_start::hc13d05e8634371ab
  47:     0x7f6d4bea81f5 - start_thread
                               at ./nptl/pthread_create.c:442:8
  48:     0x7f6d4bf2889c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81:0
  49:                0x0 - <unknown>


rustc version: 1.88.0-nightly (e2014e876 2025-04-01)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Arr::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
#2 [typeck] type-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack

@jjl9807 jjl9807 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 Apr 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 2, 2025
@matthiaskrgr
Copy link
Member

I think this is a duplicate of #125772 except with - instead of *

@jieyouxu jieyouxu closed this as completed May 1, 2025
@jieyouxu jieyouxu added F-generic_const_exprs `#![feature(generic_const_exprs)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 1, 2025
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-generic_const_exprs `#![feature(generic_const_exprs)]` 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