|
| 1 | +//@ check-fail |
| 2 | +//@ edition: 2024 |
| 3 | +//@ compile-flags: -Zunstable-options |
| 4 | +// gate-test-min_match_ergonomics_2024 |
| 5 | +#![feature(min_match_ergonomics_2024)] |
| 6 | +#![allow(incomplete_features)] |
| 7 | +#![deny(rust_2024_incompatible_pat)] |
| 8 | + |
| 9 | +fn main() {} |
| 10 | + |
| 11 | +#[derive(Copy, Clone)] |
| 12 | +struct T; |
| 13 | + |
| 14 | +struct Foo { |
| 15 | + f: &'static (u8,), |
| 16 | +} |
| 17 | + |
| 18 | +macro_rules! test_pat_on_type { |
| 19 | + ($($tt:tt)*) => { |
| 20 | + const _: () = { |
| 21 | + // Define a new function to ensure all cases are tested independently. |
| 22 | + fn foo($($tt)*) {} |
| 23 | + }; |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +test_pat_on_type![(&x,): &(T,)]; //~ ERROR mismatched types |
| 28 | +test_pat_on_type![(&x,): &(&T,)]; //~ ERROR patterns are not allowed to reset the default binding mode |
| 29 | +test_pat_on_type![(&x,): &(&mut T,)]; //~ ERROR mismatched types |
| 30 | +test_pat_on_type![(&mut x,): &(&T,)]; //~ ERROR mismatched types |
| 31 | +test_pat_on_type![(&mut x,): &(&mut T,)]; //~ ERROR patterns are not allowed to reset the default binding mode |
| 32 | +test_pat_on_type![(&x,): &&mut &(T,)]; //~ ERROR mismatched types |
| 33 | +test_pat_on_type![Foo { f: (&x,) }: Foo]; //~ ERROR mismatched types |
| 34 | +test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; //~ ERROR mismatched types |
| 35 | +test_pat_on_type![Foo { f: &(x,) }: &Foo]; //~ ERROR patterns are not allowed to reset the default binding mode |
| 36 | +test_pat_on_type![(mut x,): &(T,)]; //~ ERROR patterns are not allowed to reset the default binding mode |
| 37 | +test_pat_on_type![(ref x,): &(T,)]; |
| 38 | +test_pat_on_type![(ref mut x,): &mut (T,)]; |
| 39 | + |
| 40 | +fn get<X>() -> X { |
| 41 | + unimplemented!() |
| 42 | +} |
| 43 | + |
| 44 | +// Make sure this works even when the underlying type is inferred. This test passes on rust stable. |
| 45 | +fn infer<X: Copy>() -> X { |
| 46 | + match &get() { |
| 47 | + (&x,) => x, //~ ERROR patterns are not allowed to reset the default binding mode |
| 48 | + } |
| 49 | +} |
0 commit comments