rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.56k stars 12.74k forks source link

ICE: compiler/rustc_mir_build/src/build/matches/mod.rs `None` #133063

Open matthiaskrgr opened 3 hours ago

matthiaskrgr commented 3 hours ago

auto-reduced (treereduce-rust):


fn split_last(_: &()) -> Option<(&i32, &i32)> {
    None
}

fn assign_twice() {
    loop {
        match () {

            (! | !) if let _ = split_last(&()) => {}
            _ => {}
        }
    }
}

original:

//@ check-pass

#![feature(if_let_guard)]

fn split_last(_: &()) -> Option<(&i32, &i32)> {
    None
}

fn assign_twice() {
    loop {
        match () {
            #[allow(irrefutable_let_patterns)]
            (! | !) if let _ = split_last(&()) => {}
            _ => {}
        }
    }
}

fn main() {}

Version information

rustc 1.84.0-nightly (251dc8ad8 2024-11-15)
binary: rustc
commit-hash: 251dc8ad84492c792a7600d8c5fef2ec868a36a7
commit-date: 2024-11-15
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Possibly related line of code: https://github.com/rust-lang/rust/blob/251dc8ad84492c792a7600d8c5fef2ec868a36a7/compiler/rustc_mir_build/src/build/matches/mod.rs#L1534-L1546

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

Program output

``` error[E0658]: `if let` guards are experimental --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:21 | 13 | (! | !) if let _ = split_last(&()) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #51114 for more information = help: add `#![feature(if_let_guard)]` to the crate attributes to enable = note: this compiler was built on 2024-11-15; consider upgrading it if it is out of date = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `!` patterns are experimental --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:14 | 13 | (! | !) if let _ = split_last(&()) => {} | ^ | = note: see issue #118155 for more information = help: add `#![feature(never_patterns)]` to the crate attributes to enable = note: this compiler was built on 2024-11-15; consider upgrading it if it is out of date error[E0658]: `!` patterns are experimental --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:18 | 13 | (! | !) if let _ = split_last(&()) => {} | ^ | = note: see issue #118155 for more information = help: add `#![feature(never_patterns)]` to the crate attributes to enable = note: this compiler was built on 2024-11-15; consider upgrading it if it is out of date warning: unnecessary parentheses around pattern --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:13 | 13 | (! | !) if let _ = split_last(&()) => {} | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 13 - (! | !) if let _ = split_last(&()) => {} 13 + ! | ! if let _ = split_last(&()) => {} | error: a never pattern is always unreachable --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:51 | 13 | (! | !) if let _ = split_last(&()) => {} | ^^ | | | this will never be executed | help: remove this expression error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:17:2 | 17 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs` error: mismatched types --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:14 | 13 | (! | !) if let _ = split_last(&()) => {} | ^ a never pattern must be used on an uninhabited type | = note: the matched value is of type `()` error: mismatched types --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:18 | 13 | (! | !) if let _ = split_last(&()) => {} | ^ a never pattern must be used on an uninhabited type | = note: the matched value is of type `()` warning: irrefutable `if let` guard pattern --> /tmp/icemaker_global_tempdir.FVFwJhAXzIYI/rustc_testrunner_tmpdir_reporting.RbOs5qNwMqij/mvce.rs:13:24 | 13 | (! | !) if let _ = split_last(&()) => {} | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this pattern will always match, so the guard is useless = help: consider removing the guard and adding a `let` inside the match arm = note: `#[warn(irrefutable_let_patterns)]` on by default thread 'rustc' panicked at compiler/rustc_mir_build/src/build/matches/mod.rs:1540:76: called `Option::unwrap()` on a `None` value stack backtrace: 0: 0x79ade605a3ba - ::fmt::h3e8890c320687803 1: 0x79ade680414a - core::fmt::write::h8e02e323e721d5d3 2: 0x79ade7c2cc51 - std::io::Write::write_fmt::hfa5fc2d5ad51eab4 3: 0x79ade605a212 - std::sys::backtrace::BacktraceLock::print::hef9ddff43c45c466 4: 0x79ade605c716 - std::panicking::default_hook::{{closure}}::he4ae1ef11715c038 5: 0x79ade605c560 - std::panicking::default_hook::h4571154760051e3a 6: 0x79ade50e4281 - std[575dabc3fc23637d]::panicking::update_hook::>::{closure#0} 7: 0x79ade605ce28 - std::panicking::rust_panic_with_hook::h99e29fee3fbc2974 8: 0x79ade605cbc6 - std::panicking::begin_panic_handler::{{closure}}::h66e3972102a7eb3e 9: 0x79ade605a869 - std::sys::backtrace::__rust_end_short_backtrace::ha9860e2cc56614c6 10: 0x79ade605c8bc - rust_begin_unwind 11: 0x79ade2adde30 - core::panicking::panic_fmt::h21ce4ecfcb0cf215 12: 0x79ade2e52c6c - core::panicking::panic::h2175426ea9d4336d 13: 0x79ade40982f9 - core::option::unwrap_failed::hb947bce75902c03c 14: 0x79ade6b48ff7 - rustc_mir_build[ce774ae811bc940]::build::matches::traverse_candidate::<&mut rustc_mir_build[ce774ae811bc940]::build::matches::Candidate, (), core[678332cb0ee15b78]::iter::adapters::rev::Rev>, ::visit_leaves_rev<::lower_match_tree::{closure#1}>::{closure#0}, ::visit_leaves_rev<::lower_match_tree::{closure#1}>::{closure#1}, ::visit_leaves_rev<::lower_match_tree::{closure#1}>::{closure#2}> 15: 0x79ade6b485cb - ::lower_match_tree 16: 0x79ade6b26bb2 - ::expr_into_dest 17: 0x79ade6b2804a - ::expr_into_dest 18: 0x79ade748d32b - ::ast_block_stmts 19: 0x79ade748c28c - ::ast_block 20: 0x79ade6b25f0e - ::expr_into_dest 21: 0x79ade6b29dda - ::expr_into_dest 22: 0x79ade6b1cb49 - ::as_temp::{closure#0} 23: 0x79ade6b27dbd - ::expr_into_dest 24: 0x79ade6b2804a - ::expr_into_dest 25: 0x79ade748d32b - ::ast_block_stmts 26: 0x79ade748c28c - ::ast_block 27: 0x79ade6b25f0e - ::expr_into_dest 28: 0x79ade6b2804a - ::expr_into_dest 29: 0x79ade6b378e9 - rustc_mir_build[ce774ae811bc940]::build::mir_build 30: 0x79ade6807f04 - rustc_mir_transform[b6a0096f646ee25e]::mir_built 31: 0x79ade6807ec7 - rustc_query_impl[bf1c9f3baad9eabf]::plumbing::__rust_begin_short_backtrace::> 32: 0x79ade6f12001 - rustc_query_system[d5846f7a9cb2c23f]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[bf1c9f3baad9eabf]::plumbing::QueryCtxt, false> 33: 0x79ade6f11bcd - rustc_query_impl[bf1c9f3baad9eabf]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 34: 0x79ade2c7bd71 - rustc_mir_build[ce774ae811bc940]::check_unsafety::check_unsafety 35: 0x79ade703eafd - rustc_query_impl[bf1c9f3baad9eabf]::plumbing::__rust_begin_short_backtrace::> 36: 0x79ade703ed9c - rustc_query_system[d5846f7a9cb2c23f]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[bf1c9f3baad9eabf]::plumbing::QueryCtxt, false> 37: 0x79ade703ea41 - rustc_query_impl[bf1c9f3baad9eabf]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace 38: 0x79ade6d4562c - rustc_interface[c18496298df4cf52]::passes::run_required_analyses 39: 0x79ade762961e - rustc_interface[c18496298df4cf52]::passes::analysis 40: 0x79ade76295ef - rustc_query_impl[bf1c9f3baad9eabf]::plumbing::__rust_begin_short_backtrace::> 41: 0x79ade77dee6e - rustc_query_system[d5846f7a9cb2c23f]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[bf1c9f3baad9eabf]::plumbing::QueryCtxt, false> 42: 0x79ade77deb4e - rustc_query_impl[bf1c9f3baad9eabf]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 43: 0x79ade76d963a - rustc_interface[c18496298df4cf52]::interface::run_compiler::, rustc_driver_impl[530468506af41d6d]::run_compiler::{closure#0}>::{closure#1} 44: 0x79ade7732e50 - std[575dabc3fc23637d]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[530468506af41d6d]::run_compiler::{closure#0}>::{closure#1}, core[678332cb0ee15b78]::result::Result<(), rustc_span[9778d555244491c7]::ErrorGuaranteed>>::{closure#0}, core[678332cb0ee15b78]::result::Result<(), rustc_span[9778d555244491c7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[678332cb0ee15b78]::result::Result<(), rustc_span[9778d555244491c7]::ErrorGuaranteed>> 45: 0x79ade773326b - <::spawn_unchecked_, rustc_driver_impl[530468506af41d6d]::run_compiler::{closure#0}>::{closure#1}, core[678332cb0ee15b78]::result::Result<(), rustc_span[9778d555244491c7]::ErrorGuaranteed>>::{closure#0}, core[678332cb0ee15b78]::result::Result<(), rustc_span[9778d555244491c7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[678332cb0ee15b78]::result::Result<(), rustc_span[9778d555244491c7]::ErrorGuaranteed>>::{closure#1} as core[678332cb0ee15b78]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 46: 0x79ade7733d39 - std::sys::pal::unix::thread::Thread::new::thread_start::h1176f996a4a1b888 47: 0x79ade908f39d - 48: 0x79ade911449c - 49: 0x0 - 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: please make sure that you have updated to the latest nightly note: rustc 1.84.0-nightly (251dc8ad8 2024-11-15) running on x86_64-unknown-linux-gnu query stack during panic: #0 [mir_built] building MIR for `assign_twice` #1 [check_unsafety] unsafety-checking `assign_twice` end of query stack error: aborting due to 7 previous errors; 2 warnings emitted Some errors have detailed explanations: E0601, E0658. For more information about an error, try `rustc --explain E0601`. ```

@rustbot label +F-if_let_guard

matthiaskrgr commented 2 hours ago

This bisects to #127159 cc @Nadrieril

matthiaskrgr commented 2 hours ago

smaller

fn main() {
    match () {
        (! | !) if let _ = Some(0) => {}
        _ => {}
    }
}