1
- //@ revisions: stable2021 classic2024 structural2024
1
+ //@ revisions: stable2021 classic2021 structural2021 classic2024 structural2024
2
2
//@[stable2021] edition: 2021
3
+ //@[classic2021] edition: 2021
4
+ //@[structural2021] edition: 2021
3
5
//@[classic2024] edition: 2024
4
6
//@[structural2024] edition: 2024
5
7
//! Tests for pattern errors not handled by the pattern typing rules, but by borrowck.
6
8
#![ 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) ) ]
9
11
10
12
/// These patterns additionally use `&` to match a `&mut` reference type, which causes compilation
11
13
/// 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() {
14
16
//[stable2021]~^ mismatched types
15
17
//[stable2021]~| types differ in mutability
16
18
//[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;
18
21
19
22
let [ & x] = & mut [ & mut 0 ] ;
20
23
//[stable2021]~^ mismatched types
21
24
//[stable2021]~| types differ in mutability
22
25
//[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;
24
28
}
25
29
26
30
pub fn main ( ) {
@@ -33,16 +37,16 @@ pub fn main() {
33
37
//~^ cannot borrow data in a `&` reference as mutable [E0596]
34
38
35
39
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;
38
42
}
39
43
40
44
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;
43
47
44
48
let [ & mut x] = & mut [ & mut 0 ] ;
45
49
//[classic2024]~^ ERROR: cannot move out of type
46
- #[ cfg( stable2021) ] let _: u32 = x;
50
+ #[ cfg( any ( stable2021, classic2021 , structural2021 ) ) ] let _: u32 = x;
47
51
#[ cfg( structural2024) ] let _: & mut u32 = x;
48
52
}
0 commit comments