Skip to content
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

Merged
merged 2 commits into from
Jan 19, 2023

Conversation

Ezrashaw
Copy link
Contributor

Fixes #106903

Simple impl for the linked issue. I also made some other small changes:

  • CastError::ErrorGuaranteed now owns an actual ErrorGuaranteed. This better enforces the static guarantees of ErrorGuaranteed.
  • CastError::NeedDeref code simplified a bit, we now just suggest the *, instead of the whole expression as well.

@rustbot
Copy link
Collaborator

rustbot commented Jan 16, 2023

r? @eholk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 16, 2023
Comment on lines 7 to 10
help: dereference the expression
|
LL | *&0u8 as u8;
| +
Copy link
Contributor

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?

@estebank
Copy link
Contributor

r? @estebank

r=me after addressing the nitpick

@rustbot rustbot assigned estebank and unassigned eholk Jan 17, 2023
@Ezrashaw
Copy link
Contributor Author

@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());
Copy link
Contributor

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?

Copy link
Contributor Author

@Ezrashaw Ezrashaw Jan 18, 2023

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.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 19, 2023

📌 Commit b73cdf1 has been approved by estebank

It is now in the queue for this repository.

@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 Jan 19, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 19, 2023
…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
@bors bors merged commit 1a878df into rust-lang:master Jan 19, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 19, 2023
@Ezrashaw Ezrashaw deleted the e0606-make-machine-applicable branch March 9, 2023 08:36
@Ezrashaw Ezrashaw restored the e0606-make-machine-applicable branch May 3, 2024 08:11
@Ezrashaw Ezrashaw deleted the e0606-make-machine-applicable branch May 13, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

E0606 could be auto-applicable in some cases
5 participants