summaryrefslogtreecommitdiffstats
path: root/tests/ui/or-patterns/or-patterns-syntactic-fail.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/or-patterns/or-patterns-syntactic-fail.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/or-patterns/or-patterns-syntactic-fail.rs')
-rw-r--r--tests/ui/or-patterns/or-patterns-syntactic-fail.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/or-patterns/or-patterns-syntactic-fail.rs b/tests/ui/or-patterns/or-patterns-syntactic-fail.rs
new file mode 100644
index 000000000..358e9d034
--- /dev/null
+++ b/tests/ui/or-patterns/or-patterns-syntactic-fail.rs
@@ -0,0 +1,30 @@
+// Test some cases where or-patterns may ostensibly be allowed but are in fact not.
+// This is not a semantic test. We only test parsing.
+
+fn main() {}
+
+enum E { A, B }
+use E::*;
+
+fn no_top_level_or_patterns() {
+ // We do *not* allow or-patterns at the top level of lambdas...
+ let _ = |A | B: E| (); //~ ERROR no implementation for `E | ()`
+ // -------- This looks like an or-pattern but is in fact `|A| (B: E | ())`.
+
+ // ...and for now neither do we allow or-patterns at the top level of functions.
+ fn fun1(A | B: E) {}
+ //~^ ERROR top-level or-patterns are not allowed
+
+ fn fun2(| A | B: E) {}
+ //~^ ERROR top-level or-patterns are not allowed
+
+ // We don't allow top-level or-patterns before type annotation in let-statements because we
+ // want to reserve this syntactic space for possible future type ascription.
+ let A | B: E = A;
+ //~^ ERROR top-level or-patterns are not allowed
+
+ let | A | B: E = A;
+ //~^ ERROR top-level or-patterns are not allowed
+
+ let (A | B): E = A; // ok -- wrapped in parens
+}