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 #131101

Closed
matthiaskrgr opened this issue Oct 1, 2024 · 0 comments · Fixed by #133367
Closed

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

matthiaskrgr opened this issue Oct 1, 2024 · 0 comments · Fixed by #133367
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):

trait Foo<const N: u8> {
    fn do_x(&self) -> [u8; N];
}

struct Bar;

impl Foo<const 3> for Bar {
    fn do_x(&self) -> [u8; 3] {
        [0u8; 3]
    }
}

original:

trait Foo<const N: u8> {
    fn do_x(&self) -> [u8; N];
}

struct Bar;

const T: usize = 42;

impl Foo<const 3> for Bar {
//~^ERROR expected lifetime, type, or constant, found keyword `const`
    fn do_x(&self) -> [u8; 3] {
        [0u8; 3]
    }
}

fn main() {}

Version information

rustc 1.83.0-nightly (c4f717650 2024-10-01)
binary: rustc
commit-hash: c4f7176501a7d3c19c230b8c9111b2d39142f83a
commit-date: 2024-10-01
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

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

Program output

error: expected lifetime, type, or constant, found keyword `const`
 --> /tmp/icemaker_global_tempdir.xhOgY77xz6zM/rustc_testrunner_tmpdir_reporting.0OBRpObgqu4G/mvce.rs:9:10
  |
9 | impl Foo<const 3> for Bar {
  |          ^^^^^
  |
help: the `const` keyword is only needed in the definition of the type
  |
9 - impl Foo<const 3> for Bar {
9 + impl Foo<3> for Bar {
  |

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.xhOgY77xz6zM/rustc_testrunner_tmpdir_reporting.0OBRpObgqu4G/mvce.rs:14:2
   |
14 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.xhOgY77xz6zM/rustc_testrunner_tmpdir_reporting.0OBRpObgqu4G/mvce.rs`

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

thread 'rustc' panicked at compiler/rustc_middle/src/ty/consts/int.rs:263:13:
Box<dyn Any>
stack backtrace:
   0:     0x74626d8daeda - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::had0a4a07d444c243
   1:     0x74626e0033e6 - core::fmt::write::hfa03780471fd40a1
   2:     0x74626f1bd491 - std::io::Write::write_fmt::he88bb98b829c33b1
   3:     0x74626d8dad32 - std::sys::backtrace::BacktraceLock::print::h1e8153a6bf47e7a5
   4:     0x74626d8dd251 - std::panicking::default_hook::{{closure}}::h2d7a6dde612f1b16
   5:     0x74626d8dd084 - std::panicking::default_hook::ha6ce9de3458bcdda
   6:     0x74626c9a486f - std[c1d7bd3f58de7430]::panicking::update_hook::<alloc[29d5ad3c4a91d383]::boxed::Box<rustc_driver_impl[b3d9015aed309aa5]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x74626d8dd968 - std::panicking::rust_panic_with_hook::haf1d2e00d64b82f1
   8:     0x74626c9de321 - std[c1d7bd3f58de7430]::panicking::begin_panic::<rustc_errors[a2cc27f529684419]::ExplicitBug>::{closure#0}
   9:     0x74626c9d13c6 - std[c1d7bd3f58de7430]::sys::backtrace::__rust_end_short_backtrace::<std[c1d7bd3f58de7430]::panicking::begin_panic<rustc_errors[a2cc27f529684419]::ExplicitBug>::{closure#0}, !>
  10:     0x74626c9ccad9 - std[c1d7bd3f58de7430]::panicking::begin_panic::<rustc_errors[a2cc27f529684419]::ExplicitBug>
  11:     0x74626c9e7bb1 - <rustc_errors[a2cc27f529684419]::diagnostic::BugAbort as rustc_errors[a2cc27f529684419]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x74626d00ba54 - rustc_middle[99056c3c142edfd1]::util::bug::opt_span_bug_fmt::<rustc_span[fbdd09955dfcae25]::span_encoding::Span>::{closure#0}
  13:     0x74626cff17ca - rustc_middle[99056c3c142edfd1]::ty::context::tls::with_opt::<rustc_middle[99056c3c142edfd1]::util::bug::opt_span_bug_fmt<rustc_span[fbdd09955dfcae25]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x74626cff165b - rustc_middle[99056c3c142edfd1]::ty::context::tls::with_context_opt::<rustc_middle[99056c3c142edfd1]::ty::context::tls::with_opt<rustc_middle[99056c3c142edfd1]::util::bug::opt_span_bug_fmt<rustc_span[fbdd09955dfcae25]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x74626a5cce60 - rustc_middle[99056c3c142edfd1]::util::bug::bug_fmt
  16:     0x74626f3fdba3 - <rustc_middle[99056c3c142edfd1]::ty::consts::Const as rustc_type_ir[52210652b01e0c85]::inherent::Const<rustc_middle[99056c3c142edfd1]::ty::context::TyCtxt>>::try_to_target_usize.cold
  17:     0x74626e0e6b05 - <rustc_infer[6567e56aed91dd61]::infer::InferCtxt>::super_combine_tys::<rustc_infer[6567e56aed91dd61]::infer::relate::type_relating::TypeRelating>
  18:     0x74626e0e10dd - <rustc_infer[6567e56aed91dd61]::infer::relate::type_relating::TypeRelating as rustc_type_ir[52210652b01e0c85]::relate::TypeRelation<rustc_middle[99056c3c142edfd1]::ty::context::TyCtxt>>::tys
  19:     0x74626a46bbd9 - rustc_hir_analysis[5f12a0460b8fec89]::check::check::check_impl_items_against_trait
  20:     0x74626baea1a2 - rustc_hir_analysis[5f12a0460b8fec89]::check::wfcheck::check_well_formed
  21:     0x74626e3d9727 - rustc_query_impl[a128c9efc091a24e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a128c9efc091a24e]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[99056c3c142edfd1]::query::erase::Erased<[u8; 1usize]>>
  22:     0x74626e3d99b4 - rustc_query_system[a5b010e784c9cc4f]::query::plumbing::try_execute_query::<rustc_query_impl[a128c9efc091a24e]::DynamicConfig<rustc_query_system[a5b010e784c9cc4f]::query::caches::VecCache<rustc_hir[a33e640fa4d8b320]::hir_id::OwnerId, rustc_middle[99056c3c142edfd1]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a128c9efc091a24e]::plumbing::QueryCtxt, false>
  23:     0x74626e3d9706 - rustc_query_impl[a128c9efc091a24e]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  24:     0x74626e3da4d7 - rustc_hir_analysis[5f12a0460b8fec89]::check::wfcheck::check_mod_type_wf
  25:     0x74626e3da315 - rustc_query_impl[a128c9efc091a24e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a128c9efc091a24e]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[99056c3c142edfd1]::query::erase::Erased<[u8; 1usize]>>
  26:     0x74626ee8c8bb - rustc_query_system[a5b010e784c9cc4f]::query::plumbing::try_execute_query::<rustc_query_impl[a128c9efc091a24e]::DynamicConfig<rustc_query_system[a5b010e784c9cc4f]::query::caches::DefaultCache<rustc_span[fbdd09955dfcae25]::def_id::LocalModDefId, rustc_middle[99056c3c142edfd1]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a128c9efc091a24e]::plumbing::QueryCtxt, false>
  27:     0x74626ee8c66d - rustc_query_impl[a128c9efc091a24e]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  28:     0x74626e3a5a3b - rustc_hir_analysis[5f12a0460b8fec89]::check_crate
  29:     0x74626e3a26d7 - rustc_interface[89dec4b9d675c708]::passes::run_required_analyses
  30:     0x74626ed0f51e - rustc_interface[89dec4b9d675c708]::passes::analysis
  31:     0x74626ed0f4f1 - rustc_query_impl[a128c9efc091a24e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a128c9efc091a24e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[99056c3c142edfd1]::query::erase::Erased<[u8; 1usize]>>
  32:     0x74626ee9252e - rustc_query_system[a5b010e784c9cc4f]::query::plumbing::try_execute_query::<rustc_query_impl[a128c9efc091a24e]::DynamicConfig<rustc_query_system[a5b010e784c9cc4f]::query::caches::SingleCache<rustc_middle[99056c3c142edfd1]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a128c9efc091a24e]::plumbing::QueryCtxt, false>
  33:     0x74626ee9220f - rustc_query_impl[a128c9efc091a24e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x74626ed1f55e - rustc_interface[89dec4b9d675c708]::interface::run_compiler::<core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>, rustc_driver_impl[b3d9015aed309aa5]::run_compiler::{closure#0}>::{closure#1}
  35:     0x74626edea350 - std[c1d7bd3f58de7430]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[89dec4b9d675c708]::util::run_in_thread_with_globals<rustc_interface[89dec4b9d675c708]::util::run_in_thread_pool_with_globals<rustc_interface[89dec4b9d675c708]::interface::run_compiler<core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>, rustc_driver_impl[b3d9015aed309aa5]::run_compiler::{closure#0}>::{closure#1}, core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>>::{closure#0}, core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>>
  36:     0x74626edea9ba - <<std[c1d7bd3f58de7430]::thread::Builder>::spawn_unchecked_<rustc_interface[89dec4b9d675c708]::util::run_in_thread_with_globals<rustc_interface[89dec4b9d675c708]::util::run_in_thread_pool_with_globals<rustc_interface[89dec4b9d675c708]::interface::run_compiler<core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>, rustc_driver_impl[b3d9015aed309aa5]::run_compiler::{closure#0}>::{closure#1}, core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>>::{closure#0}, core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d0cd706d8d014919]::result::Result<(), rustc_span[fbdd09955dfcae25]::ErrorGuaranteed>>::{closure#1} as core[d0cd706d8d014919]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x74626edeadab - std::sys::pal::unix::thread::Thread::new::thread_start::h6a16a471557e53ce
  38:     0x74627042539d - <unknown>
  39:     0x7462704aa49c - <unknown>
  40:                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.83.0-nightly (c4f717650 2024-10-01) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.xhOgY77xz6zM/rustc_testrunner_tmpdir_reporting.0OBRpObgqu4G/mvce.rs:9:1: 9:26>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0601`.

@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 Oct 1, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 1, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 12, 2024
jhpratt added a commit to jhpratt/rust that referenced this issue Nov 26, 2024
…, r=BoxyUwU

Simplify array length mismatch error reporting (to not try to turn consts into target usizes)

This changes `TypeError::FixedArrayLen` to use `ExpectedFound<ty::Const<'tcx>>` (instead of `ExpectedFound<u64>`), and renames it to `TypeError::ArrayLen`. This allows us to avoid a `try_to_target_usize` call in the type relation, which ICEs when we have a scalar of the wrong bit length (i.e. u8).

This also makes `structurally_relate_tys` to always use this type error kind any time we have a const mismatch resulting from relating the array-len part of `[T; N]`.

This has the effect of changing the error message we issue for array length mismatches involving non-valtree consts. I actually quite like the change, though, since before:

```
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
   |                                              ------- expected `[u8; M]` because of return type
LL |     [0; N]
   |     ^^^^^^ expected `M`, found `N`
   |
   = note: expected array `[u8; M]`
              found array `[u8; N]`
```

and after, which I think is far less verbose:

```
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
   |                                              ------- expected `[u8; M]` because of return type
LL |     [0; N]
   |     ^^^^^^ expected an array with a size of M, found one with a size of N
```

The only questions I have are:
1. Should we do something about backticks here? Right now we don't backtick either fully evaluated consts like `2`, or rigid consts like `Foo::BAR`.... but maybe we should? It seems kinda verbose to do for numbers -- maybe we could intercept those specifically.
2. I guess we may still run the risk of leaking unevaluated consts into error reporting like `2 + 1`...?

r? `@BoxyUwU`

Fixes rust-lang#126359
Fixes rust-lang#131101
@bors bors closed this as completed in cf09718 Nov 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 27, 2024
Rollup merge of rust-lang#133367 - compiler-errors:array-len-mismatch, r=BoxyUwU

Simplify array length mismatch error reporting (to not try to turn consts into target usizes)

This changes `TypeError::FixedArrayLen` to use `ExpectedFound<ty::Const<'tcx>>` (instead of `ExpectedFound<u64>`), and renames it to `TypeError::ArrayLen`. This allows us to avoid a `try_to_target_usize` call in the type relation, which ICEs when we have a scalar of the wrong bit length (i.e. u8).

This also makes `structurally_relate_tys` to always use this type error kind any time we have a const mismatch resulting from relating the array-len part of `[T; N]`.

This has the effect of changing the error message we issue for array length mismatches involving non-valtree consts. I actually quite like the change, though, since before:

```
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
   |                                              ------- expected `[u8; M]` because of return type
LL |     [0; N]
   |     ^^^^^^ expected `M`, found `N`
   |
   = note: expected array `[u8; M]`
              found array `[u8; N]`
```

and after, which I think is far less verbose:

```
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
   |                                              ------- expected `[u8; M]` because of return type
LL |     [0; N]
   |     ^^^^^^ expected an array with a size of M, found one with a size of N
```

The only questions I have are:
1. Should we do something about backticks here? Right now we don't backtick either fully evaluated consts like `2`, or rigid consts like `Foo::BAR`.... but maybe we should? It seems kinda verbose to do for numbers -- maybe we could intercept those specifically.
2. I guess we may still run the risk of leaking unevaluated consts into error reporting like `2 + 1`...?

r? ``@BoxyUwU``

Fixes rust-lang#126359
Fixes rust-lang#131101
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
None yet
3 participants