Skip to content

Improve error message for E0081 #97456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2022
Merged

Improve error message for E0081 #97456

merged 1 commit into from
May 29, 2022

Conversation

Bryysen
Copy link
Contributor

@Bryysen Bryysen commented May 27, 2022

Closes #97319

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @lcnr (or someone else) soon.

Please see the contribution instructions for more information.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 27, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 27, 2022
@Bryysen
Copy link
Contributor Author

Bryysen commented May 27, 2022

Note that this was done by using the (existing) Display implementation for the Discr type, instead of just printing the val field directly. Additionally, we check if the duplicate discriminant was explicitly set, if not we notify that it is being incremented from the previous discriminant. That note can definitely be improved, but maybe in a different PR.

@compiler-errors
Copy link
Member

You probably need to re-bless your test stderr. Did you run ./x.py test src/test/ui --bless?

@rust-log-analyzer

This comment has been minimized.

@Bryysen
Copy link
Contributor Author

Bryysen commented May 27, 2022

Hmm I could have sworn i blessed the tests... strange

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

Do you need to git add src/test/ui? Tests still aren't blessed.

@Bryysen
Copy link
Contributor Author

Bryysen commented May 27, 2022

I'm on it. Ended up pulling from origin somehow and now i have to recompile everything locally to make the changes. I have the dream combo of weak laptop + slow connection so everything takes ages 😞

@Bryysen
Copy link
Contributor Author

Bryysen commented May 27, 2022

Moving the note to its own span seems kinda noisy:

error[E0081]: discriminant value `-1` assigned more than once
 --> tst.rs:4:5
  |
2 |     First = -1,
  |             -- first assignment of `-1`
3 |     Second = -2,
4 |     Last,
  |     ^^^^
  |
note: because `Last` has no explicit discriminant, it is being assigned the increment of the previous discriminant
 --> tst.rs:4:5
  |
4 |     Last,
  |     ^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0081`.

Could also just remove it all-together
Edit:
Or make it point to the variant incremented from, Second in this case
Edit2: Gonna remove it for now, improving that part can be done properly in another PR

@Bryysen

This comment was marked as resolved.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually kinda miss that "assigned value that was incremented from the previous value" error... could you add that back? Maybe pointing at the previous value, instead of the current one?

Something like

enum Foo {
  A = 1, // first assignment of `0` here
  B = 0, //~ assigned value for `C` was incremented from the previous value
  C,

@compiler-errors
Copy link
Member

@Bryysen, let's go with #97456 (comment).

r? @compiler-errors

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two tiny nitpicks, then we're good to go!

@rust-log-analyzer

This comment has been minimized.

Previously whenever a duplicate discriminant was detected for an Enum,
we would print the discriminant bits in the diagnostic without any
casting. This caused us to display incorrect values for negative
discriminants. After this PR we format the discriminant signedness
correctly. Also reworded some of the original error
messages.
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thanks for dealing with the back-and-forth of my comments. I will approve as soon as CI is green.

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 29, 2022

📌 Commit f671bc9 has been approved by compiler-errors

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2022
@bors
Copy link
Collaborator

bors commented May 29, 2022

⌛ Testing commit f671bc9 with merge abc7681...

@bors
Copy link
Collaborator

bors commented May 29, 2022

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing abc7681 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 29, 2022
@bors bors merged commit abc7681 into rust-lang:master May 29, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 29, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (abc7681): comparison url.

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
2.3% 2.3% 1
Regressions 😿
(secondary)
2.7% 2.7% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.0% -3.5% 2
All 😿🎉 (primary) 2.3% 2.3% 1

Cycles

Results
  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
3.5% 3.8% 2
Regressions 😿
(secondary)
3.1% 3.6% 2
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.8% -3.8% 1
All 😿🎉 (primary) 3.5% 3.8% 2

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing error message on negative enum-discriminants
8 participants