-
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
Use span_suggestion_with_applicability instead of span_suggestion #3191
Conversation
this might duplicate parts of #2943 |
I've posted it because of in my linked pull request I suggest deprecation of non- This pull request is only refactoring: all changed suggestions stay Git merge strategy parameter ( |
This PR only addresses calls to The formatting of many If rust-lang/rust#54241 gets accepted and merged, I'm ok with merging this too. |
clippy_lints/src/assign_ops.rs
Outdated
"or", | ||
long, | ||
Applicability::Unspecified, | ||
); |
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.
weird indentation (for example)
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.
Is it cargo fmt
-able? If not, I'm not sure what is the correct indentation.
I was doing it manually and used judgement call it is too far right or not and whether it is distinguishable as arguments or not...
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.
rustfmt
converts this to
db.span_suggestion_with_applicability(
expr.span,
"or",
long,
Applicability::Unspecified,
);
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.
Since rust-lang/rust#54241 is S-waiting-on-bors
we should move forward with this.
Let's also add Applicability
levels here. I annotated the functions with the Applicability
levels I think would be fitting. I took @estebank approached and annotated as much as possible with MachineApplicable
.
Since I'm not sure how to handle cases where a call to snippet(_, _, "placeholder");
is involved, I annotated them with ", snippet". This could produce suggestions with Placeholders, so maybe HasPlaceholders
would be better here.
If I wasn't sure how the suggestion is generated, I just didn't add a comment. I would leave those cases as Unspecified
for now.
I would be happy if @killercup and @estebank could also look over my suggestions, in case I misjudged them.
Could you also apply the style @estebank suggested in rust-lang/rust#54241 (review) to the modified methods?
clippy_lints/src/bit_mask.rs
Outdated
e.span, | ||
"try", | ||
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), | ||
Applicability::Unspecified, |
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.
MaybeIncorrect
And indentation of the whole |db|
closure
#2943 changes the I think closing it and starting over would be a better approach. Maybe also implement this #2943 (comment) before adding |
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.
some comments but haven read all of it
span, | ||
"consider boxing the large fields to reduce the total size of the \ | ||
enum", | ||
format!("Box<{}>", snip), | ||
Applicability::Unspecified, |
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.
not MachineApplicable since changing the enum field can stop the code from compiling (since we don't also change all the sites where you destructure the enum and would need to add the box to the pattern matching)
clippy_lints/src/let_if_seq.rs
Outdated
span, | ||
"it is more idiomatic to write", | ||
sug, | ||
Applicability::Unspecified, |
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.
Applicability::HasPlaceholders
, actually: https://github.com/rust-lang-nursery/rust-clippy/blob/125907ad08853b92d35e86aecebcf0f784f348d5/tests/ui/let_if_seq.stderr#L8
we might be able to make this MachineApplicable in cases where there is no placeholders: https://github.com/rust-lang-nursery/rust-clippy/blob/125907ad08853b92d35e86aecebcf0f784f348d5/tests/ui/let_if_seq.stderr#L36
clippy_lints/src/matches.rs
Outdated
expr.span, | ||
"consider using an if/else expression", | ||
sugg, | ||
Applicability::Unspecified, |
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.
Hm, in https://github.com/rust-lang-nursery/rust-clippy/blob/125907ad08853b92d35e86aecebcf0f784f348d5/tests/ui/map_unit_fn.stderr I can see a few cases we can apply. Should probably track if there are any placeholders use (which is a good idea in general!).
Any false positives I missed?
clippy_lints/src/misc.rs
Outdated
"try", | ||
format!("let {name}{tyopt} = {initref};", | ||
name=snippet(cx, i.span, "_"), | ||
tyopt=tyopt, | ||
initref=initref)); | ||
initref=initref), | ||
Applicability::Unspecified, |
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 we be certain it almost always compiles, even without a type annotation or with just : _
?
About 25 more |
@vi oh I think you marked some comments as "resolved" which meant I didn't notice them so I didn't comment on it |
I marked each review as Resolved as soon as I edited and saved the respective file, to keep track. Is it wrong? |
Ah, no, not per se. It's just that @flip1995 worte
but I didn't see all their suggestions because I didn't expand the resolved comments |
As This way it would also catch mistakes in case I incorrectly transferred values from review comments to the code. |
Thanks @killercup for looking over my suggestions. And even a bigger thanks @vi for doing this! There are 3 I marked them as unresolved, but now they're showing as outdated. |
Applied those three changes, please check. Note that "Allow edits from maintainers." is checked, so no need to involve me for every edit. |
What's next? |
9043de4
to
987b34d
Compare
Needed a rebase due to #3194 and adjustment of applicability from comment of @estebank #3191 (comment) |
List of `Applicability::Unspecified`:clippy_lints/src/needless_pass_by_value.rs:235
clippy_lints/src/needless_pass_by_value.rs:247
clippy_lints/src/needless_pass_by_value.rs:264
clippy_lints/src/needless_pass_by_value.rs:276
clippy_lints/src/map_unit_fn.rs:219
clippy_lints/src/map_unit_fn.rs:246
clippy_lints/src/booleans.rs:400
clippy_lints/src/booleans.rs:430
clippy_lints/src/methods.rs:1187
clippy_lints/src/ptr.rs:189
clippy_lints/src/ptr.rs:200
clippy_lints/src/ptr.rs:218
clippy_lints/src/ptr.rs:228
clippy_lints/src/ptr.rs:259
clippy_lints/src/swap.rs:144
clippy_lints/src/transmute.rs:253
clippy_lints/src/transmute.rs:268
clippy_lints/src/transmute.rs:330
clippy_lints/src/transmute.rs:351
clippy_lints/src/transmute.rs:381
clippy_lints/src/transmute.rs:405
clippy_lints/src/transmute.rs:424
clippy_lints/src/transmute.rs:441
clippy_lints/src/transmute.rs:468 |
Hi! Could you leave the requested comment in #3230 for relicensing? |
Connected with rust-lang/rust#54241