-
Notifications
You must be signed in to change notification settings - Fork 13.4k
lint towards rejecting consts in patterns that do not implement PartialEq #115893
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
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
Some changes might have occurred in exhaustiveness checking cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
892ff5b
to
dc85202
Compare
Crucially, tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/allow-use-behind-cousin-variant.rs is still accepted; this is the example where #62411 (indirect_structural_match) was initially over-eager. |
@rust-lang/lang I found a surprising gap in our pattern-related future-incompat lints, which lead to us still accepting (without a warning) some consts as patterns that don't even implement So the question for you is, are you okay with consts in patterns requiring at least a If you are curious about what the affected code looks like, here are some examples: On both cases, the reason the constant isn't |
6ca2a35
to
3eac984
Compare
Checking in from the @rust-lang/lang meeting and unnominating: Our judgment is that this is a bug fix and only causes more warnings, so no FCP is required, and we are in favor of going forward. However, we were pretty confused about what the story is around constants and matching -- requiring a @rustbot labels -I-lang-nominated |
Yeah I think a design meeting is due, also see here. Maybe we shouldn't add further warnings until that happened, to avoid having to take back the warning again. |
I started writing up a design meeting document and there good reasons for requiring |
3eac984
to
2bbd5c3
Compare
This comment has been minimized.
This comment has been minimized.
2bbd5c3
to
31bd8e0
Compare
Regarding the lint's name, maybe it is too general? I assume you do not want to forbid code like this: enum Foo { Bar, Baz }
impl Foo {
fn is_bar(&self) -> bool {
matches!(self, Foo::Bar)
}
} Where Would the name |
31bd8e0
to
204272b
Compare
I renamed it to |
This comment has been minimized.
This comment has been minimized.
|
||
// Always check for `PartialEq`, even if we emitted other lints. (But not if there were | ||
// any errors.) This ensures it shows up in cargo's future-compat reports as well. | ||
if !self.type_has_partial_eq_impl(cv.ty()) { |
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.
There is the potential alternative of checking for Eq
here instead of PartialEq
. This would then subsume the "disallow floats in patterns" lint as well. However with t-lang in the past having been disinclined to disallow float patterns, it's not clear that we want to require Eq
.
@bors r+ let's land this and figure out the details of consts in patterns in a design meeting with T-lang |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1f2bacf): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 631.784s -> 630.892s (-0.14%) |
I think we definitely don't want to allow such consts, so even while the general plan around structural matching is up in the air, we can start the process of getting non-PartialEq matches out of the ecosystem.