-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #87166 - de-vri-es:show-discriminant-before-overflow,…
… r=jackh726 Show discriminant before overflow in diagnostic for duplicate values. This PR adds the value before overflow for explicit discriminant values in the error for duplicate discriminant values. I found it rather confusing to see only the overflowed value. It only does this for literals, since overflows in const evaluated arithmetic are already a hard error. This is my first PR to the compiler, so please let me know if the implementation can be improved :) Before: ![image](https://user-images.githubusercontent.com/786213/125850097-bf5fb7e0-d800-4386-a738-c30f41822964.png) After: ![image](https://user-images.githubusercontent.com/786213/125850120-e2bb765d-ad86-4888-a6cb-dec34fba3fea.png)
- Loading branch information
Showing
5 changed files
with
52 additions
and
8 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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
enum Enum { | ||
P = 3, | ||
//~^ NOTE first use of `3` | ||
X = 3, | ||
//~^ ERROR discriminant value `3` already exists | ||
//~| NOTE enum already has `3` | ||
Y = 5 | ||
} | ||
|
||
#[repr(u8)] | ||
enum EnumOverflowRepr { | ||
P = 257, | ||
//~^ NOTE first use of `1` (overflowed from `257`) | ||
X = 513, | ||
//~^ ERROR discriminant value `1` already exists | ||
//~| NOTE enum already has `1` (overflowed from `513`) | ||
} | ||
|
||
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
error[E0081]: discriminant value `3` already exists | ||
--> $DIR/E0081.rs:3:9 | ||
--> $DIR/E0081.rs:4:9 | ||
| | ||
LL | P = 3, | ||
| - first use of `3` | ||
LL | | ||
LL | X = 3, | ||
| ^ enum already has `3` | ||
|
||
error: aborting due to previous error | ||
error[E0081]: discriminant value `1` already exists | ||
--> $DIR/E0081.rs:14:9 | ||
| | ||
LL | P = 257, | ||
| --- first use of `1` (overflowed from `257`) | ||
LL | | ||
LL | X = 513, | ||
| ^^^ enum already has `1` (overflowed from `513`) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0081`. |