Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 5, 2025
1 parent 8df89d1 commit d1231ea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/ui/pattern/overflowing-literals.rs
Original file line number Diff line number Diff line change
@@ -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 => {}
_ => {}
}
}
29 changes: 29 additions & 0 deletions tests/ui/pattern/overflowing-literals.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d1231ea

Please sign in to comment.