Skip to content

ICE: leaf_candidate.false_edge_start_block.is_some() duplicate match arm #133117

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
matthiaskrgr opened this issue Nov 16, 2024 · 1 comment · Fixed by #135409
Closed

ICE: leaf_candidate.false_edge_start_block.is_some() duplicate match arm #133117

matthiaskrgr opened this issue Nov 16, 2024 · 1 comment · Fixed by #135409
Assignees
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. F-never_patterns `#![feature(never_patterns)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Nov 16, 2024

Code

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

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (917a50a03 2024-11-15)
binary: rustc
commit-hash: 917a50a03931a9861c19a46f3e2a02a28f1da936
commit-date: 2024-11-15
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Error output

error[E0658]: `!` patterns are experimental
 --> f.rs:3:10
  |
3 |         (!|!) if true => {}
  |          ^
  |
  = note: see issue #118155 <https://github.com/rust-lang/rust/issues/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
 --> f.rs:3:12
  |
3 |         (!|!) if true => {}
  |            ^
  |
  = note: see issue #118155 <https://github.com/rust-lang/rust/issues/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
 --> f.rs:4:10
  |
4 |         (!|!) if true => {}
  |          ^
  |
  = note: see issue #118155 <https://github.com/rust-lang/rust/issues/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
 --> f.rs:4:12
  |
4 |         (!|!) if true => {}
  |            ^
  |
  = note: see issue #118155 <https://github.com/rust-lang/rust/issues/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
 --> f.rs:3:9
  |
3 |         (!|!) if true => {}
  |         ^   ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 -         (!|!) if true => {}
3 +         !|! if true => {}
  |

warning: unnecessary parentheses around pattern
 --> f.rs:4:9
  |
4 |         (!|!) if true => {}
  |         ^   ^
  |
help: remove these parentheses
  |
4 -         (!|!) if true => {}
4 +         !|! if true => {}
  |

error: a never pattern is always unreachable
 --> f.rs:3:26
  |
3 |         (!|!) if true => {}
  |                          ^^
  |                          |
  |                          this will never be executed
  |                          help: remove this expression

error: a never pattern is always unreachable
 --> f.rs:4:26
  |
4 |         (!|!) if true => {}
  |                          ^^
  |                          |
  |                          this will never be executed
  |                          help: remove this expression

error: mismatched types
 --> f.rs:3:10
  |
3 |         (!|!) if true => {}
  |          ^ a never pattern must be used on an uninhabited type
  |
  = note: the matched value is of type `()`

error: mismatched types
 --> f.rs:3:12
  |
3 |         (!|!) if true => {}
  |            ^ a never pattern must be used on an uninhabited type
  |
  = note: the matched value is of type `()`
Backtrace

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/matches/mod.rs:1550:17:
assertion failed: leaf_candidate.false_edge_start_block.is_some()
stack backtrace:
   0:     0x79de1e881b0a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hf209b603f512c5df
   1:     0x79de1f003f26 - core::fmt::write::hb7459499d17d36c1
   2:     0x79de2042e891 - std::io::Write::write_fmt::h4275802de0932d6f
   3:     0x79de1e881962 - std::sys::backtrace::BacktraceLock::print::hfbfa2f755b02b3d5
   4:     0x79de1e883e66 - std::panicking::default_hook::{{closure}}::h807768543f95a41b
   5:     0x79de1e883cb0 - std::panicking::default_hook::h7a17744703ed785c
   6:     0x79de1d909571 - std[7202c64df357eec]::panicking::update_hook::<alloc[27366bf968cf5613]::boxed::Box<rustc_driver_impl[45f2b7ecc3390aac]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x79de1e884578 - std::panicking::rust_panic_with_hook::h4fba84c8b130fcc8
   8:     0x79de1e884316 - std::panicking::begin_panic_handler::{{closure}}::h9a05dc892413e069
   9:     0x79de1e881fb9 - std::sys::backtrace::__rust_end_short_backtrace::hb562433a6e41eea6
  10:     0x79de1e88400c - rust_begin_unwind
  11:     0x79de1b2e1030 - core::panicking::panic_fmt::hb2b4d3a454bfbc1d
  12:     0x79de1c2b14ec - core::panicking::panic::h4826b1ec2849648d
  13:     0x79de1f2fab32 - rustc_mir_build[7b3a9d387328b746]::build::matches::traverse_candidate::<&mut rustc_mir_build[7b3a9d387328b746]::build::matches::Candidate, (), core[426ecb0f3488faf5]::iter::adapters::rev::Rev<core[426ecb0f3488faf5]::slice::iter::IterMut<rustc_mir_build[7b3a9d387328b746]::build::matches::Candidate>>, <rustc_mir_build[7b3a9d387328b746]::build::matches::Candidate>::visit_leaves_rev<<rustc_mir_build[7b3a9d387328b746]::build::Builder>::lower_match_tree::{closure#1}>::{closure#0}, <rustc_mir_build[7b3a9d387328b746]::build::matches::Candidate>::visit_leaves_rev<<rustc_mir_build[7b3a9d387328b746]::build::Builder>::lower_match_tree::{closure#1}>::{closure#1}, <rustc_mir_build[7b3a9d387328b746]::build::matches::Candidate>::visit_leaves_rev<<rustc_mir_build[7b3a9d387328b746]::build::Builder>::lower_match_tree::{closure#1}>::{closure#2}>
  14:     0x79de1f2fa14b - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::lower_match_tree
  15:     0x79de1f2d86f2 - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::expr_into_dest
  16:     0x79de1f2d9b8a - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::expr_into_dest
  17:     0x79de1fcca02b - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::ast_block_stmts
  18:     0x79de1fcc8f8c - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::ast_block
  19:     0x79de1f2d7a4e - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::expr_into_dest
  20:     0x79de1f2d9b8a - <rustc_mir_build[7b3a9d387328b746]::build::Builder>::expr_into_dest
  21:     0x79de1f2e9469 - rustc_mir_build[7b3a9d387328b746]::build::mir_build
  22:     0x79de1f007d04 - rustc_mir_transform[270f2df9b7743285]::mir_built
  23:     0x79de1f007cc7 - rustc_query_impl[fea741c774525841]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fea741c774525841]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[19aa9677ff432410]::query::erase::Erased<[u8; 8usize]>>
  24:     0x79de1f537781 - rustc_query_system[4942b57954000236]::query::plumbing::try_execute_query::<rustc_query_impl[fea741c774525841]::DynamicConfig<rustc_query_system[4942b57954000236]::query::caches::VecCache<rustc_span[7bb8b1398364d9ae]::def_id::LocalDefId, rustc_middle[19aa9677ff432410]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[fea741c774525841]::plumbing::QueryCtxt, false>
  25:     0x79de1f53734d - rustc_query_impl[fea741c774525841]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  26:     0x79de1b47ef01 - rustc_mir_build[7b3a9d387328b746]::check_unsafety::check_unsafety
  27:     0x79de1f87a87d - rustc_query_impl[fea741c774525841]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fea741c774525841]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[19aa9677ff432410]::query::erase::Erased<[u8; 0usize]>>
  28:     0x79de1f87ab1c - rustc_query_system[4942b57954000236]::query::plumbing::try_execute_query::<rustc_query_impl[fea741c774525841]::DynamicConfig<rustc_query_system[4942b57954000236]::query::caches::VecCache<rustc_span[7bb8b1398364d9ae]::def_id::LocalDefId, rustc_middle[19aa9677ff432410]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[fea741c774525841]::plumbing::QueryCtxt, false>
  29:     0x79de1f87a7c1 - rustc_query_impl[fea741c774525841]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  30:     0x79de1f761c2c - rustc_interface[923321855aedf668]::passes::run_required_analyses
  31:     0x79de1ffae75e - rustc_interface[923321855aedf668]::passes::analysis
  32:     0x79de1ffae72f - rustc_query_impl[fea741c774525841]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fea741c774525841]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[19aa9677ff432410]::query::erase::Erased<[u8; 1usize]>>
  33:     0x79de1ffd5cee - rustc_query_system[4942b57954000236]::query::plumbing::try_execute_query::<rustc_query_impl[fea741c774525841]::DynamicConfig<rustc_query_system[4942b57954000236]::query::caches::SingleCache<rustc_middle[19aa9677ff432410]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fea741c774525841]::plumbing::QueryCtxt, false>
  34:     0x79de1ffd59ce - rustc_query_impl[fea741c774525841]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  35:     0x79de1fee593a - rustc_interface[923321855aedf668]::interface::run_compiler::<core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>, rustc_driver_impl[45f2b7ecc3390aac]::run_compiler::{closure#0}>::{closure#1}
  36:     0x79de1ff887d0 - std[7202c64df357eec]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[923321855aedf668]::util::run_in_thread_with_globals<rustc_interface[923321855aedf668]::util::run_in_thread_pool_with_globals<rustc_interface[923321855aedf668]::interface::run_compiler<core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>, rustc_driver_impl[45f2b7ecc3390aac]::run_compiler::{closure#0}>::{closure#1}, core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>>::{closure#0}, core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>>
  37:     0x79de1ff88beb - <<std[7202c64df357eec]::thread::Builder>::spawn_unchecked_<rustc_interface[923321855aedf668]::util::run_in_thread_with_globals<rustc_interface[923321855aedf668]::util::run_in_thread_pool_with_globals<rustc_interface[923321855aedf668]::interface::run_compiler<core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>, rustc_driver_impl[45f2b7ecc3390aac]::run_compiler::{closure#0}>::{closure#1}, core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>>::{closure#0}, core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[426ecb0f3488faf5]::result::Result<(), rustc_span[7bb8b1398364d9ae]::ErrorGuaranteed>>::{closure#1} as core[426ecb0f3488faf5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x79de1ff896b9 - std::sys::pal::unix::thread::Thread::new::thread_start::h10999df32e8f1e96
  39:     0x79de217b139d - <unknown>
  40:     0x79de2183649c - <unknown>
  41:                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: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/im/rustc-ice-2024-11-16T18_50_02-873945.txt` to your bug report

query stack during panic:
#0 [mir_built] building MIR for `main`
#1 [check_unsafety] unsafety-checking `main`
end of query stack
error: aborting due to 8 previous errors; 2 warnings emitted

For more information about this error, try `rustc --explain E0658`.

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. F-never_patterns `#![feature(never_patterns)]` 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. labels Nov 16, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 16, 2024
@saethlin saethlin added A-patterns Relating to patterns and pattern matching A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 16, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Dec 16, 2024
@Shunpoco
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 22, 2025
…lse-edge-start-block, r=Nadrieril

Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block

Fixes rust-lang#133117 , and close fixes rust-lang#133063 , fixes rust-lang#130779

In order to fix ICE-133117, at first I needed to tackle to ICE-133063 (this fixed 130779 as well).

### ICE-133063 and ICE-130779
This ICE is caused by those steps:
1. An arm has or-pattern, and all of the sub-candidates are never-pattern
2. In that case, all sub-candidates are removed in remove_never_subcandidates(). So the arm (candidate) has no sub-candidate.
3. In the current implementation, if there is no sub-candidate, the function assigns `pre_binding_block` into the candidate ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L2002-L2004)). However, otherwise_block should be assigned to the candidate as well, because the otherwise_block is unwrapped in multiple place (like in lower_match_tree()). As a result, it causes the panic.

I simply added the same block as pre_binding_block into otherwise_block, but I'm wondering if there is a better block to assign to otherwise_block (is it ok to assign the same block into pre_binding and otherwise?)

### ICE-133117
This is caused by those steps:
1. There are two arms, both are or-pattern and each has one match-pair (in the test code, both are `(!|!)`), and the second arm has a guard.
2. In match_candidate() for the first arm, it expands the second arm’s sub-candidates as well ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L1800-L1805)). As a result, the root candidate of the second arm is not evaluated/modified in match_candidate(). So a false_edge_start_block is not assigned to the candidate.
3. merge_trivial_subcandidates() is called against the candidate for the second arm. It just returns immediately because the candidate has a guard. So a flase_edge_start_block is not assigned to the candidate also in this function.
4. remove_never_subcandidates() is called against the candidate. Since all sub-candidates are never-pattern. they are removed.
5. In lower_match_tree(), since there is no sub-candidate for the candidate, the candidate itself is evaluated in visit_leave_rev ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L1532)). Because the candidate has no false_edge_start_block, it causes the panic.

So I modified the order of if blocks in merge_trivial_subcandidates() to assign a false_edge_start_block if the candidate doesn't have.
@bors bors closed this as completed in f875983 Jan 23, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. F-never_patterns `#![feature(never_patterns)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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