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
Permit impl Trait in type aliases #2515
Permit impl Trait in type aliases #2515
Changes from 13 commits
b0bf8c5
1082efd
d6db251
c62791c
c0a0fc6
3c25784
5d15369
70baad7
f45db44
7fbc159
21322a6
1b10512
2cf0366
4076858
956a51d
2b921f9
1691e6e
b02be50
e7e26ea
f81510c
bc1f25a
758e49d
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.
My biggest issue with this restriction is that it makes
impl Trait
inconsistent between type aliases and everywhere else (excluding the already inconsistent argument position). Withexistential type
there was a simple rule that could be applied toimpl Trait
in every position except argument position: it introduces a new anonymousexistential type
in the current context. This rule works perfectly for return position, type declaration in bindings, type aliases, and could work for type declaration of struct/enum members if there wasn't a chance of confusion with argument-position-impl-trait.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'm not quite sure I follow your point. This restriction is simply a syntactic one: it is simply intended to sidestep the question of what:
means for now (because some people expressed unease at this construction in particular).
impl Trait
continues to be applicable in exactly the same places asexistential type
: this rule simply means it can't be used in more complex scenarios thanexistential type
yet.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 mean that with existential types it's possible to have a single very simple rule for desugaring
impl Trait
that covers both:but with
type Foo = impl Trait;
trying to apply the same sort of rule you get to this recursive definition that needs a special case when you use a bareimpl Trait
in a type alias.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.
Ah, I see. Yes, you do have to have a single type alias as a base case if you're using the
impl Trait
type aliases to desugar. In practice, the desugaring ofexistential type
is effectively replaced by the type alias. That is, theexistential type
design was originally intended to act as a desugaring for return-position and variable-binding (e.g.let
)impl Trait
. Using type aliases fills that role: but you can't use it to desugar itself. In practice, I don't think this is important, as there's no practical difference between theexistential type
itself and its alias.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.
Why can't it be used to desugar, @varkor?
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.
Because if you try to desugar each occurrence of
impl Trait
you would end up trying to desugar:into:
so you need to have this as a base case.