-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Don't prefix full path specification when suggesting changing & to &mut. #6385
Comments
Clippy does not have the ability to add imports, so we generally suggest the fully-qualified path to avoid generating compile errors. That being said, if I'm not mistaken rustc used to have a similar problem which was solved somehow (e.g. If we manage to use the same solution, it should be applied generally as this lint is not the only case where we do that. |
Well, I'm curious about the process here, because I don't understand why the ability to add imports interferes :( My understanding is that types are checked before mutability. If this is correct, then this lint appearing already means that the type is correctly qualified, so there is no need to query the current namespace, and just changing |
Oh my bad, ignore me, I confused this case with the case where we suggest something that may not be on scope. This should be doable. |
I could reproduce the suggestion with the full type specification in the Rust Playground. The message that this suggestion most likely originates from is: error[E0596]: cannot borrow `*me` as mutable, as it is behind a `&` reference
--> src/main.rs:3:5
|
2 | fn not_using_mut(me: &Vec<u8>) {
| -------- help: consider changing this to be a mutable reference: `&mut Vec<u8>`
3 | me.push(4);
| ^^ `me` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error: aborting due to previous error I couldn't find the message in the clippy code base. However, I found it in the rustc code in diagnostics/mutability_errors.rs line 390. So, I would think that this actually comes from the rust compiler. (I've also commented this on the rust issue) |
@xFrednet Well, I'm confused, since I don't actually read the full type spec in your playground, or in your snippet, I read This said, I can reproduce in your playground if I eventually click
So I think the problem does not occur with |
Ohhh yes you're completely right. I mixed up the output from Than it's most likely a problem with Clippy or with the combination of the two. I'll try to look into this in a week or two. Someone else can also take this issue if it sounds interesting :) Update: I didn't look further into this. This issue can be taken up if someone is interested |
(moved (again) from rust-lang/rust#79405)
With the following code:
I get a suggestion to "change this to a mutable reference", but if I do, I get:
That's a bit overkill, right? I would rather expect
It actually becomes worse. I've decided to file this bug report after my argument:
was changed to
instead of just
That's definitely overkill, so I end up changing the
&
to&mut
by hand.Is this something expected? Or something I can configure not to happen?
The text was updated successfully, but these errors were encountered: