We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
See the following code:
enum TestEnum { Item(i32), } fn test(_: &mut i32) { } fn main() { let mut x = TestEnum::Item(10); match x { TestEnum::Item(ref mut x) => { test(&mut x); } } }
The compiler raises error and suggests that:
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
which doesn't make sense, because ref mut mut is invalid.
ref mut mut
The correct code here is actually using test(x) directly as x itself is already a mutable reference there.
test(x)
x
The text was updated successfully, but these errors were encountered:
Similar #34337
Sorry, something went wrong.
Auto merge of #37531 - estebank:fix-ref-mut-mut, r=jonathandturner
026add5
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
No branches or pull requests
See the following code:
The compiler raises error and suggests that:
which doesn't make sense, because
ref mut mut
is invalid.The correct code here is actually using
test(x)
directly asx
itself is already a mutable reference there.The text was updated successfully, but these errors were encountered: