Cannot Use NoOp Procedural Macro as Custom Inner Attribute
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Hi, I am currently trying to use a procedural macro as a custom inner attribute to apply my macro to every function in my crate without manually adding it.
I am first trying to use a noop procedural macro which does not modify anything. This is the implementation of that macro--
#[proc_macro_attribute]
pub fn noop(_args: TokenStream, input: TokenStream) -> TokenStream {
let f = parse_macro_input!(input as ItemFn);
quote!(#f).into()
}
Then, in my main crate, I added this to the top of main.rs--
#![feature(custom_inner_attributes)]
#![my_macro_crate::noop]
In main.rs, there is my main function, and a few other functions to test if the macro will work when I use my real macro.
After running cargo +nightly run, I receive 4 errors--
error: expected square brackets
--> main.rs:1:1
(it also red highlights the end of the file)
error: #[panic_handler] function required, but not found
error: unwinding panics are not supported without std
error: main function not found
Is it expected for any procedural macros to work as custom inner attributes? Since this NoOp macro does not compile, is there something I did incorrectly in my setup?
Also, when I run cargo +nightly expand > output.rs, the only error is "expected square brackets", which also underlines the end of the file. And the only contents of output.rs is
#![feature(prelude_import)]
Meta
I am using a nightly build of rustc, installed with cargo a few days ago.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example from main.rs with cargo +nightly run, then compare the result from cargo +nightly expand. Read the noop procedural macro implementation and the custom_inner_attributes usage together; done means the expected support or limitation is established and the reported expansion errors are addressed or documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100