-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
make CastError::NeedsDeref
create a MachineApplicable
suggestion
#106927
make CastError::NeedsDeref
create a MachineApplicable
suggestion
#106927
Conversation
…+ other misc fixes
r? @eholk (rustbot has picked a reviewer for you, use r? to override) |
tests/ui/error-codes/E0606.stderr
Outdated
help: dereference the expression | ||
| | ||
LL | *&0u8 as u8; | ||
| + |
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.
You have access to the expression through self.expr
. Would you mind special casing hir::ExprKind::AddrOf
to suggest removing the &
instead?
r? @estebank r=me after addressing the nitpick |
@estebank Done, I'd also like to handle multiple derefs/borrows but that is going to get a bit complex (I've prepared the code a little bit). |
); | ||
if matches!(self.expr.kind, ExprKind::AddrOf(..)) { | ||
// get just the borrow part of the expression | ||
let span = self.expr_span.with_hi(self.expr.peel_borrows().span.lo()); |
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.
Wouldn't this be a problem if you had &&&&&0u8 as &&&&u8
?
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.
That code compiles, but the case: &&&0u8 as &&u32
(note the different int type) fails to compile with a more generic error (without any suggestions). Ideally, it would understand that multiple borrows/derefs can be used but that is outside the scope of this PR and requires some thought.
@bors r+ |
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#105977 (Transform async `ResumeTy` in generator transform) - rust-lang#106927 (make `CastError::NeedsDeref` create a `MachineApplicable` suggestion) - rust-lang#106931 (document + UI test `E0208` and make its output more user-friendly) - rust-lang#107027 (Remove extra removal from test path) - rust-lang#107037 (Fix Dominators::rank_partial_cmp to match documentation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #106903
Simple impl for the linked issue. I also made some other small changes:
CastError::ErrorGuaranteed
now owns an actualErrorGuaranteed
. This better enforces the static guarantees ofErrorGuaranteed
.CastError::NeedDeref
code simplified a bit, we now just suggest the*
, instead of the whole expression as well.