-
Notifications
You must be signed in to change notification settings - Fork 1.7k
overhaul mut_mut
#15417
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?
overhaul mut_mut
#15417
Conversation
rustbot has assigned @samueltardieu. Use |
//~| mut_mut | ||
} | ||
|
||
let mut z = inline!(&mut $(&mut 3u32)); |
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.
I stopped the lint from firing when inside macros, because the $(&mut 3u32)
thing caused a bad suggestion:
&mut 3u32mut $(&mut u32)
should I try bringing the suggestion back, and if so, how?
"this expression mutably borrows a mutable reference. Consider reborrowing", | ||
"this expression mutably borrows a mutable reference", | ||
|diag| { | ||
diag.span_suggestion(expr.span, "reborrow instead", 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.
From my experience, not many people know about reborrowing -- maybe the message for the case that recommends it should link to some page that explains it?
Admittedly this is less necessary now that we've got a structured suggestion; people can just search for the term separately if they're interested
self.cx, | ||
MUT_MUT, | ||
expr.hir_id, | ||
expr.span, | ||
"generally you want to avoid `&mut &mut _` if possible", | ||
"an expression of form `&mut &mut _`", |
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 this message helpful enough?
Lintcheck changes for dcb123e
This comment will be updated if you push new changes |
a81c9a6
to
c26eb82
Compare
@cmrschwarz let me know what you think! You can see the change in the diagnostic messages in the |
Just looking at the structured suggestions, this looks exactly like what I hoped for. |
for some reason this seems to already be the case with exprs, so only do it for tys
This PR:
_unfixable.rs
, to allow running rustfix on the main file&mut &mut &mut T
Open questions:
&mut
are useless.. but can't really come up with something consice. I very much don't like the one in the docs -- it's a bit too condescending imo.I do realize that the PR ended up being quite wide-scoped, but that's primarily because once I added structured suggestions to one of the lint cases,
ui_test
started complaining about warnings remaining after the rustfix run, which of course had to with the fact that the other two lint cases didn't actually fix the code they linted, only warned. I guessui_test
could be smarter about this, by understanding that if a warning was created without a suggestion, then that warning will still remain in the fixed file. But oh well.changelog: [
mut_mut
]: add structured suggestions, improve docsfixes #13021