Skip to content

Commit 24d94b2

Browse files
committed
Add regression test for negative unsigned literals in patterns
1 parent 8df89d1 commit 24d94b2

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(pattern_types)]
2+
#![feature(pattern_type_macro)]
3+
4+
use std::pat::pattern_type;
5+
6+
type Sign = pattern_type!(u32 is -10..);
7+
//~^ ERROR: cannot apply unary operator `-`
8+
9+
type SignedChar = pattern_type!(char is -'A'..);
10+
//~^ ERROR: cannot apply unary operator `-`
11+
12+
fn main() {
13+
match 42_u8 {
14+
-10..253 => {}
15+
_ => {}
16+
}
17+
18+
match 'A' {
19+
-'\0'..'a' => {}
20+
_ => {}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0600]: cannot apply unary operator `-` to type `u32`
2+
--> $DIR/signed_ranges.rs:6:34
3+
|
4+
LL | type Sign = pattern_type!(u32 is -10..);
5+
| ^^^ cannot apply unary operator `-`
6+
|
7+
= note: unsigned values cannot be negated
8+
9+
error[E0600]: cannot apply unary operator `-` to type `char`
10+
--> $DIR/signed_ranges.rs:9:41
11+
|
12+
LL | type SignedChar = pattern_type!(char is -'A'..);
13+
| ^^^^ cannot apply unary operator `-`
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0600`.

0 commit comments

Comments
 (0)