-
Notifications
You must be signed in to change notification settings - Fork 501
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
Add more content to impl-trait.md #1017
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ed438b9
Update impl-trait from edition-guide
tlyu 999a143
Fix typo(impl-trait)
tlyu d9264ab
impl-trait: less update-y; more reference-y
tlyu 48d970e
impl-trait: don't talk about future Rust
tlyu ec1ee92
impl-trait: generics vs `impl Trait` as return
tlyu 4531218
impl-trait: condense return type examples
tlyu 1a2f82e
address PR feedback
tlyu 94085bb
use "argument", "parameter" more consistently
tlyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 can see how changing from generic parameter to impl trait would be a breaking change, but can you explain how the reverse is also a breaking change?
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 this was based on text that I copied from the edition guide. For the reverse direction, I'm not especially familiar with using turbofish when there are multiple type parameters, e.g., what if we went from
to
Is it valid to omit the second type parameter? How does the compiler know which one is omitted? (I can't find any text in the reference about this case.) I'm sorry if this is a bad example.
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 experimented a bit in the playground, and it seems like in practice:
impl Trait
in argument position, turbofish may not be used for any type arguments at all (edit: apparently this includes type parameters for the return type!)Side note: are we avoiding using the term "turbofish" in the reference?
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 see. The second parameter can be omitted if it is defaulted, like
<T, U=T>
, but that can't be done with functions.The reference normally doesn't discuss semver compatibility since that is a cargo concept (documented here). It's probably fine to leave this as-is, though.
There is one mention of turbofish, plus another in the glossary, but otherwise it usually doesn't come up.
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.
Some further experimentation suggests that both my proposed text and the edition guide are differently wrong:
impl Trait
in return position doesn't prevent the use of turbofish, contrary to the edition guide, which says that "In the case of impl Trait, if it is used anywhere in the function definition, then you can't use turbo-fish at all"impl Trait
in any parameter type prevents the caller from providing any generic arguments at all, including return type and even const generics (No way to usefn
with both const generics andimpl Trait
rust#85475)! This is contrary to my text, which says it only prevents turbofish for that parameter.