-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #119650 - chenyukang:yukang-fix-118596-ref-mut, r=wesle…
…ywiser Suggest ref mut for pattern matching assignment Fixes #118596
- Loading branch information
Showing
7 changed files
with
154 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
let y = Some(0); | ||
if let Some(x) = y { | ||
x = 2; //~ ERROR cannot assign twice to immutable variable `x` | ||
} | ||
|
||
let mut arr = [1, 2, 3]; | ||
let [x, ref xs_hold @ ..] = arr; | ||
x = 0; //~ ERROR cannot assign twice to immutable variable `x` | ||
eprintln!("{:?}", arr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
error[E0384]: cannot assign twice to immutable variable `x` | ||
--> $DIR/issue-118596-suggest-ref-mut.rs:4:9 | ||
| | ||
LL | if let Some(x) = y { | ||
| - first assignment to `x` | ||
LL | x = 2; | ||
| ^^^^^ cannot assign twice to immutable variable | ||
| | ||
help: consider making this binding mutable | ||
| | ||
LL | if let Some(mut x) = y { | ||
| ~~~~~ | ||
help: to modify the original value, take a borrow instead | ||
| | ||
LL | if let Some(ref mut x) = y { | ||
| ~~~~~~~~~ | ||
|
||
error[E0384]: cannot assign twice to immutable variable `x` | ||
--> $DIR/issue-118596-suggest-ref-mut.rs:9:5 | ||
| | ||
LL | let [x, ref xs_hold @ ..] = arr; | ||
| - first assignment to `x` | ||
LL | x = 0; | ||
| ^^^^^ cannot assign twice to immutable variable | ||
| | ||
help: consider making this binding mutable | ||
| | ||
LL | let [mut x, ref xs_hold @ ..] = arr; | ||
| ~~~~~ | ||
help: to modify the original value, take a borrow instead | ||
| | ||
LL | let [ref mut x, ref xs_hold @ ..] = arr; | ||
| ~~~~~~~~~ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0384`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters