Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot Use NoOp Procedural Macro as Custom Inner Attribute #143003

Open
Labels
A-attributesArea: Attributes (`#[...]`, `#![...]`) A-proc-macrosArea: Procedural macros C-discussionCategory: Discussion or questions that doesn't represent real issues.
@benwu25

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[...]`, `#![...]`) A-proc-macrosArea: Procedural macros C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /