Skip to content

Commit f78369b

Browse files
committed
fix: dedup static_candidates before report
1 parent 1221e43 commit f78369b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+6
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473473
let mut custom_span_label = false;
474474

475475
let static_candidates = &mut no_match_data.static_candidates;
476+
477+
// `static_candidates` may have same candidates appended by
478+
// inherent and extension, which may result in incorrect
479+
// diagnostic.
480+
static_candidates.dedup();
481+
476482
if !static_candidates.is_empty() {
477483
err.note(
478484
"found the following associated functions; to be used as methods, \

tests/ui/suggestions/issue-103646.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Cat {
2+
fn nya() {}
3+
}
4+
5+
fn uwu<T: Cat>(c: T) {
6+
c.nya();
7+
//~^ ERROR no method named `nya` found for type parameter `T` in the current scope
8+
//~| Suggestion T::nya()
9+
}
10+
11+
fn main() {}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0599]: no method named `nya` found for type parameter `T` in the current scope
2+
--> $DIR/issue-103646.rs:6:7
3+
|
4+
LL | fn uwu<T: Cat>(c: T) {
5+
| - method `nya` not found for this type parameter
6+
LL | c.nya();
7+
| --^^^--
8+
| | |
9+
| | this is an associated function, not a method
10+
| help: use associated function syntax instead: `T::nya()`
11+
|
12+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
13+
note: the candidate is defined in the trait `Cat`
14+
--> $DIR/issue-103646.rs:2:5
15+
|
16+
LL | fn nya() {}
17+
| ^^^^^^^^
18+
19+
error: aborting due to previous error
20+
21+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)