Clippy lints / Suspicious
Clippy lint · Suspicious · checked with Clippy 0.1.99
clippy::empty_line_after_outer_attr: empty line after outer attribute
What it meansChecks for empty lines after outer attributes It is in the suspicious group and warns by default.
What you see
warning: empty line after outer attribute --> main.rs:3:1 | 3 | / #[allow(dead_code)] 4 | | | |_^ 5 | fn not_quite_good_code() {} | ---------------------- the attribute applies to this function | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#empty_line_after_outer_attr = note: `#[warn(clippy::empty_line_after_outer_attr)]` on by default = help: if the empty line is unintentional, remove it
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
The attribute may have meant to be an inner attribute (#![attr]). If it was meant to be an outer attribute (#[attr]) then the empty line should be removed
Code that is most likely wrong or useless. Warns by default.
How to fix it
Clippy does not fix this one automatically (its suggestion may change behaviour, so it only shows it). Change the code by hand:
Flagged
#[allow(dead_code)]
fn not_quite_good_code() {}
Write this instead
// Good (as inner attribute)
#![allow(dead_code)]
fn this_is_fine() {}
// or
// Good (as outer attribute)
#[allow(dead_code)]
fn this_is_fine_too() {}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::empty_line_after_outer_attr)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
empty_line_after_outer_attr = "allow"One run
cargo clippy -- -A clippy::empty-line-after-outer-attrThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for empty lines after outer attributes
Why is this bad?
The attribute may have meant to be an inner attribute (#![attr]). If
it was meant to be an outer attribute (#[attr]) then the empty line
should be removed
Example
#[allow(dead_code)]
fn not_quite_good_code() {}
Use instead:
// Good (as inner attribute)
#![allow(dead_code)]
fn this_is_fine() {}
// or
// Good (as outer attribute)
#[allow(dead_code)]
fn this_is_fine_too() {}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- duplicated_attributesduplicated attribute
- empty_docsempty doc comment
- empty_line_after_doc_commentsempty line after doc comment
- empty_loopempty `loop {}` wastes CPU cycles
- float_equality_without_absfloat equality check without `.abs()`
- for_unbounded_rangefor loop on unbounded range
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::duplicated_attributesduplicated attributeRead it next →Did this answer your question?