diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-19 18:03:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-19 18:03:51 +0100 |
| commit | 17386b8fbfa876c1dc4355d7d166c5567974825b (patch) | |
| tree | 6dcf123a873a99f3a4a773c592d477744cb81256 /tests | |
| parent | 42dec6f874c81fd1a6c72f05a8dc439916669bc7 (diff) | |
| parent | 19f72dfe04d030aba3885333156590d0b9191851 (diff) | |
| download | rust-17386b8fbfa876c1dc4355d7d166c5567974825b.tar.gz rust-17386b8fbfa876c1dc4355d7d166c5567974825b.zip | |
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
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/pattern/patkind-ref-binding-issue-114896.fixed | 10 | ||||
| -rw-r--r-- | tests/ui/pattern/patkind-ref-binding-issue-114896.rs (renamed from tests/ui/pattern/issue-114896.rs) | 3 | ||||
| -rw-r--r-- | tests/ui/pattern/patkind-ref-binding-issue-114896.stderr (renamed from tests/ui/pattern/issue-114896.stderr) | 2 | ||||
| -rw-r--r-- | tests/ui/pattern/patkind-ref-binding-issue-122415.fixed | 11 | ||||
| -rw-r--r-- | tests/ui/pattern/patkind-ref-binding-issue-122415.rs | 11 | ||||
| -rw-r--r-- | tests/ui/pattern/patkind-ref-binding-issue-122415.stderr | 11 |
6 files changed, 47 insertions, 1 deletions
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed b/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed new file mode 100644 index 00000000000..086a119eb77 --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed @@ -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 + } +} diff --git a/tests/ui/pattern/issue-114896.rs b/tests/ui/pattern/patkind-ref-binding-issue-114896.rs index cde37f658d6..b4d6b72c01f 100644 --- a/tests/ui/pattern/issue-114896.rs +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.rs @@ -1,3 +1,6 @@ +//@ run-rustfix +#![allow(dead_code)] + fn main() { fn x(a: &char) { let &b = a; diff --git a/tests/ui/pattern/issue-114896.stderr b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr index 285c9109e1b..68538255edd 100644 --- a/tests/ui/pattern/issue-114896.stderr +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr @@ -1,5 +1,5 @@ error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable - --> $DIR/issue-114896.rs:4:9 + --> $DIR/patkind-ref-binding-issue-114896.rs:7:9 | LL | let &b = a; | -- help: consider changing this to be mutable: `&(mut b)` diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed b/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed new file mode 100644 index 00000000000..6144f062169 --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed @@ -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() {} diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.rs b/tests/ui/pattern/patkind-ref-binding-issue-122415.rs new file mode 100644 index 00000000000..b9f6416027a --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.rs @@ -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() {} diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr new file mode 100644 index 00000000000..39283133ac7 --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr @@ -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`. |
