-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 [use_self]
false negative with on struct and tuple struct patterns
#8899
Fix [use_self]
false negative with on struct and tuple struct patterns
#8899
Conversation
r? @xFrednet (rust-highfive has picked a reviewer for you, use r? to override) |
r? @Alexendoo (It would be cool, if you could leave a comment so that I can assign this PR to you :)) |
👋 |
tests/ui/use_self.rs
Outdated
impl Something { | ||
const fn get_value(&self) -> u8 { | ||
match self { | ||
Something::Num(n) => *n, | ||
Something::TupleNums(n, _m) => *n, | ||
Something::StructNums { one, two: _ } => *one, | ||
} | ||
} | ||
} |
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.
Using the variants directly trigger the lint, suggesting to replace them all with Self
:
fn imported_variants(&self) -> u8 {
use Something::*;
match self {
Num(n) => *n,
TupleNums(n, _m) => *n,
StructNums { one, two: _ } => *one,
}
}
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.
Seems that's uncovering an existing bug, the first path segment is picked unconditionally
enum Enum {
A,
}
impl Enum {
fn f(self) -> usize {
match self {
crate::Enum::A => 1,
}
}
}
warning: unnecessary structure name repetition
--> t.rs:13:13
|
13 | crate::Enum::A => 1,
| ^^^^^ help: use the applicable keyword: `Self`
|
You could check the res
field of the PathSegment
s to pick the right one
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.
This was tricky. Using the res
field on the PathSegment
s doesn't seem to work. In the playground, I found that most of the res
fields had errors, so I ended up using a workaround similar to what's done in the check_expr
method. Luckily, the lint_path_to_variant
function already exists. But, it's a bit hacky, and I did find that the name of the enum is correctly shown in the res
fields. I made a version of the function which uses the res
field, and is a bit less hacky, but it's also a bit less performant. I doubt anyone would notice the difference, but I left it unchanged for now.
Thanks! Could you also squash the commits and then I think it'll be good to go |
e5d697e
to
2aa4569
Compare
@Alexendoo Should be good now |
@Alexendoo when you're happy with this PR you can r+ it directly. And we no longer need a delegate for that 🥳 |
@bors r+ |
@Alexendoo: 🔑 Insufficient privileges: Not in reviewers |
Well then. Guess the teams PR needs to happen for that yet 😄 |
Talking in bors voice Thank you for the approval @bors r=Alexendoo |
📌 Commit 2aa4569 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #8845
changelog: Triggered the warning for
[`use_self`]
onTupleStruct
andStruct
patterns, whereas currently it's only triggered forPath
patterns