-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore: multipart_suggestions for manual_assert #13787
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
a2618b9
to
09589ff
Compare
I could use a pointer on this one. We're trying to avoid displaying any comments that are captured within the span including the if/assert block, and only retain them in the tool-applied suggestion: rust-clippy/clippy_lints/src/manual_assert.rs Lines 68 to 84 in f83a227
I've preserved this here by keeping the tool-only suggestion, and replacing only the
The second case fails the testing, because the if/assert has not been removed. I think this is the correct behaviour from the runtime perspective, but because the testing framework automatically diverges when there are multiple suggestions, i'm stuck. Options I see:
Any tips @y21 ? |
I suppose there would also be the option to have a single multipart suggestion that removes the |
Cheers @y21 - i'll add them back in and see where we land 🙌 |
bc9e5a6
to
e146ead
Compare
Hey @y21 , do you have a chance to look at this? We are inches away from finishing the whole issue 🤣 |
Sorry for the delay, will try to get to this soon (probably this weekend). I have a bunch of other PRs + other stuff going on at the same time |
Sorry I figured it might’ve fallen through the cracks! It’s probably not a high priority so no stress. Hope you can have a good break! |
This comment has been minimized.
This comment has been minimized.
7a68957
to
a805a6f
Compare
a805a6f
to
5e448ee
Compare
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.
LGTM, thank you for pushing this through!
Looks like CI is failing with a compile error. The signature of |
clippy_lints/src/manual_assert.rs
Outdated
let base_sugg = format!("assert!({not}{cond_sugg}, {format_args_snip}){semicolon}"); | ||
|
||
let indent = indent_of(cx, expr.span); | ||
let full_sugg = reindent_multiline(format!("{comments}{base_sugg}").into(), true, indent); |
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.
While we're already here and have to change something anyway: since this base_sugg
is only used once we could inline it into the format macro directly to get rid of an allocation
let base_sugg = format!("assert!({not}{cond_sugg}, {format_args_snip}){semicolon}"); | |
let indent = indent_of(cx, expr.span); | |
let full_sugg = reindent_multiline(format!("{comments}{base_sugg}").into(), true, indent); | |
let indent = indent_of(cx, expr.span); | |
let full_sugg = reindent_multiline(&*format!("{comments}assert!({not}{cond_sugg}, {format_args_snip}){semicolon}"), true, indent); |
(may need some formatting changes if the line is too long)
Also, can you move all of this code that prepares/formats the suggestion into the span_lint_and_then
closure? The lint is in pedantic, so often the lint isn't enabled and we don't need to emit/prepare any suggestion as the closure won't be called.
This comment has been minimized.
This comment has been minimized.
Ping @scottgerring from triage. Do you plan to return to working on this? Looks like it was almost ready. |
hey @Jarcho sorry this dropped off my radar! I'll try rebase it this week. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5d8489b
to
5e448ee
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5e448ee
to
0f8c62c
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. |
3346a38
to
793c00a
Compare
Lintcheck changes for 8ef9057
This comment will be updated if you push new changes |
Hey @Jarcho I reckon this is good to go now 🙏 |
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.
One minor nit I only now realized (sorry), other than that looks good to me. Could you also squash the commits the next push? Then this should be ready to merge
clippy_lints/src/manual_assert.rs
Outdated
diag.multipart_suggestion( | ||
"replace `if`-then-`panic!` with `assert!`", | ||
vec![(expr.span, full_sugg)], | ||
applicability, |
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.
Actually, since this is just always a single suggestion now, can't we just use .span_suggestion()
now (or rather .span_suggestion_verbose()
to keep having it on a separate line)? That should be identical but removes the need for creating a vec here.
diag.multipart_suggestion( | |
"replace `if`-then-`panic!` with `assert!`", | |
vec![(expr.span, full_sugg)], | |
applicability, | |
diag.span_suggestion_verbose( | |
expr.span, | |
"replace `if`-then-`panic!` with `assert!`", | |
full_sugg, | |
applicability, | |
); |
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.
Hey @y21 im AFK on holidays at the moment, but I can certainly polish it when I’m back in a couple weeks 👌
793c00a
to
8ef9057
Compare
@y21 - let's try again :D Squashed into a single commit, using |
This should address #13099 for the let_unit test.
changelog: [manual_assert]: Updated manual_assert to use multipart_suggestions where appropriate