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: None in deconstruct_pat.rs #117378

Closed
matthiaskrgr opened this issue Oct 30, 2023 · 2 comments · Fixed by #117398
Closed

ICE: None in deconstruct_pat.rs #117378

matthiaskrgr opened this issue Oct 30, 2023 · 2 comments · Fixed by #117398
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

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

fn main() {
    let mut a: u8 = 0;
    let mut b: u8 = 0;

    match (a, b) {
        (x @ 0 | x @ (1 | 2), 2 | 3) => {}
        _ => {}
    }
}

original:

fn main() {
    // Initialize test constants in a way that cannot be determined at compile time, to ensure
    // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
    // dependent conditions.
    let is_true = std::env::args().len() == 1;

    let mut a: u8 = 0;
    let mut b: u8 = 0;
    if is_true {
        a = 2;
        b = 0;
    }
    match (a, b) {
        // Or patterns generate MIR `SwitchInt` with multiple targets to the same `BasicBlock`.
        // This test confirms a fix for Issue #79569.
        (0 | 1, 2 | 3) => {}
        _ => {}
    }
    if is_true {
        a = 0;
        b = 0;
    }
    match (a, b) {
        (x @ 0 | x @ (1 | 2), 2 | 3) => {}
        _ => {}
    }
    if is_true {
        a = 2;
        b = 2;
    }
    match (a, b) {
        (0 | 1, 2 | 3) => {}
        _ => {}
    }
    if is_true {
        a = 0;
        b = 2;
    }
    match (a, b) {
        (0 | 1, 2 | 3) => {}
        _ => {}
    }
}

Version information

rustc 1.75.0-nightly (bcb5798dd 2023-10-30)
binary: rustc
commit-hash: bcb5798dd890a691644af9d371f3bd7fcc465584
commit-date: 2023-10-30
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

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

Program output

thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs:1014:57:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f3346569cfc - std::backtrace_rs::backtrace::libunwind::trace::h696e701df900a2b2
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f3346569cfc - std::backtrace_rs::backtrace::trace_unsynchronized::h0a821b5067328428
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f3346569cfc - std::sys_common::backtrace::_print_fmt::h561ba93d7dd378a2
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f3346569cfc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hadaea2aacdfa4b18
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f33465cbf50 - core::fmt::rt::Argument::fmt::haaf2e1dae680d0d4
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/core/src/fmt/rt.rs:142:9
   5:     0x7f33465cbf50 - core::fmt::write::h92a090160f936a3a
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/core/src/fmt/mod.rs:1117:17
   6:     0x7f334655db8f - std::io::Write::write_fmt::h304b2c71e3a57237
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/io/mod.rs:1763:15
   7:     0x7f3346569ae4 - std::sys_common::backtrace::_print::h805cb7447553b9fa
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f3346569ae4 - std::sys_common::backtrace::print::h7be441b9aecf7507
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f334656c777 - std::panicking::default_hook::{{closure}}::hf0f1687c23b85f00
  10:     0x7f334656c4df - std::panicking::default_hook::h1aa7ed866efb6ff4
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/panicking.rs:292:9
  11:     0x7f33490e0b80 - std[52b4fac2c1cd6916]::panicking::update_hook::<alloc[b6c0ed09a4f055cf]::boxed::Box<rustc_driver_impl[f6d8c9ab4fbb7a4c]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f334656ceb8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha095ea6a5339338c
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/alloc/src/boxed.rs:2021:9
  13:     0x7f334656ceb8 - std::panicking::rust_panic_with_hook::h96c03960eff56a0b
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/panicking.rs:783:13
  14:     0x7f334656cbd9 - std::panicking::begin_panic_handler::{{closure}}::h84d48c8fcbaa5a8e
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/panicking.rs:649:13
  15:     0x7f334656a1c6 - std::sys_common::backtrace::__rust_end_short_backtrace::hecfc998ecdf91e3f
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f334656c972 - rust_begin_unwind
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/panicking.rs:645:5
  17:     0x7f33465c8675 - core::panicking::panic_fmt::h6e82c0350c7df615
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/core/src/panicking.rs:72:14
  18:     0x7f33465c8713 - core::panicking::panic::h13c740d142feafe7
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/core/src/panicking.rs:127:5
  19:     0x7f334a73925e - <rustc_mir_build[8d4645eb8362c67e]::thir::pattern::usefulness::PatternColumn>::analyze_ctors
  20:     0x7f334a73689a - rustc_mir_build[8d4645eb8362c67e]::thir::pattern::usefulness::lint_overlapping_range_endpoints
  21:     0x7f334a736c95 - rustc_mir_build[8d4645eb8362c67e]::thir::pattern::usefulness::lint_overlapping_range_endpoints
  22:     0x7f334a7353f3 - rustc_mir_build[8d4645eb8362c67e]::thir::pattern::usefulness::compute_match_usefulness
  23:     0x7f33474de4e1 - <rustc_mir_build[8d4645eb8362c67e]::thir::pattern::check_match::MatchVisitor as rustc_middle[13e6374ce232bd81]::thir::visit::Visitor>::visit_expr
  24:     0x7f33474ddbc9 - <rustc_mir_build[8d4645eb8362c67e]::thir::pattern::check_match::MatchVisitor as rustc_middle[13e6374ce232bd81]::thir::visit::Visitor>::visit_expr
  25:     0x7f33474de7e3 - <rustc_mir_build[8d4645eb8362c67e]::thir::pattern::check_match::MatchVisitor as rustc_middle[13e6374ce232bd81]::thir::visit::Visitor>::visit_expr
  26:     0x7f33474ddbc9 - <rustc_mir_build[8d4645eb8362c67e]::thir::pattern::check_match::MatchVisitor as rustc_middle[13e6374ce232bd81]::thir::visit::Visitor>::visit_expr
  27:     0x7f334a730bd4 - rustc_mir_build[8d4645eb8362c67e]::thir::pattern::check_match::check_match
  28:     0x7f334a730947 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 1usize]>>
  29:     0x7f334a73036b - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  30:     0x7f334a73011d - rustc_query_impl[d72368bb483549e]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7f334a6f3b3a - rustc_mir_build[8d4645eb8362c67e]::build::mir_built
  32:     0x7f334a6f39f1 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7f334a34aa2c - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  34:     0x7f334a34a410 - rustc_query_impl[d72368bb483549e]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7f33479ed39e - rustc_mir_transform[f35e55d77e06c6f7]::check_unsafety::unsafety_check_result
  36:     0x7f334a34a807 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::unsafety_check_result::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>
  37:     0x7f334a34aa2c - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  38:     0x7f334a34a4d0 - rustc_query_impl[d72368bb483549e]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f334a34b51a - rustc_mir_transform[f35e55d77e06c6f7]::mir_const
  40:     0x7f334a34b467 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::mir_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>
  41:     0x7f334a34aa2c - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  42:     0x7f334a34a590 - rustc_query_impl[d72368bb483549e]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7f33486e4b2a - rustc_mir_transform[f35e55d77e06c6f7]::mir_promoted
  44:     0x7f334a76b7d2 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 16usize]>>
  45:     0x7f334a76ba40 - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  46:     0x7f334a76b6d3 - rustc_query_impl[d72368bb483549e]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  47:     0x7f334afa24a1 - rustc_borrowck[743c78a69b92f584]::mir_borrowck
  48:     0x7f334afa2417 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>
  49:     0x7f334a34aa2c - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  50:     0x7f334a34a650 - rustc_query_impl[d72368bb483549e]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7f334aa128c8 - rustc_interface[6394f483f79c51a]::passes::analysis
  52:     0x7f334aa121b5 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 1usize]>>
  53:     0x7f334ad231e6 - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::SingleCache<rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  54:     0x7f334ad23015 - rustc_query_impl[d72368bb483549e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  55:     0x7f334af1aeb4 - std[52b4fac2c1cd6916]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6394f483f79c51a]::util::run_in_thread_with_globals<rustc_interface[6394f483f79c51a]::interface::run_compiler<core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>, rustc_driver_impl[f6d8c9ab4fbb7a4c]::run_compiler::{closure#1}>::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>
  56:     0x7f334af1a173 - <<std[52b4fac2c1cd6916]::thread::Builder>::spawn_unchecked_<rustc_interface[6394f483f79c51a]::util::run_in_thread_with_globals<rustc_interface[6394f483f79c51a]::interface::run_compiler<core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>, rustc_driver_impl[f6d8c9ab4fbb7a4c]::run_compiler::{closure#1}>::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>::{closure#1} as core[68a6506991500897]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7f3346577c85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5c45b6a24e5f1474
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/alloc/src/boxed.rs:2007:9
  58:     0x7f3346577c85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h18b35e832435abd8
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/alloc/src/boxed.rs:2007:9
  59:     0x7f3346577c85 - std::sys::unix::thread::Thread::new::thread_start::h4880d4dbe7e5215f
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7f33463419eb - <unknown>
  61:     0x7f33463c57cc - <unknown>
  62:                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.75.0-nightly (bcb5798dd 2023-10-30) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`
#2 [unsafety_check_result] unsafety-checking `main`
#3 [mir_const] preparing `main` for borrow checking
#4 [mir_promoted] promoting constants in MIR for `main`
#5 [mir_borrowck] borrow-checking `main`
#6 [analysis] running analysis passes on this crate
end of query stack

@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 Oct 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@matthiaskrgr
Copy link
Member Author

#116751 cc @Nadrieril

@Nadrieril
Copy link
Member

Nadrieril commented Oct 30, 2023

Oh I see, nested or-patterns are usually flattened except not here because of the @ bindings! Fix incoming, thanks again @matthiaskrgr!

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@bors bors closed this as completed in 342483c Oct 30, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 30, 2023
Rollup merge of rust-lang#117398 - Nadrieril:fix-117378, r=compiler-errors

Correctly handle nested or-patterns in exhaustiveness

I had assumed nested or-patterns were flattened, and they mostly are but not always.

Fixes rust-lang#117378
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

Successfully merging a pull request may close this issue.

4 participants