Skip to content

Don't ICE when a guard condition is a place of type ! - #165745

Open
lapla-cogito wants to merge 1 commit into
rust-lang:mainfrom
lapla-cogito:never_guard_expr
Open

lapla-cogito wants to merge 1 commit into
rust-lang:mainfrom
lapla-cogito:never_guard_expr

Conversation

@lapla-cogito

@lapla-cogito lapla-cogito commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #165169

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 10, 2026
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 22 candidates

@mu001999

mu001999 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

But removing the parentheses would not lead to success (play):

#![feature(guard_patterns)]
#![expect(incomplete_features)]

fn main() {
    let x: !;
    match 1 {
        (y if x) => {}
    }
}

would give

error: unexpected parentheses surrounding `match` arm pattern
 --> src/main.rs:7:9
  |
7 |         (y if x) => {}
  |         ^      ^
  |
help: remove parentheses surrounding the pattern
  |
7 -         (y if x) => {}
7 +         y if x => {}
  |

warning: unreachable expression
 --> src/main.rs:7:21
  |
7 |         (y if x) => {}
  |               -     ^^ unreachable expression
  |               |
  |               any code following this expression is unreachable
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

error[E0004]: non-exhaustive patterns: `i32::MIN..=i32::MAX` not covered
 --> src/main.rs:6:11
  |
6 |     match 1 {
  |           ^ pattern `i32::MIN..=i32::MAX` not covered
  |
  = note: the matched value is of type `i32`
  = note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
7 ~         (y if x) => {},
8 +         i32::MIN..=i32::MAX => todo!()
  |

I think the behaviors should be consistent.

@mu001999 mu001999 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2026
@lapla-cogito

lapla-cogito commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

But removing the parentheses would not lead to success (play):

#![feature(guard_patterns)]
#![expect(incomplete_features)]

fn main() {
    let x: !;
    match 1 {
        (y if x) => {}
    }
}

would give

error: unexpected parentheses surrounding `match` arm pattern
 --> src/main.rs:7:9
  |
7 |         (y if x) => {}
  |         ^      ^
  |
help: remove parentheses surrounding the pattern
  |
7 -         (y if x) => {}
7 +         y if x => {}
  |

warning: unreachable expression
 --> src/main.rs:7:21
  |
7 |         (y if x) => {}
  |               -     ^^ unreachable expression
  |               |
  |               any code following this expression is unreachable
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

error[E0004]: non-exhaustive patterns: `i32::MIN..=i32::MAX` not covered
 --> src/main.rs:6:11
  |
6 |     match 1 {
  |           ^ pattern `i32::MIN..=i32::MAX` not covered
  |
  = note: the matched value is of type `i32`
  = note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
7 ~         (y if x) => {},
8 +         i32::MIN..=i32::MAX => todo!()
  |

I think the behaviors should be consistent.

But is this really an issue that should be fixed with this patch? It seems like something that should be handled on the parser side. (Of course I can work on a follow-up PR later for this.)

@rustbot reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2026
@mu001999

Copy link
Copy Markdown
Member

But is this really an issue that should be fixed with this patch? It seems like something that should be handled on the parser side. (Of course I can work on a follow-up PR later for this.)

I think it is reasonable. And I find #164465 would support this.

Thanks!

@bors r+ rollup

@rust-bors

This comment was marked as outdated.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 13, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 13, 2026
…u001999

Don't ICE when a guard condition is a place of type `!`

Fixes rust-lang#165169
rust-bors Bot pushed a commit that referenced this pull request Nov 13, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #164828 (When suggesting path of renamed crate, use the renamed name)
 - #164864 (Avoid hoisting uninitialized reads in EarlyOtherwiseBranch)
 - #165068 (Change color usage for highlights)
 - #165221 (Canonicalize more comparison operators)
 - #165841 (Tell Miri about the alignment handling in the Windows System allocator)
 - #165869 (Cleanup: Remove `path_matches` and `value_str` from `AttributeExt`)
 - #165880 (Remove dead code for returning `BackendRepr::Memory` with `PassMode::Direct`)
 - #164108 (Add unstable `-Zllvm-tpde` flag to `rustc_codegen_llvm`)
 - #165565 (view-types: lower view types from HIR)
 - #165622 (small cleanups in rustc_codegen_llvm)
 - #165745 (Don't ICE when a guard condition is a place of type `!`)
 - #165771 (tests: cover MSVC ThinLTO exported symbol preservation)
 - #165810 (reflection: reflect attributes from adts, fields, and variants)
 - #165823 (Tweak crate error wording and turn them into fatal errors)
 - #165849 (More opt-dist improvements)
 - #165855 (Update `sysinfo` version to `0.40.3`)
 - #165872 (Some attribute related cleanups)
 - #165905 (CI: Use a consistent locale when sorting docker build inputs)
@mu001999

This comment was marked as outdated.

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 13, 2026
@rust-bors

This comment was marked as outdated.

@mu001999 mu001999 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2026
mu001999

This comment was marked as resolved.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 13, 2026
@rustbot

This comment was marked as outdated.

@mu001999

This comment was marked as outdated.

@rust-bors

rust-bors Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit fc3192b has been approved by mu001999

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2026

@WaffleLapkin WaffleLapkin left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +3 to +12
//@check-pass

#![feature(guard_patterns)]

fn main() {
let x: !;
match 1 {
((y if x)) => {}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this. This should definitely not compile. What is even going on here?

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 13, 2026
@rust-bors

rust-bors Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: place expr not allowed in pattern

4 participants