Ask a question about using macros

Why #[macro_use] attribute macros cannot be used on use crate


pub use crate::web2::macros::cfg;

Compiler warns:

Valid forms are:

#[macro_use(name1, name2, ...)]
`#[macro_use]` only has an effect on `extern crate` and modules
`#[warn(unused_attributes)]` on by defaultrustc(unused_attributes)

I mean the error message says exactly why - they have to be declared on extern crate ... items. Anywhere else, they have no meaning.


I want to share use macros under multiple internal folders

This syntax is used to import all macros from a crate globally.

// in or
extern crate foo;

// can be used anywhere in your crate

Otherwise you have to import the macro with use in each file you need it.

use foo;


thanks, i try

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.