Skip to content

Commit 2f65aac

Browse files
committed
Determine self_ty with expected ty
1 parent 089677e commit 2f65aac

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ fn report_trait_method_mismatch<'tcx>(
901901
if trait_m.fn_has_self_parameter =>
902902
{
903903
let ty = trait_sig.inputs()[0];
904-
let sugg = match ExplicitSelf::determine(ty, |_| ty == impl_trait_ref.self_ty()) {
904+
let sugg = match ExplicitSelf::determine(ty, |ty| ty == impl_trait_ref.self_ty()) {
905905
ExplicitSelf::ByValue => "self".to_owned(),
906906
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
907907
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),

tests/ui/mismatched_types/E0053.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | fn bar(&mut self) { }
2222
| ^^^^^^^^^
2323
| |
2424
| types differ in mutability
25-
| help: change the self-receiver type to match the trait: `self: &Bar`
25+
| help: change the self-receiver type to match the trait: `&self`
2626
|
2727
note: type in trait
2828
--> $DIR/E0053.rs:3:12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct Foo;
2+
3+
impl Drop for Foo {
4+
fn drop(self) {} //~ ERROR method `drop` has an incompatible type for trait
5+
}
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0053]: method `drop` has an incompatible type for trait
2+
--> $DIR/issue-112036.rs:4:13
3+
|
4+
LL | fn drop(self) {}
5+
| ^^^^
6+
| |
7+
| expected `&mut Foo`, found `Foo`
8+
| help: change the self-receiver type to match the trait: `&mut self`
9+
|
10+
= note: expected signature `fn(&mut Foo)`
11+
found signature `fn(Foo)`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)