-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #122677 - surechen:fix_122415, r=Nadrieril
Fix incorrect mutable suggestion information for binding in ref pattern. For ref pattern in func param, the mutability suggestion has to apply to the binding. For example: `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)` fixes #122415
- Loading branch information
Showing
8 changed files
with
71 additions
and
15 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,10 @@ | ||
//@ run-rustfix | ||
#![allow(dead_code)] | ||
|
||
fn main() { | ||
fn x(a: &char) { | ||
let &(mut b) = a; | ||
b.make_ascii_uppercase(); | ||
//~^ cannot borrow `b` as mutable, as it is not declared as mutable | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/ui/pattern/issue-114896.rs → ...ttern/patkind-ref-binding-issue-114896.rs
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//@ run-rustfix | ||
#![allow(dead_code)] | ||
|
||
fn main() { | ||
fn x(a: &char) { | ||
let &b = a; | ||
|
2 changes: 1 addition & 1 deletion
2
tests/ui/pattern/issue-114896.stderr → ...n/patkind-ref-binding-issue-114896.stderr
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 @@ | ||
//@ run-rustfix | ||
#![allow(dead_code)] | ||
|
||
fn mutate(_y: &mut i32) {} | ||
|
||
fn foo(&(mut x): &i32) { | ||
mutate(&mut x); | ||
//~^ ERROR cannot borrow `x` as mutable | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
//@ run-rustfix | ||
#![allow(dead_code)] | ||
|
||
fn mutate(_y: &mut i32) {} | ||
|
||
fn foo(&x: &i32) { | ||
mutate(&mut x); | ||
//~^ ERROR cannot borrow `x` as mutable | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable | ||
--> $DIR/patkind-ref-binding-issue-122415.rs:7:12 | ||
| | ||
LL | fn foo(&x: &i32) { | ||
| -- help: consider changing this to be mutable: `&(mut x)` | ||
LL | mutate(&mut x); | ||
| ^^^^^^ cannot borrow as mutable | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0596`. |