Code
struct S;
trait Trait {
fn foo() {}
}
impl Trait for &S {}
impl Trait for &mut S {}
fn main() {
let _ = S::foo();
}
Current output
error[E0277]: the trait bound `S: Trait` is not satisfied
--> $DIR/dont-suggest-borrowing-existing-borrow.rs:17:13
|
LL | let _ = S::foo();
| ^ the trait `Trait` is not implemented for `S`
|
help: consider borrowing here
|
LL | let _ = &S::foo();
| +
LL | let _ = &mut S::foo();
| ++++
Desired output
error[E0277]: the trait bound `S: Trait` is not satisfied
--> $DIR/dont-suggest-borrowing-existing-borrow.rs:17:13
|
LL | let _ = S::foo();
| ^ the trait `Trait` is not implemented for `S`
|
help: consider borrowing here
|
LL | let _ = <&S>::foo();
| ++ +
LL | let _ = <&mut S>::foo();
| +++++ +
Rationale and extra context
No response
Other cases
Rust Version
Anything else?
This happens because the suggestion code assumes that the obligation always comes from an expression.
Found while working on #132469
Code
Current output
Desired output
Rationale and extra context
No response
Other cases
Rust Version
Anything else?
This happens because the suggestion code assumes that the obligation always comes from an expression.
Found while working on #132469