1
Fork 0

Rollup merge of #116995 - estebank:issue-69944, r=compiler-errors

Point at assoc fn definition on type param divergence

When the number of type parameters in the associated function of an impl and its trait differ, we now *always* point at the trait one, even if it comes from a foreign crate. When it is local, we point at the specific params, when it is foreign, we point at the whole associated item.

Fix #69944.
This commit is contained in:
Matthias Krüger 2023-10-21 10:08:18 +02:00 committed by GitHub
commit e9d18f5f78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 20 deletions

View file

@ -1557,38 +1557,24 @@ fn compare_number_of_generics<'tcx>(
DiagnosticId::Error("E0049".into()), DiagnosticId::Error("E0049".into()),
); );
let mut suffix = None; let msg =
format!("expected {trait_count} {kind} parameter{}", pluralize!(trait_count),);
if let Some(spans) = trait_spans { if let Some(spans) = trait_spans {
let mut spans = spans.iter(); let mut spans = spans.iter();
if let Some(span) = spans.next() { if let Some(span) = spans.next() {
err.span_label( err.span_label(*span, msg);
*span,
format!(
"expected {} {} parameter{}",
trait_count,
kind,
pluralize!(trait_count),
),
);
} }
for span in spans { for span in spans {
err.span_label(*span, ""); err.span_label(*span, "");
} }
} else { } else {
suffix = Some(format!(", expected {trait_count}")); err.span_label(tcx.def_span(trait_.def_id), msg);
} }
if let Some(span) = span { if let Some(span) = span {
err.span_label( err.span_label(
span, span,
format!( format!("found {} {} parameter{}", impl_count, kind, pluralize!(impl_count),),
"found {} {} parameter{}{}",
impl_count,
kind,
pluralize!(impl_count),
suffix.unwrap_or_default(),
),
); );
} }

View file

@ -2,7 +2,12 @@ error[E0049]: method `foo` has 1 type parameter but its trait declaration has 0
--> $DIR/issue-36708.rs:8:12 --> $DIR/issue-36708.rs:8:12
| |
LL | fn foo<T>() {} LL | fn foo<T>() {}
| ^ found 1 type parameter, expected 0 | ^ found 1 type parameter
|
::: $DIR/auxiliary/issue-36708.rs:4:5
|
LL | fn foo();
| --------- expected 0 type parameters
error: aborting due to previous error error: aborting due to previous error