DanielKeep / tlborm

The Little Book of Rust Macros
880 stars 96 forks source link

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

Open gnzlbg opened 7 years ago

gnzlbg commented 7 years ago

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).

Redrield commented 6 years ago

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

ropottnik commented 4 years ago

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?

bjorn3 commented 4 years ago

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.