Skip to content

Commit 218c3d5

Browse files
committed
add test revisions for old-edition behavior of feature gates
This also adds `#[cfg]` attributes to tests for bindings' types, to make it visually clearer which revisions type successfully.
1 parent be7d6e3 commit 218c3d5

33 files changed

+1752
-305
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0507]: cannot move out of a shared reference
2+
--> $DIR/borrowck-errors.rs:31:29
3+
|
4+
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
5+
| - ^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| data moved here
8+
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait
9+
|
10+
help: consider removing the borrow
11+
|
12+
LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) {
13+
LL + if let Some(Some(x)) = Some(&Some(&mut 0)) {
14+
|
15+
16+
error[E0596]: cannot borrow data in a `&` reference as mutable
17+
--> $DIR/borrowck-errors.rs:36:10
18+
|
19+
LL | let &ref mut x = &0;
20+
| ^^^^^^^^^ cannot borrow as mutable
21+
22+
error[E0596]: cannot borrow data in a `&` reference as mutable
23+
--> $DIR/borrowck-errors.rs:39:23
24+
|
25+
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {
26+
| ^ cannot borrow as mutable
27+
28+
error[E0596]: cannot borrow data in a `&` reference as mutable
29+
--> $DIR/borrowck-errors.rs:44:11
30+
|
31+
LL | let &[x] = &&mut [0];
32+
| ^ cannot borrow as mutable
33+
34+
error: aborting due to 4 previous errors
35+
36+
Some errors have detailed explanations: E0507, E0596.
37+
For more information about an error, try `rustc --explain E0507`.

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array
2-
--> $DIR/borrowck-errors.rs:13:16
1+
error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array
2+
--> $DIR/borrowck-errors.rs:15:16
33
|
44
LL | let [&x] = &[&mut 0];
55
| - ^^^^^^^^^ cannot move out of here
66
| |
77
| data moved here
8-
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait
8+
| move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait
99
|
1010
help: consider borrowing the pattern binding
1111
|
1212
LL | let [&ref x] = &[&mut 0];
1313
| +++
1414

15-
error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array
16-
--> $DIR/borrowck-errors.rs:19:16
15+
error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array
16+
--> $DIR/borrowck-errors.rs:22:16
1717
|
1818
LL | let [&x] = &mut [&mut 0];
1919
| - ^^^^^^^^^^^^^ cannot move out of here
2020
| |
2121
| data moved here
22-
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait
22+
| move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait
2323
|
2424
help: consider borrowing the pattern binding
2525
|
2626
LL | let [&ref x] = &mut [&mut 0];
2727
| +++
2828

2929
error[E0507]: cannot move out of a shared reference
30-
--> $DIR/borrowck-errors.rs:27:29
30+
--> $DIR/borrowck-errors.rs:31:29
3131
|
3232
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
3333
| - ^^^^^^^^^^^^^^^^^^^
@@ -42,25 +42,25 @@ LL + if let Some(Some(x)) = Some(&Some(&mut 0)) {
4242
|
4343

4444
error[E0596]: cannot borrow data in a `&` reference as mutable
45-
--> $DIR/borrowck-errors.rs:32:10
45+
--> $DIR/borrowck-errors.rs:36:10
4646
|
4747
LL | let &ref mut x = &0;
4848
| ^^^^^^^^^ cannot borrow as mutable
4949

5050
error[E0596]: cannot borrow data in a `&` reference as mutable
51-
--> $DIR/borrowck-errors.rs:35:23
51+
--> $DIR/borrowck-errors.rs:39:23
5252
|
5353
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {
5454
| ^ cannot borrow as mutable
5555

5656
error[E0596]: cannot borrow data in a `&` reference as mutable
57-
--> $DIR/borrowck-errors.rs:40:11
57+
--> $DIR/borrowck-errors.rs:44:11
5858
|
5959
LL | let &[x] = &&mut [0];
6060
| ^ cannot borrow as mutable
6161

6262
error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array
63-
--> $DIR/borrowck-errors.rs:44:20
63+
--> $DIR/borrowck-errors.rs:48:20
6464
|
6565
LL | let [&mut x] = &mut [&mut 0];
6666
| - ^^^^^^^^^^^^^ cannot move out of here
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
//@ revisions: stable2021 classic2024 structural2024
1+
//@ revisions: stable2021 classic2021 structural2021 classic2024 structural2024
22
//@[stable2021] edition: 2021
3+
//@[classic2021] edition: 2021
4+
//@[structural2021] edition: 2021
35
//@[classic2024] edition: 2024
46
//@[structural2024] edition: 2024
57
//! Tests for pattern errors not handled by the pattern typing rules, but by borrowck.
68
#![allow(incomplete_features)]
7-
#![cfg_attr(classic2024, feature(ref_pat_eat_one_layer_2024))]
8-
#![cfg_attr(structural2024, feature(ref_pat_eat_one_layer_2024_structural))]
9+
#![cfg_attr(any(classic2021, classic2024), feature(ref_pat_eat_one_layer_2024))]
10+
#![cfg_attr(any(structural2021, structural2024), feature(ref_pat_eat_one_layer_2024_structural))]
911

1012
/// These patterns additionally use `&` to match a `&mut` reference type, which causes compilation
1113
/// to fail in HIR typeck on stable. As such, they need to be separate from the other tests.
@@ -14,13 +16,15 @@ fn errors_caught_in_hir_typeck_on_stable() {
1416
//[stable2021]~^ mismatched types
1517
//[stable2021]~| types differ in mutability
1618
//[classic2024]~^^^ ERROR: cannot move out of type
17-
let _: &u32 = x;
19+
#[cfg(any(classic2021, structural2021))] let _: u32 = x;
20+
#[cfg(structural2024)] let _: &u32 = x;
1821

1922
let [&x] = &mut [&mut 0];
2023
//[stable2021]~^ mismatched types
2124
//[stable2021]~| types differ in mutability
2225
//[classic2024]~^^^ ERROR: cannot move out of type
23-
let _: &u32 = x;
26+
#[cfg(any(classic2021, structural2021))] let _: u32 = x;
27+
#[cfg(structural2024)] let _: &u32 = x;
2428
}
2529

2630
pub fn main() {
@@ -33,16 +37,16 @@ pub fn main() {
3337
//~^ cannot borrow data in a `&` reference as mutable [E0596]
3438

3539
if let &Some(Some(x)) = &Some(&mut Some(0)) {
36-
//[stable2021,classic2024]~^ ERROR: cannot borrow data in a `&` reference as mutable
37-
let _: &u32 = x;
40+
//[stable2021,classic2021,classic2024]~^ ERROR: cannot borrow data in a `&` reference as mutable
41+
#[cfg(any(structural2021, structural2024))] let _: &u32 = x;
3842
}
3943

4044
let &[x] = &&mut [0];
41-
//[stable2021,classic2024]~^ ERROR: cannot borrow data in a `&` reference as mutable
42-
let _: &u32 = x;
45+
//[stable2021,classic2021,classic2024]~^ ERROR: cannot borrow data in a `&` reference as mutable
46+
#[cfg(any(structural2021, structural2024))] let _: &u32 = x;
4347

4448
let [&mut x] = &mut [&mut 0];
4549
//[classic2024]~^ ERROR: cannot move out of type
46-
#[cfg(stable2021)] let _: u32 = x;
50+
#[cfg(any(stable2021, classic2021, structural2021))] let _: u32 = x;
4751
#[cfg(structural2024)] let _: &mut u32 = x;
4852
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/borrowck-errors.rs:13:10
2+
--> $DIR/borrowck-errors.rs:15:10
33
|
44
LL | let [&x] = &[&mut 0];
55
| ^^ --------- this expression has type `&[&mut {integer}; 1]`
@@ -15,7 +15,7 @@ LL + let [x] = &[&mut 0];
1515
|
1616

1717
error[E0308]: mismatched types
18-
--> $DIR/borrowck-errors.rs:19:10
18+
--> $DIR/borrowck-errors.rs:22:10
1919
|
2020
LL | let [&x] = &mut [&mut 0];
2121
| ^^ ------------- this expression has type `&mut [&mut {integer}; 1]`
@@ -31,7 +31,7 @@ LL + let [x] = &mut [&mut 0];
3131
|
3232

3333
error[E0507]: cannot move out of a shared reference
34-
--> $DIR/borrowck-errors.rs:27:29
34+
--> $DIR/borrowck-errors.rs:31:29
3535
|
3636
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
3737
| - ^^^^^^^^^^^^^^^^^^^
@@ -46,19 +46,19 @@ LL + if let Some(Some(x)) = Some(&Some(&mut 0)) {
4646
|
4747

4848
error[E0596]: cannot borrow data in a `&` reference as mutable
49-
--> $DIR/borrowck-errors.rs:32:10
49+
--> $DIR/borrowck-errors.rs:36:10
5050
|
5151
LL | let &ref mut x = &0;
5252
| ^^^^^^^^^ cannot borrow as mutable
5353

5454
error[E0596]: cannot borrow data in a `&` reference as mutable
55-
--> $DIR/borrowck-errors.rs:35:23
55+
--> $DIR/borrowck-errors.rs:39:23
5656
|
5757
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {
5858
| ^ cannot borrow as mutable
5959

6060
error[E0596]: cannot borrow data in a `&` reference as mutable
61-
--> $DIR/borrowck-errors.rs:40:11
61+
--> $DIR/borrowck-errors.rs:44:11
6262
|
6363
LL | let &[x] = &&mut [0];
6464
| ^ cannot borrow as mutable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0507]: cannot move out of a shared reference
2+
--> $DIR/borrowck-errors.rs:31:29
3+
|
4+
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
5+
| - ^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| data moved here
8+
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait
9+
|
10+
help: consider removing the borrow
11+
|
12+
LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) {
13+
LL + if let Some(Some(x)) = Some(&Some(&mut 0)) {
14+
|
15+
16+
error[E0596]: cannot borrow data in a `&` reference as mutable
17+
--> $DIR/borrowck-errors.rs:36:10
18+
|
19+
LL | let &ref mut x = &0;
20+
| ^^^^^^^^^ cannot borrow as mutable
21+
22+
error: aborting due to 2 previous errors
23+
24+
Some errors have detailed explanations: E0507, E0596.
25+
For more information about an error, try `rustc --explain E0507`.

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural2024.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0507]: cannot move out of a shared reference
2-
--> $DIR/borrowck-errors.rs:27:29
2+
--> $DIR/borrowck-errors.rs:31:29
33
|
44
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) {
55
| - ^^^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL + if let Some(Some(x)) = Some(&Some(&mut 0)) {
1414
|
1515

1616
error[E0596]: cannot borrow data in a `&` reference as mutable
17-
--> $DIR/borrowck-errors.rs:32:10
17+
--> $DIR/borrowck-errors.rs:36:10
1818
|
1919
LL | let &ref mut x = &0;
2020
| ^^^^^^^^^ cannot borrow as mutable

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mut-ref-mut.classic2024.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: binding cannot be both mutable and by-reference
2-
--> $DIR/mut-ref-mut.rs:14:13
2+
--> $DIR/mut-ref-mut.rs:18:13
33
|
44
LL | let Foo(mut a) = &Foo(0);
55
| ^^^^
@@ -9,7 +9,7 @@ LL | let Foo(mut a) = &Foo(0);
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0658]: binding cannot be both mutable and by-reference
12-
--> $DIR/mut-ref-mut.rs:19:13
12+
--> $DIR/mut-ref-mut.rs:23:13
1313
|
1414
LL | let Foo(mut a) = &mut Foo(0);
1515
| ^^^^
@@ -19,7 +19,7 @@ LL | let Foo(mut a) = &mut Foo(0);
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0308]: mismatched types
22-
--> $DIR/mut-ref-mut.rs:24:10
22+
--> $DIR/mut-ref-mut.rs:28:10
2323
|
2424
LL | let [&mut mut x] = &[&mut 0];
2525
| ^^^^^
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
//@ revisions: stable2021 classic2024 structural2024
1+
//@ revisions: stable2021 classic2021 structural2021 classic2024 structural2024
22
//@[stable2021] edition: 2021
3+
//@[classic2021] edition: 2021
4+
//@[structural2021] edition: 2021
35
//@[classic2024] edition: 2024
46
//@[structural2024] edition: 2024
57
//@[stable2021] run-pass
8+
//@[classic2021] run-pass
9+
//@[structural2021] run-pass
610
//! Test diagnostics for binding with `mut` when the default binding mode is by-ref.
711
#![allow(incomplete_features, unused_assignments, unused_variables)]
8-
#![cfg_attr(classic2024, feature(ref_pat_eat_one_layer_2024))]
9-
#![cfg_attr(structural2024, feature(ref_pat_eat_one_layer_2024_structural))]
12+
#![cfg_attr(any(classic2021, classic2024), feature(ref_pat_eat_one_layer_2024))]
13+
#![cfg_attr(any(structural2021, structural2024), feature(ref_pat_eat_one_layer_2024_structural))]
1014

1115
pub fn main() {
1216
struct Foo(u8);
1317

1418
let Foo(mut a) = &Foo(0);
1519
//[classic2024,structural2024]~^ ERROR: binding cannot be both mutable and by-reference
16-
#[cfg(stable2021)] { a = 42 }
20+
#[cfg(any(stable2021, classic2021, structural2021))] { a = 42 }
1721
#[cfg(any(classic2024, structural2024))] { a = &42 }
1822

1923
let Foo(mut a) = &mut Foo(0);
2024
//[classic2024,structural2024]~^ ERROR: binding cannot be both mutable and by-reference
21-
#[cfg(stable2021)] { a = 42 }
25+
#[cfg(any(stable2021, classic2021, structural2021))] { a = 42 }
2226
#[cfg(any(classic2024, structural2024))] { a = &mut 42 }
2327

2428
let [&mut mut x] = &[&mut 0];
2529
//[classic2024]~^ ERROR: mismatched types
2630
//[classic2024]~| cannot match inherited `&` with `&mut` pattern
2731
//[structural2024]~^^^ binding cannot be both mutable and by-reference
28-
#[cfg(stable2021)] { x = 0 }
32+
#[cfg(any(stable2021, classic2021, structural2021))] { x = 0 }
2933
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mut-ref-mut.structural2024.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: binding cannot be both mutable and by-reference
2-
--> $DIR/mut-ref-mut.rs:14:13
2+
--> $DIR/mut-ref-mut.rs:18:13
33
|
44
LL | let Foo(mut a) = &Foo(0);
55
| ^^^^
@@ -9,7 +9,7 @@ LL | let Foo(mut a) = &Foo(0);
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0658]: binding cannot be both mutable and by-reference
12-
--> $DIR/mut-ref-mut.rs:19:13
12+
--> $DIR/mut-ref-mut.rs:23:13
1313
|
1414
LL | let Foo(mut a) = &mut Foo(0);
1515
| ^^^^
@@ -19,7 +19,7 @@ LL | let Foo(mut a) = &mut Foo(0);
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: binding cannot be both mutable and by-reference
22-
--> $DIR/mut-ref-mut.rs:24:15
22+
--> $DIR/mut-ref-mut.rs:28:15
2323
|
2424
LL | let [&mut mut x] = &[&mut 0];
2525
| ^^^^

0 commit comments

Comments
 (0)