Skip to content

Commit 0bba4e5

Browse files
committed
Add a note when suggesting to use Impl Trait
Add tests Update compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs Co-authored-by: Lukas <[email protected]> Fixed tests
1 parent dc0943d commit 0bba4e5

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
856856
format!("impl {}", all_bounds_str),
857857
Applicability::MaybeIncorrect,
858858
);
859+
err.note(format!("the type of `{}` is chosen by the caller", expected_ty_as_param.name));
859860
}
860861

861862
pub(in super::super) fn suggest_missing_break_or_return_expr(

tests/ui/return/return-impl-trait-bad.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ LL | "don't suggest this, because the generic param is used in the bound."
5353
|
5454
= note: expected type parameter `T`
5555
found reference `&'static str`
56+
= note: the type of `T` is chosen by the caller
5657

5758
error: aborting due to 4 previous errors
5859

tests/ui/return/return-impl-trait.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LL | ()
1212
|
1313
= note: expected type parameter `T`
1414
found unit type `()`
15+
= note: the type of `T` is chosen by the caller
1516

1617
error[E0308]: mismatched types
1718
--> $DIR/return-impl-trait.rs:23:5
@@ -28,6 +29,7 @@ LL | ()
2829
|
2930
= note: expected type parameter `T`
3031
found unit type `()`
32+
= note: the type of `T` is chosen by the caller
3133

3234
error: aborting due to 2 previous errors
3335

0 commit comments

Comments
 (0)