Skip to content

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
Contributor

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
Contributor

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

flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 18, 2025
decided to put each lint extraction into a separate commit this time --
do let me know if you prefer all of that being in a single commit
instead

changelog: none
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