Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
format!("impl {}", all_bounds_str),
Applicability::MaybeIncorrect,
);
err.note(format!("the type of `{}` is chosen by the caller", expected_ty_as_param.name));
Copy link
Member

@compiler-errors compiler-errors May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this note adds much value in this context. Not exactly sure why, but something about the ordering or placement of this note feels to me like it's missing context.

In the tests/ui/return/return-impl-trait-bad.stderr stderr below:

LL | fn used_in_trait<T>() -> T
   |                  -       -
   |                  |       |
   |                  |       expected `T` because of return type
   |                  |       help: consider using an impl return type: `impl Send`
   |                  this type parameter

My sense would be that "this type parameter" label could be replaced with the text above... Not sure how hard that is though.

Alternatively, "the type of {} is chosen by the caller" should probably be extended to explain its significance. Maybe something along the lines of "and may be a type that is different than {(the other type mentioned)}"...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the message to explain its significance. However finding exactly where "this type parameter" is derived from and put into the message here is a bit hard. Do let me know if this is sufficient, or if not some more context on how I can find the construction of the above "this type parameter"

}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compiler-errors Here found_ty_as_param should return the parameter found right, or am I understanding something wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need found_ty_as_param -- the found ty might be any type, and you can just render that to string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    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.to_string()));

Converting found to string still does not return the type expected.


pub(in super::super) fn suggest_missing_break_or_return_expr(
Expand Down
1 change: 1 addition & 0 deletions tests/ui/return/return-impl-trait-bad.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

error: aborting due to 4 previous errors

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/return/return-impl-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LL | ()
|
= note: expected type parameter `T`
found unit type `()`
= note: the type of `T` is chosen by the caller

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

error: aborting due to 2 previous errors

Expand Down