-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix invalid "ref mut mut" sugestion #37531
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
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
7498116
to
5495774
Compare
5495774
to
1a5456b
Compare
I need to see the full example, but this:
Seems like it might not be correct. If you remove |
@jonathandturner the original code was (from #37139): enum TestEnum {
Item(i32),
}
fn test(x: &mut i32) {
println!("hi! {:?}", x);
}
fn main() {
let mut x = TestEnum::Item(10);
match x {
TestEnum::Item(ref mut x) => {
test(&mut x);
}
}
} When compiling it fails saying that |
Oh dear that is indeed a confusing error message ( (although that may just end up being too convoluted) |
@alexcrichton @jonathandturner I haven't been able to come up with a case where a wrong suggestion would be given. In the cases where it'd be wrong to remove the |
📌 Commit 1a5456b has been approved by |
Fix invalid "ref mut mut" sugestion Change output from: ```nocode error: cannot borrow immutable local variable `x` as mutable --> <anon>:12:23 | 11 | TestEnum::Item(ref mut x) => { | --------- use `ref mut mut x` here to make mutable 12 | test(&mut x); | ^ cannot borrow mutably ``` to ```nocode error: cannot borrow immutable local variable `x` as mutable --> <anon>:12:23 | 12 | test(&mut x); | ^ | | | cannot reborrow mutably | try removing `&mut` here ``` Fixes #37139, #34337, #34126
Change output from:
to
Fixes #37139, #34337, #34126