rustc_lint::builtin

Static MACRO_USE_EXTERN_CRATE

source
pub static MACRO_USE_EXTERN_CRATE: &'static Lint
Expand description

The macro_use_extern_crate lint detects the use of the macro_use attribute.

§Example

#![deny(macro_use_extern_crate)]

#[macro_use]
extern crate serde_json;

fn main() {
    let _ = json!{{}};
}

This will produce:

error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
 --> src/main.rs:3:1
  |
3 | #[macro_use]
  | ^^^^^^^^^^^^
  |
  = help: remove it and import macros at use sites with a `use` item instead
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(macro_use_extern_crate)]
  |         ^^^^^^^^^^^^^^^^^^^^^^

§Explanation

The macro_use attribute on an [extern crate] item causes macros in that external crate to be brought into the prelude of the crate, making the macros in scope everywhere. As part of the efforts to simplify handling of dependencies in the [2018 edition], the use of extern crate is being phased out. To bring macros from extern crates into scope, it is recommended to use a use import.

This lint is “allow” by default because this is a stylistic choice that has not been settled, see issue #52043 for more information.