Skip to content

Commit 1f44d4a

Browse files
committed
Fix 'self' in method signature suggestions
1 parent 367dba7 commit 1f44d4a

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,13 @@ fn compare_number_of_method_arguments<'tcx>(
18141814
})
18151815
.or_else(|| {
18161816
let signature = trait_m.signature(tcx);
1817-
find_param_bounds(&signature).map(|(lo, hi)| signature[lo..hi].trim().to_string())
1817+
find_param_bounds(&signature).map(|(lo, hi)| {
1818+
let mut params = signature[lo..hi].trim().to_string();
1819+
if trait_m.is_method() {
1820+
params = params.replacen("Self", "self", 1);
1821+
}
1822+
params
1823+
})
18181824
});
18191825

18201826
if let (Some(span), Some(missing)) = (impl_inputs_span, missing_params) {

tests/ui/fn/issue-39259.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ LL | fn call(&self) -> u32 {
1919
= note: `call` from trait: `extern "rust-call" fn(&Self, Args) -> <Self as FnOnce<Args>>::Output`
2020
help: modify the signature to match the trait definition
2121
|
22-
LL - fn call(&self) -> u32 {
23-
LL + fn call(&Self, Args) -> u32 {
24-
|
22+
LL | fn call(&self, Args) -> u32 {
23+
| ++++++
2524

2625
error[E0277]: expected a `FnMut(u32)` closure, found `S`
2726
--> $DIR/issue-39259.rs:6:25

tests/ui/impl-trait/trait_type.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ LL | fn fmt(&self) -> () { }
2121
= note: `fmt` from trait: `fn(&Self, &mut Formatter<'_>) -> Result<(), std::fmt::Error>`
2222
help: modify the signature to match the trait definition
2323
|
24-
LL - fn fmt(&self) -> () { }
25-
LL + fn fmt(&Self, &mut Formatter<'_>) -> () { }
26-
|
24+
LL | fn fmt(&self, &mut Formatter<'_>) -> () { }
25+
| ++++++++++++++++++++
2726

2827
error[E0186]: method `fmt` has a `&self` declaration in the trait, but not in the impl
2928
--> $DIR/trait_type.rs:17:4

0 commit comments

Comments
 (0)