Rollup merge of #104580 - notriddle:notriddle/issue-102354-hide-sugg, r=compiler-errors
diagnostics: only show one suggestion for method -> assoc fn Fixes #102354
This commit is contained in:
commit
3cf3a65a71
@ -114,7 +114,7 @@ pub fn report_method_error(
|
|||||||
let report_candidates = |span: Span,
|
let report_candidates = |span: Span,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
sources: &mut Vec<CandidateSource>,
|
sources: &mut Vec<CandidateSource>,
|
||||||
sugg_span: Span| {
|
sugg_span: Option<Span>| {
|
||||||
sources.sort();
|
sources.sort();
|
||||||
sources.dedup();
|
sources.dedup();
|
||||||
// Dynamic limit to avoid hiding just one candidate, which is silly.
|
// Dynamic limit to avoid hiding just one candidate, which is silly.
|
||||||
@ -175,7 +175,8 @@ pub fn report_method_error(
|
|||||||
} else {
|
} else {
|
||||||
err.note(¬e_str);
|
err.note(¬e_str);
|
||||||
}
|
}
|
||||||
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) {
|
if let Some(sugg_span) = sugg_span
|
||||||
|
&& let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) {
|
||||||
let path = self.tcx.def_path_str(trait_ref.def_id);
|
let path = self.tcx.def_path_str(trait_ref.def_id);
|
||||||
|
|
||||||
let ty = match item.kind {
|
let ty = match item.kind {
|
||||||
@ -224,20 +225,22 @@ pub fn report_method_error(
|
|||||||
err.span_note(item_span, msg);
|
err.span_note(item_span, msg);
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let path = self.tcx.def_path_str(trait_did);
|
if let Some(sugg_span) = sugg_span {
|
||||||
print_disambiguation_help(
|
let path = self.tcx.def_path_str(trait_did);
|
||||||
item_name,
|
print_disambiguation_help(
|
||||||
args,
|
item_name,
|
||||||
err,
|
args,
|
||||||
path,
|
err,
|
||||||
rcvr_ty,
|
path,
|
||||||
item.kind,
|
rcvr_ty,
|
||||||
item.def_id,
|
item.kind,
|
||||||
sugg_span,
|
item.def_id,
|
||||||
idx,
|
sugg_span,
|
||||||
self.tcx.sess.source_map(),
|
idx,
|
||||||
item.fn_has_self_parameter,
|
self.tcx.sess.source_map(),
|
||||||
);
|
item.fn_has_self_parameter,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,9 +410,9 @@ pub fn report_method_error(
|
|||||||
sugg_span,
|
sugg_span,
|
||||||
);
|
);
|
||||||
|
|
||||||
report_candidates(span, &mut err, &mut static_candidates, sugg_span);
|
report_candidates(span, &mut err, &mut static_candidates, None);
|
||||||
} else if static_candidates.len() > 1 {
|
} else if static_candidates.len() > 1 {
|
||||||
report_candidates(span, &mut err, &mut static_candidates, sugg_span);
|
report_candidates(span, &mut err, &mut static_candidates, Some(sugg_span));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bound_spans = vec![];
|
let mut bound_spans = vec![];
|
||||||
@ -1015,7 +1018,7 @@ trait bound{s}",
|
|||||||
);
|
);
|
||||||
err.span_label(item_name.span, format!("multiple `{}` found", item_name));
|
err.span_label(item_name.span, format!("multiple `{}` found", item_name));
|
||||||
|
|
||||||
report_candidates(span, &mut err, &mut sources, sugg_span);
|
report_candidates(span, &mut err, &mut sources, Some(sugg_span));
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,10 @@ error[E0599]: no method named `func` found for type `i32` in the current scope
|
|||||||
--> $DIR/issue-102354.rs:9:7
|
--> $DIR/issue-102354.rs:9:7
|
||||||
|
|
|
|
||||||
LL | x.func();
|
LL | x.func();
|
||||||
| ^^^^ this is an associated function, not a method
|
| --^^^^--
|
||||||
|
| | |
|
||||||
|
| | this is an associated function, not a method
|
||||||
|
| help: use associated function syntax instead: `i32::func()`
|
||||||
|
|
|
|
||||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||||
note: the candidate is defined in the trait `Trait`
|
note: the candidate is defined in the trait `Trait`
|
||||||
@ -10,14 +13,6 @@ note: the candidate is defined in the trait `Trait`
|
|||||||
|
|
|
|
||||||
LL | fn func() {}
|
LL | fn func() {}
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
help: use associated function syntax instead
|
|
||||||
|
|
|
||||||
LL | i32::func();
|
|
||||||
| ~~~~~~~~~~~
|
|
||||||
help: disambiguate the associated function for the candidate
|
|
||||||
|
|
|
||||||
LL | <i32 as Trait>::func(x);
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user