-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better diag when const ranges are used in patterns
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Regression test for diagnostic issue #76191 | ||
#![allow(non_snake_case)] | ||
|
||
use std::ops::RangeInclusive; | ||
const RANGE: RangeInclusive<i32> = 0..=255; | ||
|
||
fn main() { | ||
let n: i32 = 1; | ||
match n { | ||
RANGE => {} | ||
//~^ ERROR mismatched types | ||
_ => {} | ||
} | ||
} |
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[E0308]: mismatched types | ||
--> $DIR/issue-76191.rs:10:9 | ||
| | ||
LL | const RANGE: RangeInclusive<i32> = 0..=255; | ||
| ------------------------------------------- constant defined here | ||
... | ||
LL | match n { | ||
| - this expression has type `i32` | ||
LL | RANGE => {} | ||
| ^^^^^ | ||
| | | ||
| expected `i32`, found struct `RangeInclusive` | ||
| `RANGE` is interpreted as a constant, not a new binding | ||
| | ||
= note: expected type `i32` | ||
found struct `RangeInclusive<i32>` | ||
= note: constants only support matching by type, if you meant to match against a range of values, consider using a range pattern like `min ..= max` in the match block | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |