mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #101388 - compiler-errors:issue-101376, r=fee1-dead
Don't delay invalid LHS bug unless it will be covered by an error in `check_overloaded_binop` Fixes #101376
This commit is contained in:
commit
dd35e2f79b
@ -57,9 +57,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
// Suppress this error, since we already emitted
|
// If LHS += RHS is an error, but *LHS += RHS is successful, then we will have
|
||||||
// a deref suggestion in check_overloaded_binop
|
// emitted a better suggestion during error handling in check_overloaded_binop.
|
||||||
err.downgrade_to_delayed_bug();
|
if self
|
||||||
|
.lookup_op_method(
|
||||||
|
lhs_ty,
|
||||||
|
Some(rhs_ty),
|
||||||
|
Some(rhs),
|
||||||
|
Op::Binary(op, IsAssign::Yes),
|
||||||
|
expected,
|
||||||
|
)
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
err.downgrade_to_delayed_bug();
|
||||||
|
} else {
|
||||||
|
// Otherwise, it's valid to suggest dereferencing the LHS here.
|
||||||
|
err.span_suggestion_verbose(
|
||||||
|
lhs.span.shrink_to_lo(),
|
||||||
|
"consider dereferencing the left-hand side of this operation",
|
||||||
|
"*",
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
19
src/test/ui/typeck/assign-non-lval-needs-deref.rs
Normal file
19
src/test/ui/typeck/assign-non-lval-needs-deref.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// issue #101376
|
||||||
|
|
||||||
|
use std::ops::AddAssign;
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl AddAssign<()> for Foo {
|
||||||
|
fn add_assign(&mut self, _: ()) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddAssign<()> for &mut Foo {
|
||||||
|
fn add_assign(&mut self, _: ()) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
(&mut Foo) += ();
|
||||||
|
//~^ ERROR invalid left-hand side of assignment
|
||||||
|
//~| NOTE cannot assign to this expression
|
||||||
|
//~| HELP consider dereferencing the left-hand side of this operation
|
||||||
|
}
|
16
src/test/ui/typeck/assign-non-lval-needs-deref.stderr
Normal file
16
src/test/ui/typeck/assign-non-lval-needs-deref.stderr
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
error[E0067]: invalid left-hand side of assignment
|
||||||
|
--> $DIR/assign-non-lval-needs-deref.rs:15:16
|
||||||
|
|
|
||||||
|
LL | (&mut Foo) += ();
|
||||||
|
| ---------- ^^
|
||||||
|
| |
|
||||||
|
| cannot assign to this expression
|
||||||
|
|
|
||||||
|
help: consider dereferencing the left-hand side of this operation
|
||||||
|
|
|
||||||
|
LL | *(&mut Foo) += ();
|
||||||
|
| +
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0067`.
|
Loading…
Reference in New Issue
Block a user