Add regression test

This commit is contained in:
Oli Scherer 2025-01-31 17:19:19 +00:00
parent 8df89d1cb0
commit d1231eabf9
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,20 @@
//! Check that overflowing literals are in patterns are rejected
#![feature(pattern_types)]
#![feature(pattern_type_macro)]
use std::pat::pattern_type;
type TooBig = pattern_type!(u8 is 500..);
//~^ ERROR: literal out of range for `u8`
type TooSmall = pattern_type!(i8 is -500..);
//~^ ERROR: literal out of range for `i8`
type TooBigSigned = pattern_type!(i8 is 200..);
//~^ ERROR: literal out of range for `i8`
fn main() {
match 5_u8 {
500 => {}
_ => {}
}
}

View File

@ -0,0 +1,29 @@
error: literal out of range for `u8`
--> $DIR/overflowing-literals.rs:8:35
|
LL | type TooBig = pattern_type!(u8 is 500..);
| ^^^
|
= note: the literal `500` does not fit into the type `u8` whose range is `0..=255`
= note: `#[deny(overflowing_literals)]` on by default
error: literal out of range for `i8`
--> $DIR/overflowing-literals.rs:10:37
|
LL | type TooSmall = pattern_type!(i8 is -500..);
| ^^^^
|
= note: the literal `-500` does not fit into the type `i8` whose range is `-128..=127`
= help: consider using the type `i16` instead
error: literal out of range for `i8`
--> $DIR/overflowing-literals.rs:12:41
|
LL | type TooBigSigned = pattern_type!(i8 is 200..);
| ^^^
|
= note: the literal `200` does not fit into the type `i8` whose range is `-128..=127`
= help: consider using the type `u8` instead
error: aborting due to 3 previous errors