]> git.proxmox.com Git - rustc.git/blame - src/test/ui/or-patterns/nested-undelimited-precedence.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / src / test / ui / or-patterns / nested-undelimited-precedence.rs
CommitLineData
6a06907d
XL
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
6a06907d
XL
8enum E {
9 A,
10 B,
11}
12
13fn foo() {
14 use E::*;
15
16 // ok
17 let b @ (A | B): E = A;
18
19 let b @ A | B: E = A; //~ERROR `b` is not bound in all patterns
20 //~^ ERROR top-level or-patterns are not allowed
21}
22
23enum F {
24 A(usize),
25 B(usize),
26}
27
28fn bar() {
29 use F::*;
30
31 // ok
32 let (A(x) | B(x)): F = A(3);
33
34 let &A(_) | B(_): F = A(3); //~ERROR mismatched types
35 //~^ ERROR top-level or-patterns are not allowed
36 let &&A(_) | B(_): F = A(3); //~ERROR mismatched types
37 //~^ ERROR top-level or-patterns are not allowed
38 let &mut 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}
43
44fn main() {}