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: for_variant called on zero-variant enum: rustc_middle/src/ty/layout.rs:2254:25 #94073

Closed
matthiaskrgr opened this issue Feb 17, 2022 · 3 comments · Fixed by #94093
Closed
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@matthiaskrgr
Copy link
Member

Code

./src/test/ui/issues/issue-46855.rs

// run-pass
#![allow(dead_code)]
// compile-flags: -Zmir-opt-level=1

use std::mem;

#[derive(Copy, Clone)]
enum Never {}

union Foo {
    a: u64,
    b: Never
}

fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 }

fn bar([(_, x)]: [(Never, u32); 1]) -> u32 { x }

fn main() {
    println!("{}", mem::size_of::<Foo>());

    let f = [Foo { a: 42 }, Foo { a: 10 }];
    println!("{:?}", unsafe { f[0].a });
}

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (930fc4f59 2022-02-17)
binary: rustc
commit-hash: 930fc4f59ddeb9f26d554a2c75c5355989189540
commit-date: 2022-02-17
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

Error output

rustc --emit=mir -Zmir-opt-level=3 ./src/test/ui/issues/issue-46855.rs

error: internal compiler error: /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/compiler/rustc_middle/src/ty/layout.rs:2254:25: for_variant called on zero-variant enum

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1160:9
stack backtrace:
Backtrace

error: internal compiler error: /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/compiler/rustc_middle/src/ty/layout.rs:2254:25: for_variant called on zero-variant enum

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1160:9
stack backtrace:
   0:     0x7f78ad4b5b5c - std::backtrace_rs::backtrace::libunwind::trace::hae9f9f42caadfe9e
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f78ad4b5b5c - std::backtrace_rs::backtrace::trace_unsynchronized::h984313517e631cbc
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f78ad4b5b5c - std::sys_common::backtrace::_print_fmt::ha75e0881baa93144
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f78ad4b5b5c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h41c1f36665a9bd0e
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f78ad51769c - core::fmt::write::h3e5b6f29124944f2
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1190:17
   5:     0x7f78ad4a5f48 - std::io::Write::write_fmt::h96de94e7a15fe749
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/io/mod.rs:1657:15
   6:     0x7f78ad4b9ad7 - std::sys_common::backtrace::_print::h04f509d7765fd143
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f78ad4b9ad7 - std::sys_common::backtrace::print::h1d2690496ac522bf
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f78ad4b9ad7 - std::panicking::default_hook::{{closure}}::h4365d5216af531ce
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/panicking.rs:295:22
   9:     0x7f78ad4b979f - std::panicking::default_hook::h08ec5ddaab2681b4
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/panicking.rs:314:9
  10:     0x7f78adc43e31 - rustc_driver[bd9cd877565bda13]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f78ad4ba3b5 - std::panicking::rust_panic_with_hook::hf261a9968df6254e
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/panicking.rs:702:17
  12:     0x7f78aed15891 - std[c5462c1bfd218a1c]::panicking::begin_panic::<rustc_errors[510fcacd8a67285a]::ExplicitBug>::{closure#0}
  13:     0x7f78aed15806 - std[c5462c1bfd218a1c]::sys_common::backtrace::__rust_end_short_backtrace::<std[c5462c1bfd218a1c]::panicking::begin_panic<rustc_errors[510fcacd8a67285a]::ExplicitBug>::{closure#0}, !>
  14:     0x7f78aed1bb5f - std[c5462c1bfd218a1c]::panicking::begin_panic::<rustc_errors[510fcacd8a67285a]::ExplicitBug>
  15:     0x7f78aed2891d - std[c5462c1bfd218a1c]::panic::panic_any::<rustc_errors[510fcacd8a67285a]::ExplicitBug>
  16:     0x7f78aed27bd7 - <rustc_errors[510fcacd8a67285a]::HandlerInner>::bug
  17:     0x7f78aed27700 - <rustc_errors[510fcacd8a67285a]::Handler>::bug
  18:     0x7f78aeba79d9 - rustc_middle[54f726bc1ff843e8]::ty::context::tls::with_opt::<rustc_middle[54f726bc1ff843e8]::util::bug::opt_span_bug_fmt<rustc_span[6689c5c9190a746]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f78aeba84b0 - rustc_middle[54f726bc1ff843e8]::util::bug::opt_span_bug_fmt::<rustc_span[6689c5c9190a746]::span_encoding::Span>
  20:     0x7f78aeba8426 - rustc_middle[54f726bc1ff843e8]::util::bug::bug_fmt
  21:     0x7f78af4b14e6 - <rustc_target[975f0522de779dc6]::abi::TyAndLayout<rustc_middle[54f726bc1ff843e8]::ty::Ty>>::for_variant::<rustc_const_eval[132fa4eec9f394a]::interpret::eval_context::InterpCx<rustc_const_eval[132fa4eec9f394a]::const_eval::machine::CompileTimeInterpreter>>
  22:     0x7f78afee887c - <rustc_const_eval[132fa4eec9f394a]::interpret::eval_context::InterpCx<rustc_const_eval[132fa4eec9f394a]::const_eval::machine::CompileTimeInterpreter>>::operand_downcast
  23:     0x7f78aff06a91 - rustc_const_eval[132fa4eec9f394a]::const_eval::try_destructure_const
  24:     0x7f78afeff797 - <rustc_const_eval[132fa4eec9f394a]::provide::{closure#0} as core[95c145b1f11c2ef3]::ops::function::FnOnce<(rustc_middle[54f726bc1ff843e8]::ty::context::TyCtxt, rustc_middle[54f726bc1ff843e8]::ty::ParamEnvAnd<rustc_middle[54f726bc1ff843e8]::ty::consts::Const>)>>::call_once
  25:     0x7f78aff9dd9e - rustc_query_system[7bd7ac6a0d193a7f]::query::plumbing::get_query::<rustc_query_impl[5a04f718ab6f27a3]::queries::try_destructure_const, rustc_query_impl[5a04f718ab6f27a3]::plumbing::QueryCtxt>
  26:     0x7f78affbac8a - <rustc_query_impl[5a04f718ab6f27a3]::Queries as rustc_middle[54f726bc1ff843e8]::ty::query::QueryEngine>::try_destructure_const
  27:     0x7f78aeb8e666 - <rustc_middle[54f726bc1ff843e8]::ty::print::pretty::FmtPrinter<&mut core[95c145b1f11c2ef3]::fmt::Formatter> as rustc_middle[54f726bc1ff843e8]::ty::print::pretty::PrettyPrinter>::pretty_print_const_value
  28:     0x7f78aeb8c76c - <rustc_middle[54f726bc1ff843e8]::ty::print::pretty::FmtPrinter<&mut core[95c145b1f11c2ef3]::fmt::Formatter> as rustc_middle[54f726bc1ff843e8]::ty::print::pretty::PrettyPrinter>::pretty_print_const
  29:     0x7f78aeb8e3f3 - <rustc_middle[54f726bc1ff843e8]::ty::print::pretty::FmtPrinter<&mut core[95c145b1f11c2ef3]::fmt::Formatter> as rustc_middle[54f726bc1ff843e8]::ty::print::pretty::PrettyPrinter>::pretty_print_const_value
  30:     0x7f78aeb8c76c - <rustc_middle[54f726bc1ff843e8]::ty::print::pretty::FmtPrinter<&mut core[95c145b1f11c2ef3]::fmt::Formatter> as rustc_middle[54f726bc1ff843e8]::ty::print::pretty::PrettyPrinter>::pretty_print_const
  31:     0x7f78aebf0cfe - rustc_middle[54f726bc1ff843e8]::mir::pretty_print_const
  32:     0x7f78ad51769c - core::fmt::write::h3e5b6f29124944f2
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1190:17
  33:     0x7f78ad5185c4 - core::fmt::Formatter::write_fmt::h23d0734773a3404c
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1644:9
  34:     0x7f78aebf0ac1 - <rustc_middle[54f726bc1ff843e8]::mir::Constant as core[95c145b1f11c2ef3]::fmt::Debug>::fmt
  35:     0x7f78ad51769c - core::fmt::write::h3e5b6f29124944f2
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1190:17
  36:     0x7f78ad5185c4 - core::fmt::Formatter::write_fmt::h23d0734773a3404c
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1644:9
  37:     0x7f78aebefc4b - <rustc_middle[54f726bc1ff843e8]::mir::Operand as core[95c145b1f11c2ef3]::fmt::Debug>::fmt
  38:     0x7f78ad514e88 - core::fmt::builders::DebugInner::entry::{{closure}}::h9222e19a8d7e9c55
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/builders.rs:404:17
  39:     0x7f78ad514e88 - core::result::Result<T,E>::and_then::h401606d107cc683f
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/result.rs:1311:22
  40:     0x7f78ad514e88 - core::fmt::builders::DebugInner::entry::h88a4247fc2119573
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/builders.rs:390:23
  41:     0x7f78ad514f49 - core::fmt::builders::DebugSet::entry::h369c1f9382734160
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/builders.rs:479:9
  42:     0x7f78aec235ed - <core[95c145b1f11c2ef3]::fmt::builders::DebugList>::entries::<&rustc_middle[54f726bc1ff843e8]::mir::Operand, core[95c145b1f11c2ef3]::slice::iter::Iter<rustc_middle[54f726bc1ff843e8]::mir::Operand>>
  43:     0x7f78aebf1d52 - <[rustc_middle[54f726bc1ff843e8]::mir::Operand] as core[95c145b1f11c2ef3]::fmt::Debug>::fmt
  44:     0x7f78ad51769c - core::fmt::write::h3e5b6f29124944f2
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1190:17
  45:     0x7f78ad5185c4 - core::fmt::Formatter::write_fmt::h23d0734773a3404c
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1644:9
  46:     0x7f78aebf040d - <rustc_middle[54f726bc1ff843e8]::mir::Rvalue as core[95c145b1f11c2ef3]::fmt::Debug>::fmt
  47:     0x7f78ad51769c - core::fmt::write::h3e5b6f29124944f2
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1190:17
  48:     0x7f78ad5185c4 - core::fmt::Formatter::write_fmt::h23d0734773a3404c
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1644:9
  49:     0x7f78aebef38e - <rustc_middle[54f726bc1ff843e8]::mir::Statement as core[95c145b1f11c2ef3]::fmt::Debug>::fmt
  50:     0x7f78ad517617 - core::fmt::run::hf5938b3d24764f7f
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1238:5
  51:     0x7f78ad517617 - core::fmt::write::h3e5b6f29124944f2
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:1206:26
  52:     0x7f78ad50ad1a - core::fmt::Write::write_fmt::h9a2f3ae66495f002
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/core/src/fmt/mod.rs:186:9
  53:     0x7f78ad50ad1a - alloc::fmt::format::h7fddae664e350972
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/alloc/src/fmt.rs:597:5
  54:     0x7f78aebe7e9f - rustc_middle[54f726bc1ff843e8]::mir::pretty::write_mir_pretty::{closure#0}
  55:     0x7f78aebe6d12 - rustc_middle[54f726bc1ff843e8]::mir::pretty::write_mir_pretty
  56:     0x7f78ade6fee7 - rustc_mir_transform[1fd4d79f3cd46a65]::dump_mir::emit_mir
  57:     0x7f78afae3ad9 - <rustc_interface[47e598c4883003da]::passes::QueryContext>::enter::<<rustc_interface[47e598c4883003da]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[95c145b1f11c2ef3]::result::Result<alloc[78bb397c44a79a8c]::boxed::Box<dyn core[95c145b1f11c2ef3]::any::Any>, rustc_errors[510fcacd8a67285a]::ErrorReported>>
  58:     0x7f78afada08f - <rustc_interface[47e598c4883003da]::queries::Queries>::ongoing_codegen
  59:     0x7f78afaa4bcb - rustc_interface[47e598c4883003da]::interface::create_compiler_and_run::<core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>, rustc_driver[bd9cd877565bda13]::run_compiler::{closure#1}>
  60:     0x7f78afa8a243 - std[c5462c1bfd218a1c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[47e598c4883003da]::util::run_in_thread_pool_with_globals<rustc_interface[47e598c4883003da]::interface::run_compiler<core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>, rustc_driver[bd9cd877565bda13]::run_compiler::{closure#1}>::{closure#0}, core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>>::{closure#0}, core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>>
  61:     0x7f78afabd219 - <<std[c5462c1bfd218a1c]::thread::Builder>::spawn_unchecked_<rustc_interface[47e598c4883003da]::util::run_in_thread_pool_with_globals<rustc_interface[47e598c4883003da]::interface::run_compiler<core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>, rustc_driver[bd9cd877565bda13]::run_compiler::{closure#1}>::{closure#0}, core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>>::{closure#0}, core[95c145b1f11c2ef3]::result::Result<(), rustc_errors[510fcacd8a67285a]::ErrorReported>>::{closure#1} as core[95c145b1f11c2ef3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  62:     0x7f78ad4c6263 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h999d90366a7ea653
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/alloc/src/boxed.rs:1854:9
  63:     0x7f78ad4c6263 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h698a3a9df94c6dbd
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/alloc/src/boxed.rs:1854:9
  64:     0x7f78ad4c6263 - std::sys::unix::thread::Thread::new::thread_start::he468d1e19370709b
                               at /rustc/930fc4f59ddeb9f26d554a2c75c5355989189540/library/std/src/sys/unix/thread.rs:108:17
  65:     0x7f78ad3cb259 - start_thread
  66:     0x7f78ad2e75e3 - __GI___clone
  67:                0x0 - <unknown>

note: 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.60.0-nightly (930fc4f59 2022-02-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3

query stack during panic:
#0 [try_destructure_const] destructure constant
end of query stack
error: aborting due to 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 Feb 17, 2022
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Feb 17, 2022

searched toolchains 6bf3008 through 930fc4f


Regression in 75d9a0a


which is my rollup 😅 : ...
Maybe #94020 ? cc @tmiasko

@matthiaskrgr
Copy link
Member Author

Reduced:

#[derive(Copy, Clone)]
enum Never {}

union Foo {
    a: u64,
    b: Never
}

fn main() {
    let _f = [Foo { a: 42 }];
}

@tmiasko
Copy link
Contributor

tmiasko commented Feb 17, 2022

Thanks for report and test case.

In #94020, I removed the special case for enums without variants, expecting that now that we handle read_discriminant failure gracefully it would be caught there. Alas, in this specific case, the read_discriminant succeeds while returning a non-existing variant index.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 19, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 19, 2022
Fix pretty printing of enums without variants

92d20c4 removed no-variants special case from `try_destructure_const` with expectation that this case would be handled gracefully when `read_discriminant` returns an error.

Alas in that case `read_discriminant` succeeds while returning a non-existing variant, so the special case is still necessary.

Fixes rust-lang#94073.

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 19, 2022
Fix pretty printing of enums without variants

92d20c4 removed no-variants special case from `try_destructure_const` with expectation that this case would be handled gracefully when `read_discriminant` returns an error.

Alas in that case `read_discriminant` succeeds while returning a non-existing variant, so the special case is still necessary.

Fixes rust-lang#94073.

r? ``@oli-obk``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 19, 2022
Fix pretty printing of enums without variants

92d20c4 removed no-variants special case from `try_destructure_const` with expectation that this case would be handled gracefully when `read_discriminant` returns an error.

Alas in that case `read_discriminant` succeeds while returning a non-existing variant, so the special case is still necessary.

Fixes rust-lang#94073.

r? ```@oli-obk```
@bors bors closed this as completed in f2d4ffe Feb 20, 2022
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. glacier ICE tracked in rust-lang/glacier. 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.

3 participants