Skip to content

Commit 30b4242

Browse files
committed
Document behavior of ! with MbE
1 parent 8d39ec1 commit 30b4242

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// run-pass
2+
#![feature(never_patterns)]
3+
#![allow(incomplete_features)]
4+
5+
use ParsedAs::*;
6+
#[derive(Debug, PartialEq, Eq)]
7+
enum ParsedAs {
8+
Pattern,
9+
Never,
10+
Other,
11+
}
12+
13+
macro_rules! detect_pat {
14+
($p:pat) => {
15+
Pattern
16+
};
17+
(!) => {
18+
Never
19+
};
20+
($($x:tt)*) => {
21+
Other
22+
};
23+
}
24+
25+
fn main() {
26+
// For backwards compatibility this does not match `$p:pat`. This is similar to how or-patterns
27+
// without parens don't match `$p:pat` either.
28+
assert_eq!(detect_pat!(!), Never);
29+
assert_eq!(detect_pat!(! | true), Other);
30+
assert_eq!(detect_pat!(true | !), Other);
31+
32+
// These are never patterns; they take no body when they're in a match arm.
33+
assert_eq!(detect_pat!((!)), Pattern);
34+
assert_eq!(detect_pat!((true, !)), Pattern);
35+
assert_eq!(detect_pat!(Some(!)), Pattern);
36+
37+
// These count as normal patterns.
38+
assert_eq!(detect_pat!((! | true)), Pattern);
39+
assert_eq!(detect_pat!((Ok(x) | Err(&!))), Pattern);
40+
}

tests/ui/rfcs/rfc-0000-never_patterns/parse.rs

+5
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ fn parse(x: Void) {
6868
//~^ ERROR top-level or-patterns are not allowed in `let` bindings
6969
let (Ok(_) | Err(!)) = &res;
7070
let (Ok(_) | Err(&!)) = res.as_ref();
71+
72+
let ! = x;
73+
let y @ ! = x;
7174
}
75+
76+
fn foo(!: Void) {}

0 commit comments

Comments
 (0)