Handle empty matches cleanly in exhaustiveness checking#78995
Handle empty matches cleanly in exhaustiveness checking#78995bors merged 6 commits intorust-lang:masterfrom
Conversation
We may as well leave early when we know there's nothing to report.
This make `_match` a lot more self-contained
src/test/ui/rfc-2008-non-exhaustive/enum_same_crate_empty_match.rs
Outdated
Show resolved
Hide resolved
src/test/ui/rfc-2008-non-exhaustive/enum_same_crate_empty_match.rs
Outdated
Show resolved
Hide resolved
|
As far as I can tell, the only stable code this affects are those using @bors try |
|
⌛ Trying commit b9da2b3 with merge bdf62782912af0337bb64e58890f4edbfb4e075b... |
|
☀️ Try build successful - checks-actions |
It's the opposite: |
Co-authored-by: varkor <github@varkor.com>
2025f60 to
36e3409
Compare
|
Does this change any code that's not using |
It does change stable code, and code without those gates. The only change this PR does is in the following case: enum Void{}
fn foo(x: Void) {
match x {
_ => println!("foo")
}
}Before, the branch was not linted as unreachable. Now it is. The PR does nothing else. People who use |
|
@Nadrieril: thanks for clarifying. There are so many interacting feature gates with uninhabited types that I find it a little hard to keep track sometimes. As far as I could tell, there were no tests without feature gates whose output changed here: presumably this means we haven't yet got a test in this particular situation. Could you add a test (both same-crate and cross-crate) with this example (there may already be suitable test files that they can be added to), so we make sure we're covering these? |
The |
It used to be that simply enabling the I'm happy with the implementation and tests now. I just want to make the lang team aware of this change. If there are no comments soon, I'll approve. |
|
cc @rust-lang/lang: this pull request changes behaviour of exhaustiveness checking to lint against enum Void {}
fn foo(x: Void) {
match x {
_ => println!("foo") // used not to warn, but now triggers the `unreachable_patterns` lint
}
}This fixes a long-standing inconsistency in |
Oh I see. I don't believe this is still the case. I haven't encountered any branching on this feature gate in any of the match checking code or in related code. I believe all this behavior is now gated under |
|
Thanks for the ping, @varkor! It makes sense to me to lint here. And empty enums are uncommon enough that I'd be very surprised if this were a churn problem. One thing that's probably covered somewhere but I didn't see scanning the PR so I figured I'd ask to double-check: Do we have a test that this doesn't trigger for matching on |
Yep, that's well-tested both same-crate and cross-crate by the thorough rust/src/test/ui/rfc-2008-non-exhaustive/enum.rs Lines 6 to 11 in 69821cf |
|
@bors try @rust-timer queue to make sure this isn't hitting anything like #51085 (comment) (though I have no reason to believe it is). |
|
Awaiting bors try build completion |
|
⌛ Trying commit 69821cf with merge 8e571541536bd9efc598a6905a9604e6aedf9134... |
|
☀️ Try build successful - checks-actions |
|
Queued 8e571541536bd9efc598a6905a9604e6aedf9134 with parent c6a6105, future comparison URL. |
|
Finished benchmarking try commit (8e571541536bd9efc598a6905a9604e6aedf9134): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
I was aware of this so I made sure to avoid calling |
|
Thanks for the fix, @Nadrieril! @bors r+ |
|
📌 Commit 69821cf has been approved by |
|
☀️ Test successful - checks-actions |
|
Nice :) |
This removes the special-casing of empty matches that was done in
check_match. This fixes most of #55123.Somewhat unrelatedly, I also made
_match.rsmore self-contained, because I think it's cleaner.r? @varkor
@rustbot modify labels: +A-exhaustiveness-checking