-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
fix: more descriptive error message for enum to integer #151122
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
base: main
Are you sure you want to change the base?
Conversation
|
r? @chenyukang rustbot has assigned @chenyukang. Use |
|
|
||
| fn main() { | ||
| let priority = &Priority::Normal; | ||
| let priority = priority as u8; //~ ERROR casting `&Priority` as `u8` is invalid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to check the HELP message as well.
like
| let priority = priority as u8; //~ ERROR casting `&Priority` as `u8` is invalid | |
| let priority = priority as u8; //~ ERROR casting `&Priority` as `u8` is invalid | |
| //~| HELP: dereference the expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to check the HELP message as well. like
Ty! will add this.
|
you can use there is no need to paste a screenshot of CI testing, since if any tests in CI failed, we will get it in Github action . |
ty, just fixed this. |
| self.expr_span.shrink_to_lo(), | ||
| "dereference the expression", | ||
| "*", | ||
| Applicability::MachineApplicable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to use MaybeIncorrect?
since if we apply the suggestion there maybe still some errors:
error[E0507]: cannot move out of `*priority` which is behind a shared reference
--> tests/ui/cast/cast-enum-to-int-issue-151116.rs:10:20
|
10 | let priority = *priority as u8; //~ ERROR casting `&Priority` as `u8` is invalid
| ^^^^^^^^^ move occurs because `*priority` has type `Priority`, which does not implement the `Copy` trait
|
note: if `Priority` implemented `Clone`, you could clone the value
--> tests/ui/cast/cast-enum-to-int-issue-151116.rs:2:1
|
2 | enum Priority {
| ^^^^^^^^^^^^^ consider implementing `Clone` for this type
...
10 | let priority = *priority as u8; //~ ERROR casting `&Priority` as `u8` is invalid
| --------- you could clone this value|
|
||
| fn main() { | ||
| let priority = &Priority::Normal; | ||
| let priority = priority as u8; //~ ERROR casting `&Priority` as `u8` is invalid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could add a test to make sure it does not suggest for code:
let priority = &Priority::Normal as u8
Fixes #151116
A more descriptive error message when casting an enum to an Integer. Please review issue linked above.