Skip to content

Commit d1231ea

Browse files
committed
Add regression test
1 parent 8df89d1 commit d1231ea

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Diff for: tests/ui/pattern/overflowing-literals.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Check that overflowing literals are in patterns are rejected
2+
3+
#![feature(pattern_types)]
4+
#![feature(pattern_type_macro)]
5+
6+
use std::pat::pattern_type;
7+
8+
type TooBig = pattern_type!(u8 is 500..);
9+
//~^ ERROR: literal out of range for `u8`
10+
type TooSmall = pattern_type!(i8 is -500..);
11+
//~^ ERROR: literal out of range for `i8`
12+
type TooBigSigned = pattern_type!(i8 is 200..);
13+
//~^ ERROR: literal out of range for `i8`
14+
15+
fn main() {
16+
match 5_u8 {
17+
500 => {}
18+
_ => {}
19+
}
20+
}

Diff for: tests/ui/pattern/overflowing-literals.stderr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: literal out of range for `u8`
2+
--> $DIR/overflowing-literals.rs:8:35
3+
|
4+
LL | type TooBig = pattern_type!(u8 is 500..);
5+
| ^^^
6+
|
7+
= note: the literal `500` does not fit into the type `u8` whose range is `0..=255`
8+
= note: `#[deny(overflowing_literals)]` on by default
9+
10+
error: literal out of range for `i8`
11+
--> $DIR/overflowing-literals.rs:10:37
12+
|
13+
LL | type TooSmall = pattern_type!(i8 is -500..);
14+
| ^^^^
15+
|
16+
= note: the literal `-500` does not fit into the type `i8` whose range is `-128..=127`
17+
= help: consider using the type `i16` instead
18+
19+
error: literal out of range for `i8`
20+
--> $DIR/overflowing-literals.rs:12:41
21+
|
22+
LL | type TooBigSigned = pattern_type!(i8 is 200..);
23+
| ^^^
24+
|
25+
= note: the literal `200` does not fit into the type `i8` whose range is `-128..=127`
26+
= help: consider using the type `u8` instead
27+
28+
error: aborting due to 3 previous errors
29+

0 commit comments

Comments
 (0)