-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(equatable_if_let): don't lint if pattern or initializer come from expansion #15958
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
base: master
Are you sure you want to change the base?
Conversation
|
Lintcheck changes for 8bcc093
This comment will be updated if you push new changes |
|
Looking at Lintcheck:
For the first one, unfortunately I don't think there's a way to allow cases like that while disallowing the case from original issue, since in both cases, the two sides will have equal, non-root To fix the second and third one, we'd need some way to only allow the sides (probably only one of them?) to come from a macro invocation (e.g. |
This comment has been minimized.
This comment has been minimized.
1e186cf to
9132a44
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| error: this pattern matching can be expressed using equality | ||
| --> tests/ui/equatable_if_let.rs:99:8 | ||
| | | ||
| LL | if let inline!("abc") = "abc" { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"abc" == inline!("abc")` | ||
|
|
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.
Are we expecting this test case to not be linted too?
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.
From #15958 (comment):
- serde is TP->FN: the scrutinee comes from a particular macro invocation, for which we know if the lint should fire, and whether we should suggest
==ormatches!- wasmi is FP->TN: the scrutinee comes from outside of the macro definition, but we gave a separate suggestion for each individual invocation, even though they might not be valid for the macro definition in general, which is a similar problem to the original issue. This is not to mention that the suggestion replaced the
$exprmetavariable with the contents of the arguments from the individual invocations.[..]
To fix the second and third one, we'd need some way to only allow the sides (probably only one of them?) to come from a macro invocation (e.g.
if let m!() = a->if a == m!()is fine), but not an expansion inside a macro (if let $pat = a->if a == $patis not fine), and I don't know how to do that.
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.
Now that I think about it, I think the if let m!() = a/ if let a = m!() cases can be detected by checking that at most 1 of the sides has a non-root SyntaxContext, right?
EDIT: Nope, that fails on the following:
macro_rules! generate_script {
($f:expr) => {
if let "bar" = $f {}
};
}
generate_script! { "foo" }9132a44 to
8bcc093
Compare
This means some existing test cases won't get linted anymore, but imo that's preferable to false-positives.
Fixes #14548
changelog: [
equatable_if_let]: don't lint if pattern or initializer come from expansion