-
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
chore: multipart_suggestions for manual_assert #13787
base: master
Are you sure you want to change the base?
chore: multipart_suggestions for manual_assert #13787
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 |
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 should address #13099 for the let_unit test.
changelog: [manual_assert]: Updated manual_assert to use multipart_suggestions where appropriate