]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/or-patterns-syntactic-fail.rs
Rollup merge of #80269 - pickfire:patch-4, r=joshtriplett
[rust.git] / src / test / ui / or-patterns / or-patterns-syntactic-fail.rs
1 // Test some cases where or-patterns may ostensibly be allowed but are in fact not.
2 // This is not a semantic test. We only test parsing.
3
4 fn main() {}
5
6 enum E { A, B }
7 use E::*;
8
9 fn no_top_level_or_patterns() {
10     // We do *not* allow or-patterns at the top level of lambdas...
11     let _ = |A | B: E| (); //~ ERROR no implementation for `E | ()`
12     //           -------- This looks like an or-pattern but is in fact `|A| (B: E | ())`.
13
14     // ...and for now neither do we allow or-patterns at the top level of functions.
15     fn fun1(A | B: E) {}
16     //~^ ERROR top-level or-patterns are not allowed
17
18     fn fun2(| A | B: E) {}
19     //~^ ERROR top-level or-patterns are not allowed
20
21     // We don't allow top-level or-patterns before type annotation in let-statements because we
22     // want to reserve this syntactic space for possible future type ascription.
23     let A | B: E = A;
24     //~^ ERROR top-level or-patterns are not allowed
25
26     let | A | B: E = A;
27     //~^ ERROR top-level or-patterns are not allowed
28
29     let (A | B): E = A; // ok -- wrapped in parens
30 }