1
Fork 0

Rollup merge of #106927 - Ezrashaw:e0606-make-machine-applicable, r=estebank

make `CastError::NeedsDeref` create a `MachineApplicable` suggestion

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.
This commit is contained in:
Guillaume Gomez 2023-01-19 11:19:34 +01:00 committed by GitHub
commit 1a878df2b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 33 deletions

View file

@ -1787,6 +1787,14 @@ impl Expr<'_> {
expr
}
pub fn peel_borrows(&self) -> &Self {
let mut expr = self;
while let ExprKind::AddrOf(.., inner) = &expr.kind {
expr = inner;
}
expr
}
pub fn can_have_side_effects(&self) -> bool {
match self.peel_drop_temps().kind {
ExprKind::Path(_) | ExprKind::Lit(_) => false,