Skip to content

Regression ICE: rustc panicked at compiler/rustc_mir_build/src/thir/cx/expr.rs #134718

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
cicilzx opened this issue Dec 24, 2024 · 1 comment
Closed
Labels
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.

Comments

@cicilzx
Copy link

cicilzx commented Dec 24, 2024

Code

I'm running one of the test cases: https://github.com/rust-lang/rust/blob/master/tests/ui/error-codes/E0081.rs

Rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e666c1025ba46d95270dfd652364f81b

enum Enum {
    //~^ ERROR discriminant value `3` assigned more than once
    P = 3,
    //~^ NOTE `3` assigned here
    X = 3,
    //~^ NOTE `3` assigned here
    Y = 5
}

#[repr(u8)]
enum EnumOverflowRepr {
    //~^ ERROR discriminant value `1` assigned more than once
    P = 257,
    //~^ NOTE `1` (overflowed from `257`) assigned here
    X = 513,
    //~^ NOTE `1` (overflowed from `513`) assigned here
}

#[repr(i8)]
enum NegDisEnum {
    //~^ ERROR discriminant value `-1` assigned more than once
    First = -1,
    //~^ NOTE `-1` assigned here
    Second = -2,
    //~^ NOTE discriminant for `Last` incremented from this startpoint (`Second` + 1 variant later => `Last` = -1)
    Last,
    //~^ NOTE `-1` assigned here
}

enum MultipleDuplicates {
    //~^ ERROR discriminant value `0` assigned more than once
    //~^^ ERROR discriminant value `-2` assigned more than once
    V0,
    //~^ NOTE `0` assigned here
    V1 = 0,
    //~^ NOTE `0` assigned here
    V2,
    V3,
    V4 = 0,
    //~^ NOTE `0` assigned here
    V5 = -2,
    //~^ NOTE discriminant for `V7` incremented from this startpoint (`V5` + 2 variants later => `V7` = 0)
    //~^^ NOTE `-2` assigned here
    V6,
    V7,
    //~^ NOTE `0` assigned here
    V8 = -3,
    //~^ NOTE discriminant for `V9` incremented from this startpoint (`V8` + 1 variant later => `V9` = -2)
    V9,
    //~^ NOTE `-2` assigned here
}

// Test for #131902
// Ensure that casting an enum with too many variants for its repr
// does not ICE
#[repr(u8)]
enum TooManyVariants {
    //~^ ERROR discriminant value `0` assigned more than once
    X000, X001, X002, X003, X004, X005, X006, X007, X008, X009,
    //~^ NOTE `0` assigned here
    //~| NOTE discriminant for `X256` incremented from this startpoint
    X010, X011, X012, X013, X014, X015, X016, X017, X018, X019,
    X020, X021, X022, X023, X024, X025, X026, X027, X028, X029,
    X030, X031, X032, X033, X034, X035, X036, X037, X038, X039,
    X040, X041, X042, X043, X044, X045, X046, X047, X048, X049,
    X050, X051, X052, X053, X054, X055, X056, X057, X058, X059,
    X060, X061, X062, X063, X064, X065, X066, X067, X068, X069,
    X070, X071, X072, X073, X074, X075, X076, X077, X078, X079,
    X080, X081, X082, X083, X084, X085, X086, X087, X088, X089,
    X090, X091, X092, X093, X094, X095, X096, X097, X098, X099,
    X100, X101, X102, X103, X104, X105, X106, X107, X108, X109,
    X110, X111, X112, X113, X114, X115, X116, X117, X118, X119,
    X120, X121, X122, X123, X124, X125, X126, X127, X128, X129,
    X130, X131, X132, X133, X134, X135, X136, X137, X138, X139,
    X140, X141, X142, X143, X144, X145, X146, X147, X148, X149,
    X150, X151, X152, X153, X154, X155, X156, X157, X158, X159,
    X160, X161, X162, X163, X164, X165, X166, X167, X168, X169,
    X170, X171, X172, X173, X174, X175, X176, X177, X178, X179,
    X180, X181, X182, X183, X184, X185, X186, X187, X188, X189,
    X190, X191, X192, X193, X194, X195, X196, X197, X198, X199,
    X200, X201, X202, X203, X204, X205, X206, X207, X208, X209,
    X210, X211, X212, X213, X214, X215, X216, X217, X218, X219,
    X220, X221, X222, X223, X224, X225, X226, X227, X228, X229,
    X230, X231, X232, X233, X234, X235, X236, X237, X238, X239,
    X240, X241, X242, X243, X244, X245, X246, X247, X248, X249,
    X250, X251, X252, X253, X254, X255,
    X256,
    //~^ ERROR enum discriminant overflowed
    //~| NOTE overflowed on value after 255
    //~| NOTE explicitly set `X256 = 0`
    //~| NOTE `0` assigned here
}

fn main() {
    TooManyVariants::X256 as u8;
}

Meta

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)

Error output

error[E0081]: discriminant value `3` assigned more than once
 --> src/main.rs:1:1
  |
1 | enum Enum {
  | ^^^^^^^^^
2 |     //~^ ERROR discriminant value `3` assigned more than once
3 |     P = 3,
  |         - `3` assigned here
4 |     //~^ NOTE `3` assigned here
5 |     X = 3,
  |         - `3` assigned here

error[E0081]: discriminant value `1` assigned more than once
  --> src/main.rs:11:1
   |
11 | enum EnumOverflowRepr {
   | ^^^^^^^^^^^^^^^^^^^^^
12 |     //~^ ERROR discriminant value `1` assigned more than once
13 |     P = 257,
   |         --- `1` (overflowed from `257`) assigned here
14 |     //~^ NOTE `1` (overflowed from `257`) assigned here
15 |     X = 513,
   |         --- `1` (overflowed from `513`) assigned here

error[E0081]: discriminant value `-1` assigned more than once
  --> src/main.rs:20:1
   |
20 | enum NegDisEnum {
   | ^^^^^^^^^^^^^^^
21 |     //~^ ERROR discriminant value `-1` assigned more than once
22 |     First = -1,
   |             -- `-1` assigned here
23 |     //~^ NOTE `-1` assigned here
24 |     Second = -2,
   |     ------ discriminant for `Last` incremented from this startpoint (`Second` + 1 variant later => `Last` = -1)
25 |     //~^ NOTE discriminant for `Last` incremented from this startpoint (`Second` + 1 variant later => `Last` = -1)
26 |     Last,
   |     ---- `-1` assigned here

error[E0081]: discriminant value `0` assigned more than once
  --> src/main.rs:30:1
   |
30 | enum MultipleDuplicates {
   | ^^^^^^^^^^^^^^^^^^^^^^^
...
33 |     V0,
   |     -- `0` assigned here
34 |     //~^ NOTE `0` assigned here
35 |     V1 = 0,
   |          - `0` assigned here
...
39 |     V4 = 0,
   |          - `0` assigned here
40 |     //~^ NOTE `0` assigned here
41 |     V5 = -2,
   |     -- discriminant for `V7` incremented from this startpoint (`V5` + 2 variants later => `V7` = 0)
...
45 |     V7,
   |     -- `0` assigned here

error[E0081]: discriminant value `-2` assigned more than once
  --> src/main.rs:30:1
   |
30 | enum MultipleDuplicates {
   | ^^^^^^^^^^^^^^^^^^^^^^^
...
41 |     V5 = -2,
   |          -- `-2` assigned here
...
47 |     V8 = -3,
   |     -- discriminant for `V9` incremented from this startpoint (`V8` + 1 variant later => `V9` = -2)
48 |     //~^ NOTE discriminant for `V9` incremented from this startpoint (`V8` + 1 variant later => `V9` = -2)
49 |     V9,
   |     -- `-2` assigned here

error[E0370]: enum discriminant overflowed
  --> src/main.rs:87:5
   |
87 |     X256,
   |     ^^^^ overflowed on value after 255
   |
   = note: explicitly set `X256 = 0` if that is desired outcome

error[E0081]: discriminant value `0` assigned more than once
  --> src/main.rs:57:1
   |
57 | enum TooManyVariants {
   | ^^^^^^^^^^^^^^^^^^^^
58 |     //~^ ERROR discriminant value `0` assigned more than once
59 |     X000, X001, X002, X003, X004, X005, X006, X007, X008, X009,
   |     ----
   |     |
   |     `0` assigned here
   |     discriminant for `X256` incremented from this startpoint (`X000` + 256 variants later => `X256` = 0)
...
87 |     X256,
   |     ---- `0` assigned here
Backtrace

thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/cx/expr.rs:284:76:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7b4239c4012a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h5b6bd5631a6d1f6b
   1:     0x7b423a4218f8 - core::fmt::write::h7550c97b06c86515
   2:     0x7b423b658b91 - std::io::Write::write_fmt::h7b09c64fe0be9c84
   3:     0x7b4239c3ff82 - std::sys::backtrace::BacktraceLock::print::h2395ccd2c84ba3aa
   4:     0x7b4239c42456 - std::panicking::default_hook::{{closure}}::he19d4c7230e07961
   5:     0x7b4239c422a0 - std::panicking::default_hook::hf614597d3c67bbdb
   6:     0x7b4238d04556 - std[c6eb78587944e35c]::panicking::update_hook::<alloc[148a978a4a62f5d]::boxed::Box<rustc_driver_impl[4c2d2ad79fb810ac]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7b4239c42b68 - std::panicking::rust_panic_with_hook::h8942133a8b252070
   8:     0x7b4239c42906 - std::panicking::begin_panic_handler::{{closure}}::hb5f5963570096b29
   9:     0x7b4239c405d9 - std::sys::backtrace::__rust_end_short_backtrace::h6208cedc1922feda
  10:     0x7b4239c425fc - rust_begin_unwind
  11:     0x7b42376bb160 - core::panicking::panic_fmt::h0c3082644d1bf418
  12:     0x7b423720a28c - core::panicking::panic::h957f98c65a3b3074
  13:     0x7b4236dea7c9 - core::option::unwrap_failed::h098b0d47c83374d6
  14:     0x7b423ad1d3df - <rustc_mir_build[3e3bbc0efa041e77]::thir::cx::Cx>::mirror_expr
  15:     0x7b423ad12f76 - <rustc_mir_build[3e3bbc0efa041e77]::thir::cx::Cx>::mirror_stmts::{closure#0}
  16:     0x7b423ad17000 - <rustc_mir_build[3e3bbc0efa041e77]::thir::cx::Cx>::mirror_expr
  17:     0x7b423ad25d5b - rustc_mir_build[3e3bbc0efa041e77]::thir::cx::thir_body
  18:     0x7b423ad25760 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::thir_body::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>
  19:     0x7b423a9ca71b - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  20:     0x7b423a9ca3a6 - rustc_query_impl[db795c774d495014]::query_impl::thir_body::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7b4236b056a5 - rustc_mir_build[3e3bbc0efa041e77]::check_unsafety::check_unsafety
  22:     0x7b423ab3ed57 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 0usize]>>
  23:     0x7b423ab3ef86 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::VecCache<rustc_span[3e5cf3424d44936d]::def_id::LocalDefId, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  24:     0x7b423ab3ec81 - rustc_query_impl[db795c774d495014]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7b423acf04df - rustc_interface[88a02114bbdb2383]::passes::run_required_analyses
  26:     0x7b423ace72e5 - rustc_interface[88a02114bbdb2383]::passes::analysis
  27:     0x7b423ace72c9 - rustc_query_impl[db795c774d495014]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db795c774d495014]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 1usize]>>
  28:     0x7b423b1f2662 - rustc_query_system[b2bb6e43dd6b7fda]::query::plumbing::try_execute_query::<rustc_query_impl[db795c774d495014]::DynamicConfig<rustc_query_system[b2bb6e43dd6b7fda]::query::caches::SingleCache<rustc_middle[a886f61dbc61428a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[db795c774d495014]::plumbing::QueryCtxt, false>
  29:     0x7b423b1f238f - rustc_query_impl[db795c774d495014]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7b423b1620bb - rustc_interface[88a02114bbdb2383]::interface::run_compiler::<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7b423b1533d9 - std[c6eb78587944e35c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[88a02114bbdb2383]::util::run_in_thread_with_globals<rustc_interface[88a02114bbdb2383]::interface::run_compiler<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>
  32:     0x7b423b222fac - <<std[c6eb78587944e35c]::thread::Builder>::spawn_unchecked_<rustc_interface[88a02114bbdb2383]::util::run_in_thread_with_globals<rustc_interface[88a02114bbdb2383]::interface::run_compiler<core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>, rustc_driver_impl[4c2d2ad79fb810ac]::run_compiler::{closure#0}>::{closure#1}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c06ff78fa456ca03]::result::Result<(), rustc_span[3e5cf3424d44936d]::ErrorGuaranteed>>::{closure#1} as core[c06ff78fa456ca03]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7b423b223a6b - std::sys::pal::unix::thread::Thread::new::thread_start::hcc78f3943333fa94
  34:     0x7b423568aa94 - <unknown>
  35:     0x7b4235717a34 - clone
  36:                0x0 - <unknown>

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: rustc 1.83.0 (90b35a623 2024-11-26) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [thir_body] building THIR for `main`
#1 [check_unsafety] unsafety-checking `main`
end of query stack
Some errors have detailed explanations: E0081, E0370.
For more information about an error, try `rustc --explain E0081`.

@cicilzx cicilzx 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 Dec 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 24, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 24, 2024

You're running this test on the stable channel in the playground. This ICEs on stable but is fixed on beta/nightly. We run this test in CI before merge.

This particular ICE was fixed by #131909.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Dec 24, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 24, 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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants