Rollup merge of #112057 - MU001999:fix/self-sugg, r=compiler-errors
Suggest correct `self_ty` Fixes #112036
This commit is contained in:
commit
880da380f1
@ -902,7 +902,7 @@ fn report_trait_method_mismatch<'tcx>(
|
|||||||
if trait_m.fn_has_self_parameter =>
|
if trait_m.fn_has_self_parameter =>
|
||||||
{
|
{
|
||||||
let ty = trait_sig.inputs()[0];
|
let ty = trait_sig.inputs()[0];
|
||||||
let sugg = match ExplicitSelf::determine(ty, |_| ty == impl_trait_ref.self_ty()) {
|
let sugg = match ExplicitSelf::determine(ty, |ty| ty == impl_trait_ref.self_ty()) {
|
||||||
ExplicitSelf::ByValue => "self".to_owned(),
|
ExplicitSelf::ByValue => "self".to_owned(),
|
||||||
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
|
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
|
||||||
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),
|
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),
|
||||||
|
@ -22,7 +22,7 @@ LL | fn bar(&mut self) { }
|
|||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| types differ in mutability
|
| types differ in mutability
|
||||||
| help: change the self-receiver type to match the trait: `self: &Bar`
|
| help: change the self-receiver type to match the trait: `&self`
|
||||||
|
|
|
|
||||||
note: type in trait
|
note: type in trait
|
||||||
--> $DIR/E0053.rs:3:12
|
--> $DIR/E0053.rs:3:12
|
||||||
|
7
tests/ui/mismatched_types/issue-112036.rs
Normal file
7
tests/ui/mismatched_types/issue-112036.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl Drop for Foo {
|
||||||
|
fn drop(self) {} //~ ERROR method `drop` has an incompatible type for trait
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
15
tests/ui/mismatched_types/issue-112036.stderr
Normal file
15
tests/ui/mismatched_types/issue-112036.stderr
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
error[E0053]: method `drop` has an incompatible type for trait
|
||||||
|
--> $DIR/issue-112036.rs:4:13
|
||||||
|
|
|
||||||
|
LL | fn drop(self) {}
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| expected `&mut Foo`, found `Foo`
|
||||||
|
| help: change the self-receiver type to match the trait: `&mut self`
|
||||||
|
|
|
||||||
|
= note: expected signature `fn(&mut Foo)`
|
||||||
|
found signature `fn(Foo)`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0053`.
|
Loading…
x
Reference in New Issue
Block a user