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: expected int of size 8, but got size 1 #126359

Open
matthiaskrgr opened this issue Jun 12, 2024 · 5 comments · May be fixed by #126382
Open

ICE: expected int of size 8, but got size 1 #126359

matthiaskrgr opened this issue Jun 12, 2024 · 5 comments · May be fixed by #126382
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

struct OppOrder<const N: u8 = 3, T = u32> {
    arr: [T; N],
}

fn main() {
    let _ = OppOrder::<3, u32> { arr: [0, 0, 0] };
}

original:

//@ run-pass
#![allow(dead_code)]

struct Both<T=u32, const N: usize=3> {
  arr: [T; N]
}

trait BothTrait<T=u32, const N: u32=3> {}

enum BothEnum<T=u32, const N: usize=3> {
  Dummy([T; N])
}

struct OppOrder<const N: u8=3, T=u32> {
  arr: [T; N]
}

fn main() {
  let _ = OppOrder::<3, u32> {
    arr: [0,0,0],
  };
  let _ = OppOrder::<3, u32> {
    arr: [0],
  };
}

Version information

rustc 1.81.0-nightly (c25ac9d6c 2024-06-12)
binary: rustc
commit-hash: c25ac9d6cc285e57e1176dc2da6848b9d0163810
commit-date: 2024-06-12
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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

Program output

error: internal compiler error: compiler/rustc_middle/src/ty/consts/int.rs:262:13: expected int of size 8, but got size 1

thread 'rustc' panicked at compiler/rustc_middle/src/ty/consts/int.rs:262:13:
Box<dyn Any>
stack backtrace:
   0:     0x734e9e0afae5 - std::backtrace_rs::backtrace::libunwind::trace::h6be50cef0e090531
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x734e9e0afae5 - std::backtrace_rs::backtrace::trace_unsynchronized::h84167074cb4f1713
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x734e9e0afae5 - std::sys_common::backtrace::_print_fmt::hb5cf039fd1f30b07
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x734e9e0afae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h01adaba1565f117f
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x734e9e10077b - core::fmt::rt::Argument::fmt::h2910e36f4e21d32d
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/core/src/fmt/rt.rs:165:63
   5:     0x734e9e10077b - core::fmt::write::h6d9d2f7ff8571b34
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/core/src/fmt/mod.rs:1168:21
   6:     0x734e9e0a46bf - std::io::Write::write_fmt::hd882c0f914f56bf0
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/io/mod.rs:1835:15
   7:     0x734e9e0af8be - std::sys_common::backtrace::_print::hcc6c907dafd9aacb
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x734e9e0af8be - std::sys_common::backtrace::print::h2c716a051c9b24be
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x734e9e0b22f9 - std::panicking::default_hook::{{closure}}::he8ad829f77bd4e23
  10:     0x734e9e0b209c - std::panicking::default_hook::heb22a1402d2cff23
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/panicking.rs:292:9
  11:     0x734e9a8b2c9f - std[5c07af62f3786d14]::panicking::update_hook::<alloc[eebcfc85002bd7db]::boxed::Box<rustc_driver_impl[2b4723ede88f52b1]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x734e9e0b2bff - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd8f0fcaec26c179e
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/alloc/src/boxed.rs:2076:9
  13:     0x734e9e0b2bff - std::panicking::rust_panic_with_hook::hc9dbad8884217847
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/panicking.rs:801:13
  14:     0x734e9a8e3621 - std[5c07af62f3786d14]::panicking::begin_panic::<rustc_errors[d9dad43edaa48690]::ExplicitBug>::{closure#0}
  15:     0x734e9a8e03d6 - std[5c07af62f3786d14]::sys_common::backtrace::__rust_end_short_backtrace::<std[5c07af62f3786d14]::panicking::begin_panic<rustc_errors[d9dad43edaa48690]::ExplicitBug>::{closure#0}, !>
  16:     0x734e9a8e00b6 - std[5c07af62f3786d14]::panicking::begin_panic::<rustc_errors[d9dad43edaa48690]::ExplicitBug>
  17:     0x734e9a8ecb71 - <rustc_errors[d9dad43edaa48690]::diagnostic::BugAbort as rustc_errors[d9dad43edaa48690]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x734e9adda21c - rustc_middle[f645b954b6a941ee]::util::bug::opt_span_bug_fmt::<rustc_span[9012e0e35e67507c]::span_encoding::Span>::{closure#0}
  19:     0x734e9adc328a - rustc_middle[f645b954b6a941ee]::ty::context::tls::with_opt::<rustc_middle[f645b954b6a941ee]::util::bug::opt_span_bug_fmt<rustc_span[9012e0e35e67507c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x734e9adc310b - rustc_middle[f645b954b6a941ee]::ty::context::tls::with_context_opt::<rustc_middle[f645b954b6a941ee]::ty::context::tls::with_opt<rustc_middle[f645b954b6a941ee]::util::bug::opt_span_bug_fmt<rustc_span[9012e0e35e67507c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x734e987dddb0 - rustc_middle[f645b954b6a941ee]::util::bug::bug_fmt
  22:     0x734e9d20e0ea - <rustc_middle[f645b954b6a941ee]::ty::consts::valtree::ValTree>::try_to_target_usize.cold
  23:     0x734e9bc639b2 - <rustc_infer[fa1e69436ce00111]::infer::InferCtxt>::super_combine_tys::<rustc_infer[fa1e69436ce00111]::infer::relate::type_relating::TypeRelating>
  24:     0x734e9bc5eb28 - <rustc_infer[fa1e69436ce00111]::infer::relate::type_relating::TypeRelating as rustc_type_ir[f1d7f392dd8f0b20]::relate::TypeRelation<rustc_middle[f645b954b6a941ee]::ty::context::TyCtxt>>::tys
  25:     0x734e9c80a039 - <rustc_hir_typeck[4e714526a792ece6]::fn_ctxt::FnCtxt>::coerce
  26:     0x734e9c410955 - <rustc_hir_typeck[4e714526a792ece6]::fn_ctxt::FnCtxt>::check_expr_struct_fields
  27:     0x734e9c82a2f5 - <rustc_hir_typeck[4e714526a792ece6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x734e9c806a1a - <rustc_hir_typeck[4e714526a792ece6]::fn_ctxt::FnCtxt>::check_decl
  29:     0x734e9c822ba5 - <rustc_hir_typeck[4e714526a792ece6]::fn_ctxt::FnCtxt>::check_block_with_expected
  30:     0x734e9c82724e - <rustc_hir_typeck[4e714526a792ece6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x734e9bdbabee - rustc_hir_typeck[4e714526a792ece6]::check::check_fn
  32:     0x734e9bdb13fe - rustc_hir_typeck[4e714526a792ece6]::typeck
  33:     0x734e9bdb0e7b - rustc_query_impl[860f4585269295fe]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[860f4585269295fe]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 8usize]>>
  34:     0x734e9beb97ee - rustc_query_system[88bb5c8529314a04]::query::plumbing::try_execute_query::<rustc_query_impl[860f4585269295fe]::DynamicConfig<rustc_query_system[88bb5c8529314a04]::query::caches::VecCache<rustc_span[9012e0e35e67507c]::def_id::LocalDefId, rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[860f4585269295fe]::plumbing::QueryCtxt, false>
  35:     0x734e9beb82d5 - rustc_query_impl[860f4585269295fe]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:     0x734e9beb7f0b - <rustc_middle[f645b954b6a941ee]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[f165ce28b444ebe1]::check_crate::{closure#4}>::{closure#0}
  37:     0x734e9beb69bc - rustc_hir_analysis[f165ce28b444ebe1]::check_crate
  38:     0x734e9c64f13e - rustc_interface[8465b2f8b714accd]::passes::analysis
  39:     0x734e9c64ec87 - rustc_query_impl[860f4585269295fe]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[860f4585269295fe]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 1usize]>>
  40:     0x734e9c9f7d25 - rustc_query_system[88bb5c8529314a04]::query::plumbing::try_execute_query::<rustc_query_impl[860f4585269295fe]::DynamicConfig<rustc_query_system[88bb5c8529314a04]::query::caches::SingleCache<rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[860f4585269295fe]::plumbing::QueryCtxt, false>
  41:     0x734e9c9f7a8f - rustc_query_impl[860f4585269295fe]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x734e9c8d0952 - rustc_interface[8465b2f8b714accd]::interface::run_compiler::<core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>, rustc_driver_impl[2b4723ede88f52b1]::run_compiler::{closure#0}>::{closure#1}
  43:     0x734e9c8ef649 - std[5c07af62f3786d14]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[8465b2f8b714accd]::util::run_in_thread_with_globals<rustc_interface[8465b2f8b714accd]::util::run_in_thread_pool_with_globals<rustc_interface[8465b2f8b714accd]::interface::run_compiler<core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>, rustc_driver_impl[2b4723ede88f52b1]::run_compiler::{closure#0}>::{closure#1}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>
  44:     0x734e9c8ef3fa - <<std[5c07af62f3786d14]::thread::Builder>::spawn_unchecked_<rustc_interface[8465b2f8b714accd]::util::run_in_thread_with_globals<rustc_interface[8465b2f8b714accd]::util::run_in_thread_pool_with_globals<rustc_interface[8465b2f8b714accd]::interface::run_compiler<core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>, rustc_driver_impl[2b4723ede88f52b1]::run_compiler::{closure#0}>::{closure#1}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#2} as core[207868f0da9fe1eb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x734e9e0bca7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd64233370b4bbb13
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/alloc/src/boxed.rs:2062:9
  46:     0x734e9e0bca7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8b9a0bf226b4eb10
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/alloc/src/boxed.rs:2062:9
  47:     0x734e9e0bca7b - std::sys::pal::unix::thread::Thread::new::thread_start::h25e4cee516ffa27e
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys/pal/unix/thread.rs:108:17
  48:     0x734e974a6ded - <unknown>
  49:     0x734e9752a0dc - <unknown>
  50:                0x0 - <unknown>

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.81.0-nightly (c25ac9d6c 2024-06-12) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error


@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Jun 12, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 12, 2024
@matthiaskrgr
Copy link
Member Author

#126159 cc @RalfJung ^^

@RalfJung
Copy link
Member

Another tainting issue -- the array is ill-typed, we shouldn't look at its details:

error[E0308]: mismatched types
 --> src/main.rs:6:39
  |
6 |     let _ = OppOrder::<3, u32> { arr: [0, 0, 0] };
  |                                       ^^^^^^^^^ expected `3`, found `3`
  |
  = note: expected array `[u32; 3]`
             found array `[u32; 3]`

error[E0308]: mismatched types
 --> src/main.rs:2:14
  |
2 |     arr: [T; N],
  |              ^ expected `usize`, found `u8`

Cc @oli-obk

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 13, 2024

Looking it into it a little bit the problem is that super_relate_tys for TyKind::Array has diagnostic logic in it that unconditionally evaluates the array length to a usize. This codepath should correctly handle length arguments that are incorrectly typed instead of assuming they can be evaluated to a usize.

            match relation.relate(sz_a, sz_b) {
                Ok(sz) => Ok(Ty::new_array_with_const_len(tcx, t, sz)),
                Err(err) => {
                    // Check whether the lengths are both concrete/known values,
                    // but are unequal, for better diagnostics.
                    let sz_a = sz_a.try_to_target_usize(tcx);
                    let sz_b = sz_b.try_to_target_usize(tcx);

                    match (sz_a, sz_b) {
                        (Some(sz_a_val), Some(sz_b_val)) if sz_a_val != sz_b_val => Err(
                            TypeError::FixedArraySize(ExpectedFound::new(true, sz_a_val, sz_b_val)),
                        ),
                        _ => Err(err),
                    }
                }
            }

@RalfJung
Copy link
Member

FWIW the diagnostic previously shown also looked odd

 --> src/main.rs:6:39
  |
6 |     let _ = OppOrder::<3, u32> { arr: [0, 0, 0] };
  |                                       ^^^^^^^^^ expected `3`, found `3`
  |
  = note: expected array `[u32; 3]`
             found array `[u32; 3]`

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 13, 2024

I think we would have had a valtree for 3_u8 and one for 3_u32 and they wouldn't compare equal due to differing bit sizes. We should probably not report const mismatch errors involving const arguments that are of different types to eachother as this should always result in an error elsewhere either when type checking an anon const or in a ConstArgHasType goal. If we ever get a way to write const N: T that ought to also end up erroring elsewhere (i.e. on the arguments to the T parameter)

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 17, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 4, 2024
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

5 participants