Skip to content

Commit e288cff

Browse files
committed
add tests differing between stable and new rules (with errors on new rules)
Since there are so many ways to write these, I've opted to only include two sorts of test: simple tests that directly target the rules differing between rulesets and nuanced tests that produce different errors under different rulesets. I've also tried not to add any duplicate tests. `well-typed-edition-2024.rs` already has tests disagreeing with stable, so I've opted not to include any in this commit that are well-typed under the new rules.
1 parent f5567e1 commit e288cff

6 files changed

+155
-18
lines changed

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ LL | let Foo(mut a) = &mut Foo(0);
1818
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

21-
error: aborting due to 2 previous errors
21+
error[E0308]: mismatched types
22+
--> $DIR/mut-ref-mut.rs:24:10
23+
|
24+
LL | let [&mut mut x] = &[&mut 0];
25+
| ^^^^^
26+
|
27+
= note: cannot match inherited `&` with `&mut` pattern
28+
help: replace this `&mut` pattern with `&`
29+
|
30+
LL | let [&mut x] = &[&mut 0];
31+
| ~
32+
33+
error: aborting due to 3 previous errors
2234

23-
For more information about this error, try `rustc --explain E0658`.
35+
Some errors have detailed explanations: E0308, E0658.
36+
For more information about an error, try `rustc --explain E0308`.

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

+6
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ pub fn main() {
2020
//[classic2024,structural2024]~^ ERROR: binding cannot be both mutable and by-reference
2121
#[cfg(stable2021)] { a = 42 }
2222
#[cfg(any(classic2024, structural2024))] { a = &mut 42 }
23+
24+
let [&mut mut x] = &[&mut 0];
25+
//[classic2024]~^ ERROR: mismatched types
26+
//[classic2024]~| cannot match inherited `&` with `&mut` pattern
27+
//[structural2024]~^^^ binding cannot be both mutable and by-reference
28+
#[cfg(stable2021)] { x = 0 }
2329
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ LL | let Foo(mut a) = &mut Foo(0);
1818
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

21-
error: aborting due to 2 previous errors
21+
error[E0658]: binding cannot be both mutable and by-reference
22+
--> $DIR/mut-ref-mut.rs:24:15
23+
|
24+
LL | let [&mut mut x] = &[&mut 0];
25+
| ^^^^
26+
|
27+
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
28+
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error: aborting due to 3 previous errors
2232

2333
For more information about this error, try `rustc --explain E0658`.

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.rs

+38-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@[stable2021] edition: 2021
33
//@[classic2024] edition: 2024
44
//@[structural2024] edition: 2024
5-
//@[classic2024] run-pass
65
//! Tests for errors from binding with `ref x` under a by-ref default binding mode in edition 2024.
76
//! These can't be in the same body as tests for other errors, since they're emitted during THIR
87
//! construction. The errors on stable edition 2021 Rust are unrelated.
@@ -36,8 +35,6 @@ fn errors_from_eating_the_real_reference() {
3635
//[structural2024]~| cannot override to bind by-reference when that is the implicit default
3736
#[cfg(stable2021)] let _: &mut u32 = x;
3837
#[cfg(classic2024)] let _: &mut &mut u32 = x;
39-
40-
errors_from_eating_the_real_reference_caught_in_hir_typeck_on_stable();
4138
}
4239

4340
/// To make absolutely sure binding with `ref` ignores inherited references on stable, let's
@@ -58,6 +55,43 @@ fn errors_from_eating_the_real_reference_caught_in_hir_typeck_on_stable() {
5855
#[cfg(classic2024)] let _: &&mut u32 = x;
5956
}
6057

58+
/// This one also needs to be quarantined for a typeck error on `classic2024` (eat-outer).
59+
fn errors_dependent_on_eating_order_caught_in_hir_typeck_when_eating_outer() {
60+
let [&mut ref x] = &[&mut 0];
61+
//[classic2024]~^ ERROR: mismatched types
62+
//[classic2024]~| cannot match inherited `&` with `&mut` pattern
63+
//[structural2024]~^^^ ERROR: this pattern relies on behavior which may change in edition 2024
64+
//[structural2024]~| cannot override to bind by-reference when that is the implicit default
65+
#[cfg(stable2021)] let _: &u32 = x;
66+
}
67+
68+
/// These should be errors in all editions. In edition 2024, they should be caught by the pattern
69+
/// typing rules disallowing `ref` when there's an inherited reference. In old editions where that
70+
/// resets the binding mode, they're borrowck errors due to binding with `ref mut`.
71+
/// As a quirk of how the edition 2024 error is emitted during THIR construction, it ends up going
72+
/// through borrowck as well, using the old `ref` behavior as a fallback, so we get that error too.
73+
fn borrowck_errors_in_old_editions() {
74+
let [ref mut x] = &[0];
75+
//~^ ERROR: cannot borrow data in a `&` reference as mutable
76+
//[classic2024,structural2024]~| ERROR: this pattern relies on behavior which may change in edition 2024
77+
//[classic2024,structural2024]~| cannot override to bind by-reference when that is the implicit default
78+
}
79+
80+
/// The remaining tests are purely for testing `ref` bindings in the presence of an inherited
81+
/// reference. These should always fail on edition 2024 and succeed on edition 2021.
6182
pub fn main() {
62-
errors_from_eating_the_real_reference();
83+
let [ref x] = &[0];
84+
//[classic2024,structural2024]~^ ERROR: this pattern relies on behavior which may change in edition 2024
85+
//[classic2024,structural2024]~| cannot override to bind by-reference when that is the implicit default
86+
#[cfg(stable2021)] let _: &u32 = x;
87+
88+
let [ref x] = &mut [0];
89+
//[classic2024,structural2024]~^ ERROR: this pattern relies on behavior which may change in edition 2024
90+
//[classic2024,structural2024]~| cannot override to bind by-reference when that is the implicit default
91+
#[cfg(stable2021)] let _: &u32 = x;
92+
93+
let [ref mut x] = &mut [0];
94+
//[classic2024,structural2024]~^ ERROR: this pattern relies on behavior which may change in edition 2024
95+
//[classic2024,structural2024]~| cannot override to bind by-reference when that is the implicit default
96+
#[cfg(stable2021)] let _: &mut u32 = x;
6397
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.stable2021.stderr

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

1717
error[E0308]: mismatched types
18-
--> $DIR/ref-binding-on-inh-ref-errors.rs:53:10
18+
--> $DIR/ref-binding-on-inh-ref-errors.rs:50:10
1919
|
2020
LL | let [&ref x] = &mut [&mut 0];
2121
| ^^^^^^ ------------- this expression has type `&mut [&mut {integer}; 1]`
@@ -30,6 +30,13 @@ LL - let [&ref x] = &mut [&mut 0];
3030
LL + let [ref x] = &mut [&mut 0];
3131
|
3232

33-
error: aborting due to 2 previous errors
33+
error[E0596]: cannot borrow data in a `&` reference as mutable
34+
--> $DIR/ref-binding-on-inh-ref-errors.rs:74:10
35+
|
36+
LL | let [ref mut x] = &[0];
37+
| ^^^^^^^^^ cannot borrow as mutable
38+
39+
error: aborting due to 3 previous errors
3440

35-
For more information about this error, try `rustc --explain E0308`.
41+
Some errors have detailed explanations: E0308, E0596.
42+
For more information about an error, try `rustc --explain E0308`.

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr

+74-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this pattern relies on behavior which may change in edition 2024
2-
--> $DIR/ref-binding-on-inh-ref-errors.rs:16:11
2+
--> $DIR/ref-binding-on-inh-ref-errors.rs:15:11
33
|
44
LL | let [&ref x] = &[&0];
55
| ^^^ cannot override to bind by-reference when that is the implicit default
@@ -11,7 +11,7 @@ LL | let &[&ref x] = &[&0];
1111
| +
1212

1313
error: this pattern relies on behavior which may change in edition 2024
14-
--> $DIR/ref-binding-on-inh-ref-errors.rs:22:11
14+
--> $DIR/ref-binding-on-inh-ref-errors.rs:21:11
1515
|
1616
LL | let [&ref x] = &mut [&0];
1717
| ^^^ cannot override to bind by-reference when that is the implicit default
@@ -23,7 +23,7 @@ LL | let &mut [&ref x] = &mut [&0];
2323
| ++++
2424

2525
error: this pattern relies on behavior which may change in edition 2024
26-
--> $DIR/ref-binding-on-inh-ref-errors.rs:28:15
26+
--> $DIR/ref-binding-on-inh-ref-errors.rs:27:15
2727
|
2828
LL | let [&mut ref x] = &mut [&mut 0];
2929
| ^^^ cannot override to bind by-reference when that is the implicit default
@@ -35,7 +35,7 @@ LL | let &mut [&mut ref x] = &mut [&mut 0];
3535
| ++++
3636

3737
error: this pattern relies on behavior which may change in edition 2024
38-
--> $DIR/ref-binding-on-inh-ref-errors.rs:34:15
38+
--> $DIR/ref-binding-on-inh-ref-errors.rs:33:15
3939
|
4040
LL | let [&mut ref mut x] = &mut [&mut 0];
4141
| ^^^^^^^ cannot override to bind by-reference when that is the implicit default
@@ -47,7 +47,7 @@ LL | let &mut [&mut ref mut x] = &mut [&mut 0];
4747
| ++++
4848

4949
error: this pattern relies on behavior which may change in edition 2024
50-
--> $DIR/ref-binding-on-inh-ref-errors.rs:46:11
50+
--> $DIR/ref-binding-on-inh-ref-errors.rs:43:11
5151
|
5252
LL | let [&ref x] = &[&mut 0];
5353
| ^^^ cannot override to bind by-reference when that is the implicit default
@@ -59,7 +59,7 @@ LL | let &[&ref x] = &[&mut 0];
5959
| +
6060

6161
error: this pattern relies on behavior which may change in edition 2024
62-
--> $DIR/ref-binding-on-inh-ref-errors.rs:53:11
62+
--> $DIR/ref-binding-on-inh-ref-errors.rs:50:11
6363
|
6464
LL | let [&ref x] = &mut [&mut 0];
6565
| ^^^ cannot override to bind by-reference when that is the implicit default
@@ -70,5 +70,72 @@ help: make the implied reference pattern explicit
7070
LL | let &mut [&ref x] = &mut [&mut 0];
7171
| ++++
7272

73-
error: aborting due to 6 previous errors
73+
error: this pattern relies on behavior which may change in edition 2024
74+
--> $DIR/ref-binding-on-inh-ref-errors.rs:60:15
75+
|
76+
LL | let [&mut ref x] = &[&mut 0];
77+
| ^^^ cannot override to bind by-reference when that is the implicit default
78+
|
79+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
80+
help: make the implied reference pattern explicit
81+
|
82+
LL | let &[&mut ref x] = &[&mut 0];
83+
| +
84+
85+
error: this pattern relies on behavior which may change in edition 2024
86+
--> $DIR/ref-binding-on-inh-ref-errors.rs:74:10
87+
|
88+
LL | let [ref mut x] = &[0];
89+
| ^^^^^^^ cannot override to bind by-reference when that is the implicit default
90+
|
91+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
92+
help: make the implied reference pattern explicit
93+
|
94+
LL | let &[ref mut x] = &[0];
95+
| +
96+
97+
error[E0596]: cannot borrow data in a `&` reference as mutable
98+
--> $DIR/ref-binding-on-inh-ref-errors.rs:74:10
99+
|
100+
LL | let [ref mut x] = &[0];
101+
| ^^^^^^^^^ cannot borrow as mutable
102+
103+
error: this pattern relies on behavior which may change in edition 2024
104+
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:10
105+
|
106+
LL | let [ref x] = &[0];
107+
| ^^^ cannot override to bind by-reference when that is the implicit default
108+
|
109+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
110+
help: make the implied reference pattern explicit
111+
|
112+
LL | let &[ref x] = &[0];
113+
| +
114+
115+
error: this pattern relies on behavior which may change in edition 2024
116+
--> $DIR/ref-binding-on-inh-ref-errors.rs:88:10
117+
|
118+
LL | let [ref x] = &mut [0];
119+
| ^^^ cannot override to bind by-reference when that is the implicit default
120+
|
121+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
122+
help: make the implied reference pattern explicit
123+
|
124+
LL | let &mut [ref x] = &mut [0];
125+
| ++++
126+
127+
error: this pattern relies on behavior which may change in edition 2024
128+
--> $DIR/ref-binding-on-inh-ref-errors.rs:93:10
129+
|
130+
LL | let [ref mut x] = &mut [0];
131+
| ^^^^^^^ cannot override to bind by-reference when that is the implicit default
132+
|
133+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
134+
help: make the implied reference pattern explicit
135+
|
136+
LL | let &mut [ref mut x] = &mut [0];
137+
| ++++
138+
139+
error: aborting due to 12 previous errors
74140

141+
For more information about this error, try `rustc --explain E0596`.

0 commit comments

Comments
 (0)