]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/nested-undelimited-precedence.rs
Rollup merge of #91915 - jackh726:issue-91899, r=Mark-Simulacrum
[rust.git] / src / test / ui / or-patterns / nested-undelimited-precedence.rs
1 // This test tests the precedence of `|` (or-patterns) undelimited nested patterns. In particular,
2 // we want to reserve the syntactic space of a pattern followed by a type annotation for possible
3 // future type ascription, so we need to make sure that any time a pattern is followed by type
4 // annotation (for now), the pattern is not a top-level or-pattern. However, there are also a few
5 // types of patterns that allow undelimited subpatterns that could cause the same ambiguity.
6 // Currently, those should be impossible due to precedence rule. This test enforces that.
7
8 #![feature(or_patterns)]
9
10 enum E {
11     A,
12     B,
13 }
14
15 fn foo() {
16     use E::*;
17
18     // ok
19     let b @ (A | B): E = A;
20
21     let b @ A | B: E = A; //~ERROR `b` is not bound in all patterns
22     //~^ ERROR top-level or-patterns are not allowed
23 }
24
25 enum F {
26     A(usize),
27     B(usize),
28 }
29
30 fn bar() {
31     use F::*;
32
33     // ok
34     let (A(x) | B(x)): F = A(3);
35
36     let &A(_) | B(_): F = A(3); //~ERROR mismatched types
37     //~^ ERROR top-level or-patterns are not allowed
38     let &&A(_) | B(_): F = A(3); //~ERROR mismatched types
39     //~^ ERROR top-level or-patterns are not allowed
40     let &mut A(_) | B(_): F = A(3); //~ERROR mismatched types
41     //~^ ERROR top-level or-patterns are not allowed
42     let &&mut A(_) | B(_): F = A(3); //~ERROR mismatched types
43     //~^ ERROR top-level or-patterns are not allowed
44 }
45
46 fn main() {}