Support syntax for one-line trait reuse #150130
Open
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.
This PR adds support for reusing the whole trait with a one-line reuse syntax and is part of the delegation feature #118212:
The core idea is that we already have support for glob reuse, so in this scenario we want to transform one-line reuse into a trait impl block with a glob reuse in the following way:
It seems like this task can be solved during parsing stage, when we encountered a one-line trait reuse, we can expand into this impl block right away, and the code which was already written to expand glob delegations will take care about the rest. We will copy trait path into glob reuse path.
The implementation of the transformation reuses already existing methods for
implparsing, however, we do not parse innerimplitems, instead we parse "inner items" as delegation body. Thus, we do not have to deal with generics, consts, unsafe and otherimplrelated features.Other syntax possibility is trying to shorten one-line reuse by replacing
implkeyword withreusekeyword:In this case implementation may become more complicated, and the syntax more confusing, as keywords such as
constorunsafewill precedereuse, and there are also generics:In the first (currently implemented) version reuse is placed in the beginning of the item, and it is clear that we will reuse trait implementation, while in the second, shorter version, the
reusekeyword may be lost in generics and keywords that may precedeimpl.r? @petrochenkov