Skip to content

Commit d8f975c

Browse files
committed
rename and comment the test for "Rule 5"-related mutability errors
This also makes it test the "structural" ruleset, in preparation for additional tests where the rulesets disagree.
1 parent b350d94 commit d8f975c

5 files changed

+91
-7
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//@ edition: 2024
22
//@ run-rustfix
3+
//@ revisions: classic structural
4+
//! Tests for `&` patterns matched against `&mut` reference types where the inner pattern attempts
5+
//! to bind by mutable reference.
36
#![allow(incomplete_features)]
4-
#![feature(ref_pat_eat_one_layer_2024)]
7+
#![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
8+
#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
59

610
pub fn main() {
711
if let Some(&mut Some(ref mut x)) = &mut Some(Some(0)) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error[E0596]: cannot borrow as mutable inside an `&` pattern
2-
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:7:31
2+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:11:31
33
|
44
LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
55
| - ^
66
| |
77
| help: replace this `&` with `&mut`: `&mut`
88

99
error[E0596]: cannot borrow as mutable inside an `&` pattern
10-
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:12:31
10+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:16:31
1111
|
1212
LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) {
1313
| - ^
1414
| |
1515
| help: replace this `&` with `&mut`: `&mut`
1616

1717
error[E0596]: cannot borrow as mutable inside an `&` pattern
18-
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:20:15
18+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:24:15
1919
|
2020
LL | let &pat!(x) = &mut 0;
2121
| - ^
2222
| |
2323
| help: replace this `&` with `&mut`: `&mut`
2424

2525
error[E0596]: cannot borrow as mutable inside an `&` pattern
26-
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:24:19
26+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:19
2727
|
2828
LL | let &(ref mut a, ref mut b) = &mut (true, false);
2929
| - ^
3030
| |
3131
| help: replace this `&` with `&mut`: `&mut`
3232

3333
error[E0596]: cannot borrow as mutable inside an `&` pattern
34-
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:24:30
34+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:30
3535
|
3636
LL | let &(ref mut a, ref mut b) = &mut (true, false);
3737
| - ^
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//@ edition: 2024
22
//@ run-rustfix
3+
//@ revisions: classic structural
4+
//! Tests for `&` patterns matched against `&mut` reference types where the inner pattern attempts
5+
//! to bind by mutable reference.
36
#![allow(incomplete_features)]
4-
#![feature(ref_pat_eat_one_layer_2024)]
7+
#![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
8+
#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
59

610
pub fn main() {
711
if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ edition: 2024
2+
//@ run-rustfix
3+
//@ revisions: classic structural
4+
//! Tests for `&` patterns matched against `&mut` reference types where the inner pattern attempts
5+
//! to bind by mutable reference.
6+
#![allow(incomplete_features)]
7+
#![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
8+
#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
9+
10+
pub fn main() {
11+
if let Some(&mut Some(ref mut x)) = &mut Some(Some(0)) {
12+
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
13+
let _: &mut u8 = x;
14+
}
15+
16+
if let &mut Some(Some(ref mut x)) = &mut Some(Some(0)) {
17+
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
18+
let _: &mut u8 = x;
19+
}
20+
21+
macro_rules! pat {
22+
($var:ident) => { ref mut $var };
23+
}
24+
let &mut pat!(x) = &mut 0;
25+
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
26+
let _: &mut u8 = x;
27+
28+
let &mut (ref mut a, ref mut b) = &mut (true, false);
29+
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
30+
//~| ERROR: cannot borrow as mutable inside an `&` pattern
31+
let _: &mut bool = a;
32+
let _: &mut bool = b;
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0596]: cannot borrow as mutable inside an `&` pattern
2+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:11:31
3+
|
4+
LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
5+
| - ^
6+
| |
7+
| help: replace this `&` with `&mut`: `&mut`
8+
9+
error[E0596]: cannot borrow as mutable inside an `&` pattern
10+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:16:31
11+
|
12+
LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) {
13+
| - ^
14+
| |
15+
| help: replace this `&` with `&mut`: `&mut`
16+
17+
error[E0596]: cannot borrow as mutable inside an `&` pattern
18+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:24:15
19+
|
20+
LL | let &pat!(x) = &mut 0;
21+
| - ^
22+
| |
23+
| help: replace this `&` with `&mut`: `&mut`
24+
25+
error[E0596]: cannot borrow as mutable inside an `&` pattern
26+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:19
27+
|
28+
LL | let &(ref mut a, ref mut b) = &mut (true, false);
29+
| - ^
30+
| |
31+
| help: replace this `&` with `&mut`: `&mut`
32+
33+
error[E0596]: cannot borrow as mutable inside an `&` pattern
34+
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:30
35+
|
36+
LL | let &(ref mut a, ref mut b) = &mut (true, false);
37+
| - ^
38+
| |
39+
| help: replace this `&` with `&mut`: `&mut`
40+
41+
error: aborting due to 5 previous errors
42+
43+
For more information about this error, try `rustc --explain E0596`.

0 commit comments

Comments
 (0)