-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a range pattern inference failing test
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/test/ui/pattern/issue-88074-pat-range-type-inference-err.rs
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,28 @@ | ||
trait Zero { | ||
const ZERO: Self; | ||
} | ||
|
||
impl Zero for String { | ||
const ZERO: Self = String::new(); | ||
} | ||
|
||
fn foo() { | ||
match String::new() { | ||
Zero::ZERO ..= Zero::ZERO => {}, | ||
//~^ ERROR only `char` and numeric types are allowed in range patterns | ||
_ => {}, | ||
} | ||
} | ||
|
||
fn bar() { | ||
match Zero::ZERO { | ||
Zero::ZERO ..= Zero::ZERO => {}, | ||
//~^ ERROR type annotations needed [E0282] | ||
_ => {}, | ||
} | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
bar(); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/pattern/issue-88074-pat-range-type-inference-err.stderr
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,21 @@ | ||
error[E0029]: only `char` and numeric types are allowed in range patterns | ||
--> $DIR/issue-88074-pat-range-type-inference-err.rs:11:9 | ||
| | ||
LL | Zero::ZERO ..= Zero::ZERO => {}, | ||
| ----------^^^^^---------- | ||
| | | | ||
| | this is of type `String` but it should be `char` or numeric | ||
| this is of type `String` but it should be `char` or numeric | ||
|
||
error[E0282]: type annotations needed | ||
--> $DIR/issue-88074-pat-range-type-inference-err.rs:19:9 | ||
| | ||
LL | Zero::ZERO ..= Zero::ZERO => {}, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type | ||
| | ||
= note: type must be known at this point | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0029, E0282. | ||
For more information about an error, try `rustc --explain E0029`. |