forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#76222 - guswynn:const_diag, r=estebank
Give better suggestion when const Range*'s are used as patterns Fixes rust-lang#76191 let me know if there is more/different information you want to show in this case
- 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`. |