Lint attribute placed on an import declaration

ID

rust.correctness.lint_attrs_crate_imports

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Suspicious Construct

Language

Rust

Description

Detects allow, warn, deny, forbid or expect attributes attached to a use or extern crate declaration.

Rationale

A lint attribute on an import governs only the diagnostics the compiler emits at that declaration; it does not follow the imported name to the places it is used, which is what most readers assume. In practice the attribute is either inert or it silences unused_imports and so preserves an import that should have been deleted, hiding the stale dependency from every later reader.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Lint attribute placed on an import declaration
#[allow(unused_imports)]
use std::collections::HashMap;

Remediation

Delete the attribute. If the import really is unused, remove the import itself; if a lint must be relaxed for the code that uses the imported item, put the attribute on that function, block or module instead of on the import.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved