Can rustc recognize custom tool namespace for macros?

From https://doc.rust-lang.org/beta/reference/attributes.html:

When a tool is not in use, the tool's attributes are accepted without a warning. When the tool is in use, the tool is responsible for processing and interpretation of its attributes.

and

Note: rustc currently recognizes the tools "clippy" and "rustfmt".

Is it possible to add a new custom tool to this list? I'm trying to annotate an enum variant with a macro:

enum Test {
    A,
    #[tool::enum_attr]
    B,
    C
}

but I get:

error: expected non-macro attribute, found attribute macro tool::enum_attr

Procedural Macros - The Rust Reference

Attribute macros define new outer attributes which can be attached to items, including items in extern blocks, inherent and trait implementations, and trait definitions.

Doesn't look like you can put a macro there. You'd have to do something like this:

#[tool::macro]
enum Test {
    A,
    #[enum_attr]
    B,
    C
}

Tools are installed with rustup and aren't for the things macros are for.

some support is in nightly, see Tracking issue for `#![register_tool]` · Issue #66079 · rust-lang/rust · GitHub

Yes, but I'm writing my own tool and would like to place an attribute annotation for it on an enum entry, which I'd then like rustc to ignore - ie not treat as a macro.

Edit: I see I wrote 'annotate an enum variant with a macro', I should have said attribute.

Can't you make that attribute into a trivial procedural macro that simply emits its input (i.e., does nothing)? Then you can slap it on anything you please, it won't affect anything, the compiler will be happy, and your tool can look for it in the AST.

That's not allowed for enum variants - that's what the compiler error in the question is from.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.