RS.CLIPPY.USELESS_ATTRIBUTE

Use of lint attributes on `extern crate` items

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: useless_attribute. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for extern crate and use items annotated with lint attributes.

This lint permits lint attributes for lints emitted on the items themself. For use items these lints are:

  • ambiguous_glob_reexports
  • dead_code
  • deprecated
  • hidden_glob_reexports
  • unreachable_pub
  • unused
  • unused_braces
  • unused_import_braces
  • clippy::disallowed_types
  • clippy::enum_glob_use
  • clippy::macro_use_imports
  • clippy::module_name_repetitions
  • clippy::redundant_pub_crate
  • clippy::single_component_path_imports
  • clippy::unsafe_removed_from_name
  • clippy::wildcard_imports

For extern crate items these lints are:

  • unused_imports on items with #[macro_use]

Why is this bad?

Lint attributes have no effect on crate imports. Most likely a ! was forgotten.

Example

#[deny(dead_code)]
extern crate foo;
#[forbid(dead_code)]
use foo::bar;

Use instead:

#[allow(unused_imports)]
use foo::baz;
#[allow(unused_imports)]
#[macro_use]
extern crate baz;