Skip to content

ICE: None in compiler/rustc_mir_build/src/build/matches/mod.rs with feature(never_patterns) #130779

Closed
@Naserume

Description

@Naserume

Code

(reduced)

#![feature(never_patterns)]

enum E { A }

fn main() {
    match E::A {
        ! |
        if true => {}
    }
}

(original)

// In this regression test we check that a trailing `|` in an or-pattern just
// before the `if` token of a `match` guard will receive parser recovery with
// an appropriate error message.

enum E { A, B }

fn main() {
    match E::A {
        ! | //~ ERROR a trailing `|` is not allowed in an or-pattern
        if true => {
            let recovery_witness: bool = 0; //~ ERROR mismatched types
        }
    }
}

Command: rustc ./7FFF.rs

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (7042c269c 2024-09-23)
binary: rustc
commit-hash: 7042c269c166191cd5d8daf0409890903df7af57
commit-date: 2024-09-23
host: x86_64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0

Error output

error: a trailing `|` is not allowed in an or-pattern
 --> ./7FFF.rs:7:11
  |
7 |         ! |
  |         - ^
  |         |
  |         while parsing this or-pattern starting here
  |
help: remove the `|`
  |
7 -         ! |
7 +         ! 
  |

warning: the feature `never_patterns` is incomplete and may not be safe to use and/or cause compiler crashes
 --> ./7FFF.rs:1:12
  |
1 | #![feature(never_patterns)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: a never pattern is always unreachable
 --> ./7FFF.rs:8:20
  |
8 |         if true => {}
  |                    ^^
  |                    |
  |                    this will never be executed
  |                    help: remove this expression

error: mismatched types
 --> ./7FFF.rs:7:9
  |
7 |         ! |
  |         ^ a never pattern must be used on an uninhabited type
  |
  = note: the matched value is of type `E`

Backtrace

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/matches/mod.rs:1425:56:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:        0x117eeb3a7 - std::backtrace::Backtrace::create::h20048774a7df5a42
   1:        0x117eeb2f5 - std::backtrace::Backtrace::force_capture::ha939d1bf254d9107
   2:        0x115d1610e - std[d09fc85cb84ad7b]::panicking::update_hook::<alloc[d02d8d2ad132a946]::boxed::Box<rustc_driver_impl[4d5b267f1f304c4d]::install_ice_hook::{closure#0}>>::{closure#0}
   3:        0x117f06958 - std::panicking::rust_panic_with_hook::he2dff332e785153d
   4:        0x117f06595 - std::panicking::begin_panic_handler::{{closure}}::h873e97cbcdcf63ab
   5:        0x117f03d29 - std::sys::backtrace::__rust_end_short_backtrace::h81ffb9aee4e709dc
   6:        0x117f0620c - _rust_begin_unwind
   7:        0x11ab2063f - core::panicking::panic_fmt::h5235a0c22d55122a
   8:        0x11ab206e4 - core::panicking::panic::h0adbbbe009b54c8c
   9:        0x11ab205b8 - core::option::unwrap_failed::h1124b7069689f6d9
  10:        0x116c21408 - rustc_mir_build[a43d6420dfdfbc61]::build::matches::traverse_candidate::<rustc_mir_build[a43d6420dfdfbc61]::build::matches::Candidate, alloc[d02d8d2ad132a946]::vec::Vec<rustc_mir_build[a43d6420dfdfbc61]::build::matches::PatternExtraData>, alloc[d02d8d2ad132a946]::vec::into_iter::IntoIter<rustc_mir_build[a43d6420dfdfbc61]::build::matches::Candidate>, <rustc_mir_build[a43d6420dfdfbc61]::build::matches::MatchTreeBranch>::from_candidate::{closure#0}, <rustc_mir_build[a43d6420dfdfbc61]::build::matches::MatchTreeBranch>::from_candidate::{closure#1}, <rustc_mir_build[a43d6420dfdfbc61]::build::matches::MatchTreeBranch>::from_candidate::{closure#2}>
  11:        0x116c22b41 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::lower_match_tree
  12:        0x116c67413 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::expr_into_dest
  13:        0x116c696c1 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::expr_into_dest::{closure#0}
  14:        0x116c64c02 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::expr_into_dest
  15:        0x116c0459c - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::ast_block_stmts
  16:        0x116c6aed3 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::in_scope::<<rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::ast_block::{closure#0}, ()>
  17:        0x116c65406 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::expr_into_dest
  18:        0x116c696c1 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::expr_into_dest::{closure#0}
  19:        0x116c64c02 - <rustc_mir_build[a43d6420dfdfbc61]::build::Builder>::expr_into_dest
  20:        0x116bf5e59 - rustc_mir_build[a43d6420dfdfbc61]::build::construct_fn
  21:        0x116bf12ad - rustc_mir_build[a43d6420dfdfbc61]::build::mir_build
  22:        0x116ee9f1c - rustc_mir_transform[5a9fb0fb7b7274f7]::mir_built
  23:        0x11755a7aa - rustc_query_impl[f79aee8be8e599e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f79aee8be8e599e2]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5020b1062cd3ce07]::query::erase::Erased<[u8; 8usize]>>
  24:        0x1173b45ae - rustc_query_system[7eae2b3ce34a8ac8]::query::plumbing::try_execute_query::<rustc_query_impl[f79aee8be8e599e2]::DynamicConfig<rustc_query_system[7eae2b3ce34a8ac8]::query::caches::VecCache<rustc_span[89bbbdd941a6c1aa]::def_id::LocalDefId, rustc_middle[5020b1062cd3ce07]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[f79aee8be8e599e2]::plumbing::QueryCtxt, false>
  25:        0x11756f1ca - rustc_query_impl[f79aee8be8e599e2]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  26:        0x116c39daf - rustc_mir_build[a43d6420dfdfbc61]::check_unsafety::check_unsafety
  27:        0x11755606a - rustc_query_impl[f79aee8be8e599e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f79aee8be8e599e2]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5020b1062cd3ce07]::query::erase::Erased<[u8; 0usize]>>
  28:        0x1173a46a8 - rustc_query_system[7eae2b3ce34a8ac8]::query::plumbing::try_execute_query::<rustc_query_impl[f79aee8be8e599e2]::DynamicConfig<rustc_query_system[7eae2b3ce34a8ac8]::query::caches::VecCache<rustc_span[89bbbdd941a6c1aa]::def_id::LocalDefId, rustc_middle[5020b1062cd3ce07]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f79aee8be8e599e2]::plumbing::QueryCtxt, false>
  29:        0x117583cb0 - rustc_query_impl[f79aee8be8e599e2]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  30:        0x116638162 - <rustc_middle[5020b1062cd3ce07]::hir::map::Map>::par_body_owners::<rustc_interface[1a7e4363985fe64]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  31:        0x1166e442c - rustc_interface[1a7e4363985fe64]::passes::run_required_analyses
  32:        0x1166e6e40 - rustc_interface[1a7e4363985fe64]::passes::analysis
  33:        0x11755a4aa - rustc_query_impl[f79aee8be8e599e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f79aee8be8e599e2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5020b1062cd3ce07]::query::erase::Erased<[u8; 1usize]>>
  34:        0x117313f4e - rustc_query_system[7eae2b3ce34a8ac8]::query::plumbing::try_execute_query::<rustc_query_impl[f79aee8be8e599e2]::DynamicConfig<rustc_query_system[7eae2b3ce34a8ac8]::query::caches::SingleCache<rustc_middle[5020b1062cd3ce07]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f79aee8be8e599e2]::plumbing::QueryCtxt, false>
  35:        0x117566b37 - rustc_query_impl[f79aee8be8e599e2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:        0x115cbf647 - <rustc_interface[1a7e4363985fe64]::queries::QueryResult<&rustc_middle[5020b1062cd3ce07]::ty::context::GlobalCtxt>>::enter::<core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>, rustc_driver_impl[4d5b267f1f304c4d]::run_compiler::{closure#0}::{closure#1}::{closure#5}>
  37:        0x115d1d29d - rustc_interface[1a7e4363985fe64]::interface::run_compiler::<core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>, rustc_driver_impl[4d5b267f1f304c4d]::run_compiler::{closure#0}>::{closure#1}
  38:        0x115d0825c - std[d09fc85cb84ad7b]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1a7e4363985fe64]::util::run_in_thread_with_globals<rustc_interface[1a7e4363985fe64]::util::run_in_thread_pool_with_globals<rustc_interface[1a7e4363985fe64]::interface::run_compiler<core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>, rustc_driver_impl[4d5b267f1f304c4d]::run_compiler::{closure#0}>::{closure#1}, core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>>::{closure#0}, core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>>
  39:        0x115d1f85a - <<std[d09fc85cb84ad7b]::thread::Builder>::spawn_unchecked_<rustc_interface[1a7e4363985fe64]::util::run_in_thread_with_globals<rustc_interface[1a7e4363985fe64]::util::run_in_thread_pool_with_globals<rustc_interface[1a7e4363985fe64]::interface::run_compiler<core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>, rustc_driver_impl[4d5b267f1f304c4d]::run_compiler::{closure#0}>::{closure#1}, core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>>::{closure#0}, core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[43b28bbecb023e0a]::result::Result<(), rustc_span[89bbbdd941a6c1aa]::ErrorGuaranteed>>::{closure#1} as core[43b28bbecb023e0a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:        0x117f1182b - std::sys::pal::unix::thread::Thread::new::thread_start::h1828de8d8adf3dc7
  41:     0x7ff801f5318b - __pthread_start


rustc version: 1.83.0-nightly (7042c269c 2024-09-23)
platform: x86_64-apple-darwin

query stack during panic:
#0 [mir_built] building MIR for `main`
#1 [check_unsafety] unsafety-checking `main`
#2 [analysis] running analysis passes on this crate
end of query stack

Note

ICE location:

impl<'tcx> MatchTreeSubBranch<'tcx> {
fn from_sub_candidate(
candidate: Candidate<'_, 'tcx>,
parent_data: &Vec<PatternExtraData<'tcx>>,
) -> Self {
debug_assert!(candidate.match_pairs.is_empty());
MatchTreeSubBranch {
span: candidate.extra_data.span,
success_block: candidate.pre_binding_block.unwrap(),
otherwise_block: candidate.otherwise_block.unwrap(),
bindings: parent_data
.iter()
.flat_map(|d| &d.bindings)
.chain(&candidate.extra_data.bindings)
.cloned()
.collect(),
ascriptions: parent_data
.iter()
.flat_map(|d| &d.ascriptions)
.cloned()
.chain(candidate.extra_data.ascriptions)
.collect(),
is_never: candidate.extra_data.is_never,
}
}
}

@rustbot label +F-never_patterns

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-never_patterns`#![feature(never_patterns)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-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