-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: Display the value of enum variant on hover #12966
Conversation
Thanks! |
☀️ Test successful - checks-actions |
Note for the changelog, this PR is two features really, const eval support for enum variants (enabling hover to work better for enum variant constants), but imo more important, we now do inference in enum variant bodies |
Properly set the enum variant body type from the repr attribute Follow up for #12966, fixes some type inference problems
Fix diagnostics not working in enum variant bodies cc #12966
That is not a valid expression, the variant is missing a cast. Though clearly we shouldn't leak the HIR representation on hover if we fail computation 😬 |
Weird, I actually checked that it compiled, but now it doesn't. Maybe I didn't save.. And you're right, of course, it does need a cast. |
fixes #12955
This PR adds const eval support for enums, as well as showing their value on hover, just as consts currently have.
I developed these two things at the same time, but I've realized now that they are separate. However since the hover is just a 10 line change (not including tests), I figured I may as well put them in the same PR. Though if you want them split up into "enum const eval support" and "show enum variant value on hover", I think that's reasonable too.
Since this adds const eval support for enums this also allows consts that reference enums to have their values computed now too.
The const evaluation itself is quite rudimentary, it doesn't keep track of the actual type of the enum, but it turns out that Rust doesn't actually either, and
E::A as u8
is valid regardless of therepr
onE
.It also doesn't really care about what expression the enum variant contains, it could for example be a string, despite that not being allowed, but I guess it's up to the
cargo check
diagnostics to inform of such issues anyway?