-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintain a list of types permitted per pattern
- Loading branch information
Showing
10 changed files
with
211 additions
and
2 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
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
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
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,12 @@ | ||
//! Check that chars can be used in ranges | ||
//@ check-pass | ||
|
||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
const LOWERCASE: pattern_type!(char is 'a'..='z') = unsafe { std::mem::transmute('b') }; | ||
|
||
fn main() {} |
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,26 @@ | ||
//! Check that pattern types can only have specific base types | ||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
// Undoing an inner pattern type's restrictions should either be forbidden, | ||
// or still validate correctly. | ||
const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(); | ||
//~^ ERROR: not a valid base type for range patterns | ||
|
||
// We want to get the most narrowest version that a pattern could be | ||
const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!(); | ||
//~^ ERROR: not a valid base type for range patterns | ||
|
||
const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ||
//~^ ERROR: not a valid base type for range patterns | ||
|
||
const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ||
//~^ ERROR: not a valid base type for range patterns | ||
|
||
const BAD_NESTING5: pattern_type!(f32 is 1.0 .. 2.0) = todo!(); | ||
//~^ ERROR: not a valid base type for range patterns | ||
|
||
fn main() {} |
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,62 @@ | ||
error: `(u32) is 1..=` is not a valid base type for range patterns | ||
--> $DIR/nested.rs:10:34 | ||
| | ||
LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: range patterns only support integers | ||
--> $DIR/nested.rs:10:63 | ||
| | ||
LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(); | ||
| ^^^ | ||
|
||
error: `(i32) is 1..=` is not a valid base type for range patterns | ||
--> $DIR/nested.rs:14:35 | ||
| | ||
LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: range patterns only support integers | ||
--> $DIR/nested.rs:14:64 | ||
| | ||
LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!(); | ||
| ^^^^^ | ||
|
||
error: `(i32) is 1..=` is not a valid base type for range patterns | ||
--> $DIR/nested.rs:17:35 | ||
| | ||
LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: range patterns only support integers | ||
--> $DIR/nested.rs:17:64 | ||
| | ||
LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ||
| ^^^ | ||
|
||
error: `()` is not a valid base type for range patterns | ||
--> $DIR/nested.rs:20:35 | ||
| | ||
LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ||
| ^^ | ||
| | ||
note: range patterns only support integers | ||
--> $DIR/nested.rs:20:41 | ||
| | ||
LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ||
| ^^^ | ||
|
||
error: `f32` is not a valid base type for range patterns | ||
--> $DIR/nested.rs:23:35 | ||
| | ||
LL | const BAD_NESTING5: pattern_type!(f32 is 1.0 .. 2.0) = todo!(); | ||
| ^^^ | ||
| | ||
note: range patterns only support integers | ||
--> $DIR/nested.rs:23:42 | ||
| | ||
LL | const BAD_NESTING5: pattern_type!(f32 is 1.0 .. 2.0) = todo!(); | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
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 pattern types patterns must be of the type of the base type | ||
//@ known-bug: unknown | ||
//@ failure-status: 101 | ||
//@ normalize-stderr: "note: .*\n\n" -> "" | ||
//@ normalize-stderr: "thread 'rustc' panicked.*\n" -> "" | ||
//@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " | ||
//@ normalize-stderr: "(delayed at compiler/rustc_mir_transform/src/lib.rs:)\d+:\d+" -> "$1:LL:CC" | ||
//@ rustc-env:RUST_BACKTRACE=0 | ||
|
||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); | ||
|
||
const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); | ||
|
||
fn main() {} |
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,31 @@ | ||
error: internal compiler error: ty::ConstKind::Error constructed but no error reported | ||
| | ||
= error: internal compiler error: ty::ConstKind::Error constructed but no error reported | ||
| | ||
= note: delayed at compiler/rustc_mir_build/src/thir/constant.rs:72:21 - disabled backtrace | ||
= error: internal compiler error: mir_const_qualif: MIR had errors | ||
--> $DIR/pattern_type_mismatch.rs:16:1 | ||
| | ||
LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: delayed at compiler/rustc_mir_transform/src/lib.rs::LL:CC - disabled backtrace | ||
--> $DIR/pattern_type_mismatch.rs:16:1 | ||
| | ||
LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: internal compiler error: mir_const_qualif: MIR had errors | ||
--> $DIR/pattern_type_mismatch.rs:18:1 | ||
| | ||
LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: delayed at compiler/rustc_mir_transform/src/lib.rs::LL:CC - disabled backtrace | ||
--> $DIR/pattern_type_mismatch.rs:18:1 | ||
| | ||
LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
query stack during panic: | ||
end of query stack |
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,14 @@ | ||
//! Check that the range start must be smaller than the range end | ||
//@ known-bug: unknown | ||
//@ failure-status: 101 | ||
//@ normalize-stderr: "note: .*\n\n" -> "" | ||
//@ normalize-stderr: "thread 'rustc' panicked.*\n" -> "" | ||
//@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " | ||
//@ rustc-env:RUST_BACKTRACE=0 | ||
|
||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
const NONE: pattern_type!(u8 is 1..0) = unsafe { std::mem::transmute(3_u8) }; |
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,17 @@ | ||
error[E0601]: `main` function not found in crate `reverse_range` | ||
--> $DIR/reverse_range.rs:14:78 | ||
| | ||
LL | const NONE: pattern_type!(u8 is 1..0) = unsafe { std::mem::transmute(3_u8) }; | ||
| ^ consider adding a `main` function to `$DIR/reverse_range.rs` | ||
|
||
|
||
assertion failed: end <= max_value | ||
error: the compiler unexpectedly panicked. this is a bug. | ||
|
||
query stack during panic: | ||
#0 [eval_to_allocation_raw] const-evaluating + checking `NONE` | ||
#1 [eval_to_const_value_raw] simplifying constant for the type system `NONE` | ||
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack | ||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0601`. |