-
Notifications
You must be signed in to change notification settings - Fork 10
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
Nested invocation in substitutions #28
Comments
There is little difference between a nested invocation and a new top-level invocation that happens to be in a substitution, except for when they are expanded and therefore the legality. Thought experiment: Given a nested invocation that produces X. Therefore, the only difference is whether a given invocation would result in macro-legal intermediate Rust expansions. It would therefore not be problematic to change the nested substitution syntax to
|
Another alternative: Anywhere in either the invocation or the body, any presence of First, it solves the problem presented in this issue, but also another one discussed in #26 regarding repetition in the body. We would still have the problem of this not playing well with |
Regarding the alternative in the previous comment: Looking for |
Final decision: Use |
Nested invocations have been upgraded to work everywhere, which includes this use case. Awaiting next release. |
Short Description:
Enable nested invocations inside substitution blocks.
Motivation:
Take #26, where we have many struct members needing to be instantiated to the same value:
We would like to be able to make a single invocation that inserts the instantiations many places. The closest we get today is:
However, this repeats the
:0 ,
bit for every member.Nested invocation would be able to remove this repetition. However, it is not available inside substitutions. Enabling it, would allow us to do:
Design
The first problem with enabling nested invocations inside substitutions is how to handle user attributes. Since we currently use the syntax
#[..][..]
to denote nested invocation, this prohibits users from using attributes inside substitutions, as they would be assumed to be nested invocations.To alleviate this, we change the syntax of nested invocations to
#duplicate[..][..]
. This is generally illegal Rust syntax, so no user would write this outside specifically when nested invocations are wanted. However, it is valid syntax, allowing us to parse it.This is, if course, a breaking change, as it will also be the syntax use for existing nested invocations.
Misc:
Syntax alternatives
#[duplicate( .. )]
: This mimics top-level invocations. However, it means we cannot distinguish between nested invocations and new top-level invocations that happen to be in the substitutions.The text was updated successfully, but these errors were encountered: