-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix incorrect pattern warning "unreachable pattern" #70413
Fix incorrect pattern warning "unreachable pattern" #70413
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. :)
Please also add the test cases mentioned in the OP in src/test/ui/or-patterns/issue-70413-no-unreachable-pat-and-guard.rs
, with #![deny(unreachable_patterns)]
and write // check-pass
at the top of the file. Also make sure to ./x.py test --stage 1 --bless --pass check src/test/ui
to adjust the fallout in UI tests (see also https://rustc-dev-guide.rust-lang.org/tests/adding.html).
You'll also need to run ./x.py fmt
to pacify the rustfmt checks in CI.
@@ -410,7 +410,7 @@ fn check_not_useful<'p, 'tcx>( | |||
) -> Result<(), Vec<super::Pat<'tcx>>> { | |||
let wild_pattern = cx.pattern_arena.alloc(super::Pat::wildcard_from_ty(ty)); | |||
let v = PatStack::from_pattern(wild_pattern); | |||
match is_useful(cx, matrix, &v, ConstructWitness, hir_id, true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a note re. the false
in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 4b1aa9fa
r? @varkor |
@@ -1664,7 +1669,9 @@ crate fn is_useful<'p, 'tcx>( | |||
bug!("Encountered or-pat in `v` during exhaustiveness checking") | |||
} | |||
} | |||
matrix.push(v); | |||
if !is_under_guard { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here as well re. the purpose of this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 4b1aa9fa
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@AminArria: could you rebase the three implementation-related commits into one? It's fine to have a separate commit for the tests. This just helps to keep the git history a little cleaner. After that, this all looks good, thanks! |
- Added is_under_guard parameter to _match::is_useful and only add to the matrix if false - Added comments explaining behavior
e9539f0
to
ae7fa30
Compare
@varkor did the rebase |
Thank you! @bors r=Centril,Nadrieril,varkor rollup |
📌 Commit ae7fa30 has been approved by |
…arning, r=Centril,Nadrieril,varkor Fix incorrect pattern warning "unreachable pattern" Fixes rust-lang#70372 Added `is_under_guard` parameter to `_match::is_useful` and only add it to the matrix if `false` Tested with: ```rust #![feature(or_patterns)] fn main() { match (3,42) { (a,_) | (_,a) if a > 10 => {println!("{}", a)} _ => () } match Some((3,42)) { Some((a, _)) | Some((_, a)) if a > 10 => {println!("{}", a)} _ => () } match Some((3,42)) { Some((a, _) | (_, a)) if a > 10 => {println!("{}", a)} _ => () } } ```
Rollup of 6 pull requests Successful merges: - rust-lang#70384 (Refactor object file handling) - rust-lang#70397 (add 'fn write_u16s' to Memory) - rust-lang#70413 (Fix incorrect pattern warning "unreachable pattern") - rust-lang#70428 (`error_bad_item_kind`: add help text) - rust-lang#70429 (Clean up E0459 explanation) - rust-lang#70437 (Miri float->int casts: be explicit that this is saturating) Failed merges: r? @ghost
Fixes #70372
Added
is_under_guard
parameter to_match::is_useful
and only add it to the matrix iffalse
Tested with: