Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Point at method call when type annotations are needed #65951
Point at method call when type annotations are needed #65951
Changes from all commits
12af256
252773a
cca4b6d
33b0636
6b76d82
5d1adbb
2924d38
cc1ab3d
860c7e4
94ab9ec
45550ef
da023c0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @estebank if we wanted to say more about where the type parameter came from, we would augment this enum with the
DefId
of the parameter instead of its name (I imagine we can extract the name -- as well as the context -- from thatDefId
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #67277 to track this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was debating if this condition is sufficient. I decided it probably is, though we could also choose to be more selective.
One thing is that there won't always be a direct connection between the type parameters and the return type. e.g. it might be
but, then again, it's still true that specifying
T
would help to figure out theItem
type.Another is that there could be many parameters.
I could imagine searching through the substitutions for the call to detect cases (like
collect
) where the return type is directly linked to a parameter and limiting to that case, or highlighting which parameter specifies the return type in the case that there are many (e.g., maybe writing "try writing out the return typeX
, as infoo.bar::<_, _, X>()
"But it's probably "good enough" the way it is, tbh, those seem like "potential improvements". (And the best phrasing is sort of unclear anyway.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I did wonder is if we want to be careful around "defaults", though they are currently being phased out on functions:
you could imagine not showing
U
in our suggestions. But nobody quite knows what the semantics of said defaults should be so it's probably "ok as is".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with
#[allow(invalid_type_param_default)]
we do something more reasonable already IMO:For the
Iterator::Item
case, the output is not ideal, but not any worse than it already is:I'm inclined at leaving things as they are for now.
The last case is because we have a visitor looking at the method calls for something that resolves to
T
, but what we should be looking is a method call that resolves to<T as std::iter::Iterator>::Item
instead (for this case).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another interesting case: