Skip to content

Commit 6c7a5ba

Browse files
committed
Only suggest assoc fn when sure about the type
1 parent 447d894 commit 6c7a5ba

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc_typeck/check/method/suggest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
380380
if !static_sources.is_empty() {
381381
err.note("found the following associated functions; to be used as methods, \
382382
functions must have a `self` parameter");
383+
}
384+
if static_sources.len() == 1 {
383385
if let Some(expr) = rcvr_expr {
384386
err.span_suggestion(expr.span.to(span),
385387
"use associated function syntax intead",
@@ -389,6 +391,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
389391
self.ty_to_string(actual), item_name));
390392
}
391393

394+
report_candidates(&mut err, static_sources);
395+
} else if static_sources.len() > 1 {
396+
392397
report_candidates(&mut err, static_sources);
393398
}
394399

src/test/ui/span/issue-7575.stderr

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no method named `f9` found for type `usize` in the current scope
22
--> $DIR/issue-7575.rs:74:18
33
|
44
LL | u.f8(42) + u.f9(342) + m.fff(42)
5-
| --^^
6-
| |
7-
| help: use associated function syntax intead: `usize::f9`
5+
| ^^
86
|
97
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
108
note: candidate #1 is defined in the trait `CtxtFn`
@@ -53,9 +51,7 @@ error[E0599]: no method named `is_str` found for type `T` in the current scope
5351
--> $DIR/issue-7575.rs:82:7
5452
|
5553
LL | t.is_str()
56-
| --^^^^^^
57-
| |
58-
| help: use associated function syntax intead: `T::is_str`
54+
| ^^^^^^
5955
|
6056
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
6157
note: the candidate is defined in the trait `ManyImplTrait`

0 commit comments

Comments
 (0)