tlborm icon indicating copy to clipboard operation
tlborm copied to clipboard

Is the "Macros in the AST" section still up to date?

Open gnzlbg opened this issue 8 years ago • 3 comments

The macros in the AST section says:

The first two are "attributes", and are shared between both language-specific constructs (such as #[repr(C)] which is used to request a C-compatible ABI for user-defined types) and syntax extensions (such as #[derive(Clone)]). There is currently no way to define a macro that uses these forms.

(emphasis mine)

But a custom-derive macro can use these forms, right? (otherwise sorry for the noise).

gnzlbg avatar Feb 12 '17 10:02 gnzlbg

Doesn't seem up to date. Seems like a vestige of the days before user defined proc macros were possible.

Redrield avatar Oct 23 '17 02:10 Redrield

I think this is outdated too, right?

As previously mentioned, macro processing in Rust happens after the construction of the AST. As such, the syntax used to invoke a macro must be a proper part of the language's syntax.

Also imo it is contradicted by this paragraph below:

Disregarding all but the third form ($name ! $arg), the question becomes: how does the Rust parser know what $arg looks like for every possible syntax extension? The answer is that it doesn't have to. Instead, the argument of a syntax extension invocation is a single token tree.

To me it seems, the chapter would be more accurate if these two sentences above were removed completely. Should I make a PR?

ropottnik avatar Oct 05 '20 11:10 ropottnik

Macro processing does happen after construction of the AST. There is just a special AST node for macro calls that contains a token tree.

No changes have been merged for five years now.

bjorn3 avatar Oct 05 '20 11:10 bjorn3