Skip to content

ICE: expression with never type wound up being adjusted #121445

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn test2() {
    let x: !;
    let c2 = SingleVariant::Points(_)
        | match x {
            _ => (),
        };
}

enum SingleVariant {
    Points(u32),
}
original code

original:

//@ edition:2021

#![feature(never_type)]

// Should fake read the discriminant and throw an error
fn test1() {
    let x: !;
    let c1 = || match x { };
    //~^ ERROR E0381
}

// Should fake read the discriminant and throw an error
fn test2() {
    let x: !;
    let c2 = SingleVariant::Points(_)| match x { _ => () };
    //~^ ERROR E0381
}

// Testing single variant patterns
enum SingleVariant {
    Points(u32)
}

// Should fake read the discriminant and throw an error
fn test3() {
    let variant: !;
    let c = || {
    //~^ ERROR E0381
        match variant {
            SingleVariant::Points(_) => {}
        }
    };
    c();
}

// Should fake read the discriminant and throw an error
fn test4() {
    let variant: !;
    let c = || { //~ ERROR E0381
        match variant {
            E::Number(_) if let _ = *value => { }
            _ => {}
        }
    };
    c();
}

fn test5() {
    let t: !;
    let g: !;

    let a = || {
        match g { }; //~ ERROR E0381
        let c = ||  {
            match t { }; //~ ERROR E0381
        };

        c();
    };

}

// Should fake read the discriminant and throw an error
fn test6() {
    let x: u8;
    let c1 = || match println { };
    //~^ ERROR E0381
    //~| ERROR: non-exhaustive patterns: type `u8` is non-empty
}

fn main() {
    test1();
    test2();
    test3();
    test4();
    test5();
    test6();
}

Version information

rustc 1.78.0-nightly (f8131a48a 2024-02-21)
binary: rustc
commit-hash: f8131a48a46ac3bc8a3d0fe0477055b132cffdc3
commit-date: 2024-02-21
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

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

Program output

error[E0658]: the `!` type is experimental
 --> /tmp/icemaker_global_tempdir.OO1P1ESTXPyY/rustc_testrunner_tmpdir_reporting.nqAuSuDEp2pP/mvce.rs:2:12
  |
2 |     let x: !;
  |            ^
  |
  = note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
  = help: add `#![feature(never_type)]` to the crate attributes to enable
  = note: this compiler was built on 2024-02-21; consider upgrading it if it is out of date

error: in expressions, `_` can only be used on the left-hand side of an assignment
 --> /tmp/icemaker_global_tempdir.OO1P1ESTXPyY/rustc_testrunner_tmpdir_reporting.nqAuSuDEp2pP/mvce.rs:3:36
  |
3 |     let c2 = SingleVariant::Points(_)
  |                                    ^ `_` not allowed here

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

warning: unreachable arm
 --> /tmp/icemaker_global_tempdir.OO1P1ESTXPyY/rustc_testrunner_tmpdir_reporting.nqAuSuDEp2pP/mvce.rs:5:18
  |
4 |         | match x {
  |                 - any code following this expression is unreachable
5 |             _ => (),
  |                  ^^ unreachable arm
  |
  = note: `#[warn(unreachable_code)]` on by default

error: internal compiler error: expression with never type wound up being adjusted
 --> /tmp/icemaker_global_tempdir.OO1P1ESTXPyY/rustc_testrunner_tmpdir_reporting.nqAuSuDEp2pP/mvce.rs:4:17
  |
4 |         | match x {
  |                 ^

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/expr.rs:81:22:
Box<dyn Any>
stack backtrace:
   0:     0x7fd8e544faf6 - std::backtrace_rs::backtrace::libunwind::trace::hbec2edc838b433e2
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fd8e544faf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h88c30257ee0dd166
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fd8e544faf6 - std::sys_common::backtrace::_print_fmt::h9176654d509e3088
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fd8e544faf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h671feaee1776bf19
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fd8e54a0a7c - core::fmt::rt::Argument::fmt::h59605c83ae32d935
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/core/src/fmt/rt.rs:142:9
   5:     0x7fd8e54a0a7c - core::fmt::write::hf7af8dfcfd20db5b
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fd8e54444bf - std::io::Write::write_fmt::h92a5dbf489025e71
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/io/mod.rs:1846:15
   7:     0x7fd8e544f8a4 - std::sys_common::backtrace::_print::h00080302d23998ae
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fd8e544f8a4 - std::sys_common::backtrace::print::h6b23124445400245
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fd8e54525eb - std::panicking::default_hook::{{closure}}::hd67b2f9d36675a28
  10:     0x7fd8e5452339 - std::panicking::default_hook::h10a39ef11c714e42
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/panicking.rs:292:9
  11:     0x7fd8e207a94c - std[5a8e7f94216a9138]::panicking::update_hook::<alloc[e14ab1f516d287ab]::boxed::Box<rustc_driver_impl[e279e4f1fedd9109]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fd8e5452d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h37ba37dc48823c1d
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/alloc/src/boxed.rs:2030:9
  13:     0x7fd8e5452d50 - std::panicking::rust_panic_with_hook::he3e3bc7c345bf54b
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/panicking.rs:786:13
  14:     0x7fd8e20a7524 - std[5a8e7f94216a9138]::panicking::begin_panic::<rustc_errors[34364e5c712fab73]::ExplicitBug>::{closure#0}
  15:     0x7fd8e20a4176 - std[5a8e7f94216a9138]::sys_common::backtrace::__rust_end_short_backtrace::<std[5a8e7f94216a9138]::panicking::begin_panic<rustc_errors[34364e5c712fab73]::ExplicitBug>::{closure#0}, !>
  16:     0x7fd8e209f936 - std[5a8e7f94216a9138]::panicking::begin_panic::<rustc_errors[34364e5c712fab73]::ExplicitBug>
  17:     0x7fd8e0a17631 - <rustc_errors[34364e5c712fab73]::diagnostic::BugAbort as rustc_errors[34364e5c712fab73]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7fd8e3ab9d44 - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_match
  19:     0x7fd8e3e85f20 - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  20:     0x7fd8e388b23e - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_overloaded_binop
  21:     0x7fd8e3e861f9 - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:     0x7fd8e3924afa - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_decl
  23:     0x7fd8e3974ec6 - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_block_with_expected
  24:     0x7fd8e3e8545c - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  25:     0x7fd8e3e72b88 - rustc_hir_typeck[7492106fe3468815]::check::check_fn
  26:     0x7fd8e3653a6e - rustc_hir_typeck[7492106fe3468815]::typeck
  27:     0x7fd8e3652d17 - rustc_query_impl[9d4c51777e2bb749]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4c51777e2bb749]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7fd8e35098b0 - rustc_query_system[9b2ccfe41ae3bb1b]::query::plumbing::try_execute_query::<rustc_query_impl[9d4c51777e2bb749]::DynamicConfig<rustc_query_system[9b2ccfe41ae3bb1b]::query::caches::VecCache<rustc_span[adb133ac03280fc1]::def_id::LocalDefId, rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9d4c51777e2bb749]::plumbing::QueryCtxt, false>
  29:     0x7fd8e35093cc - rustc_query_impl[9d4c51777e2bb749]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7fd8e3daf412 - <rustc_middle[446dd094ad85939e]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[71d4294717f7f2b7]::check_crate::{closure#6}>::{closure#0}
  31:     0x7fd8e3dadcdd - rustc_hir_analysis[71d4294717f7f2b7]::check_crate
  32:     0x7fd8e3ea2dd3 - rustc_interface[7ca501d7f8f3a34f]::passes::analysis
  33:     0x7fd8e3ea2a29 - rustc_query_impl[9d4c51777e2bb749]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4c51777e2bb749]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 1usize]>>
  34:     0x7fd8e413d4a5 - rustc_query_system[9b2ccfe41ae3bb1b]::query::plumbing::try_execute_query::<rustc_query_impl[9d4c51777e2bb749]::DynamicConfig<rustc_query_system[9b2ccfe41ae3bb1b]::query::caches::SingleCache<rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9d4c51777e2bb749]::plumbing::QueryCtxt, false>
  35:     0x7fd8e413d209 - rustc_query_impl[9d4c51777e2bb749]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7fd8e414c719 - rustc_interface[7ca501d7f8f3a34f]::interface::run_compiler::<core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>, rustc_driver_impl[e279e4f1fedd9109]::run_compiler::{closure#0}>::{closure#0}
  37:     0x7fd8e43be705 - std[5a8e7f94216a9138]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_with_globals<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_pool_with_globals<rustc_interface[7ca501d7f8f3a34f]::interface::run_compiler<core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>, rustc_driver_impl[e279e4f1fedd9109]::run_compiler::{closure#0}>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>
  38:     0x7fd8e43be532 - <<std[5a8e7f94216a9138]::thread::Builder>::spawn_unchecked_<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_with_globals<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_pool_with_globals<rustc_interface[7ca501d7f8f3a34f]::interface::run_compiler<core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>, rustc_driver_impl[e279e4f1fedd9109]::run_compiler::{closure#0}>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#1} as core[85b4fd477ce5bb21]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7fd8e545c725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1bff3efb61c3fa6b
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/alloc/src/boxed.rs:2016:9
  40:     0x7fd8e545c725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h83141cf549dced8a
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/alloc/src/boxed.rs:2016:9
  41:     0x7fd8e545c725 - std::sys::pal::unix::thread::Thread::new::thread_start::hbe9287fdd7c325bc
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x7fd8df0aa9eb - <unknown>
  43:     0x7fd8df12e7cc - <unknown>
  44:                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: rustc 1.78.0-nightly (f8131a48a 2024-02-21) running on x86_64-unknown-linux-gnu

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

Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-never_type`#![feature(never_type)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions