diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index c4add4dbdfb2f..aa1294d2c3acb 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -856,6 +856,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("impl {}", all_bounds_str), Applicability::MaybeIncorrect, ); + + let ty::Param(found_ty_as_param) = found.kind() else { return }; + err.note(format!("the type of `{}` is chosen by the caller and may be a type that is different from `{}`", expected_ty_as_param.name, found_ty_as_param.name)); } pub(in super::super) fn suggest_missing_break_or_return_expr( diff --git a/tests/ui/return/return-impl-trait-bad.stderr b/tests/ui/return/return-impl-trait-bad.stderr index 237b85ee66a10..30d7dd4f9541d 100644 --- a/tests/ui/return/return-impl-trait-bad.stderr +++ b/tests/ui/return/return-impl-trait-bad.stderr @@ -53,6 +53,7 @@ LL | "don't suggest this, because the generic param is used in the bound." | = note: expected type parameter `T` found reference `&'static str` + = note: the type of `T` is chosen by the caller and may be a type that is different than `T` error: aborting due to 4 previous errors diff --git a/tests/ui/return/return-impl-trait.stderr b/tests/ui/return/return-impl-trait.stderr index 43d40972fcac0..55e52d323ff24 100644 --- a/tests/ui/return/return-impl-trait.stderr +++ b/tests/ui/return/return-impl-trait.stderr @@ -12,6 +12,7 @@ LL | () | = note: expected type parameter `T` found unit type `()` + = note: the type of `T` is chosen by the caller and may be a type that is different than `T` error[E0308]: mismatched types --> $DIR/return-impl-trait.rs:23:5 @@ -28,6 +29,7 @@ LL | () | = note: expected type parameter `T` found unit type `()` + = note: the type of `T` is chosen by the caller and may be a type that is different than `T` error: aborting due to 2 previous errors