Skip to content

Method macros #15646

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

Merged
merged 9 commits into from
Jul 13, 2014
Merged

Method macros #15646

merged 9 commits into from
Jul 13, 2014

Conversation

jbclements
Copy link
Contributor

This patch adds support for macros in method position. It follows roughly the template for Item macros, where an outer Method wrapper contains a Method_ enum which can either be a macro invocation or a standard macro definition.

One note; adding support for macros that expand into multiple methods is not included here, but should be a simple parser change, since this patch updates the type of fold_macro to return a smallvector of methods.

For reviewers, please pay special attention to the parser changes; these are the ones I'm most concerned about.

Because of the small change to the interface of fold_method, this is a ...

[breaking change]

This change propagates to many locations, but because of the
Macro Exterminator (or, more properly, the invariant that it
protects), macro invocations can't occur downstream of expansion.
This means that in librustc and librustdoc, extracting the
desired field can simply assume that it can't be a macro
invocation. Functions in ast_util abstract over this check.
This is nice for macros, to allow them to expand into multiple methods
nothing wrong with a statement expanding into 0 stmts, that I can see.
this allows macro results to be parsed as methods
@sfackler
Copy link
Member

@jbclements
Copy link
Contributor Author

@sfackler fixed, thanks!

@emberian
Copy link
Member

r=me with the test and fix for the test squashed

@jbclements
Copy link
Contributor Author

cmr: which test squashed? one commit is a run-pass test, the other is a unit test. Or am I misunderstanding you?

@emberian
Copy link
Member

You're right, my bad.

bors added a commit that referenced this pull request Jul 13, 2014
This patch adds support for macros in method position. It follows roughly the template for Item macros, where an outer `Method` wrapper contains a `Method_` enum which can either be a macro invocation or a standard macro definition. 

One note; adding support for macros that expand into multiple methods is not included here, but should be a simple parser change, since this patch updates the type of fold_macro to return a smallvector of methods.

For reviewers, please pay special attention to the parser changes; these are the ones I'm most concerned about.

Because of the small change to the interface of fold_method, this is a ...

[breaking change]
@bors bors closed this Jul 13, 2014
@bors bors merged commit aee5917 into rust-lang:master Jul 13, 2014
@jbclements
Copy link
Contributor Author

On Jul 14, 2014, at 7:06 AM, Mitchell Nordine [email protected] wrote:

Awesome work! Really appreciating this new fancy ability.

Just thought I'd point out, I'm getting

error: use of undeclared type name Self

when trying to use the Self type as a return type.
Do you think this might be possible to do at some point?

Can you provide an example?

Many thanks,

John Clements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants