-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => {} | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|