Email me

Clippy lints / Style

Clippy lint · Style · checked with Clippy 0.1.99

clippy::mixed_attributes_style: Checks for items that have the same kind of attributes with mixed styles (inner/outer)

What it meansChecks for items that have the same kind of attributes with mixed styles (inner/outer). It is in the style group and warns by default.

Does it matter?

Having both style of said attributes makes it more complicated to read code.

Code that works but is not idiomatic Rust. Warns by default.

How to fix it

Clippy does not fix this one automatically. Change the code by hand:

Flagged

#[custom_attribute]
pub fn foo() {
    #![my_crate::custom_attribute]
}

Write this instead

#[cfg(linux)]
pub fn foo() {
    #![cfg(windows)]
}

Turn it off, or on

Allow it where it does not fit your code, as narrowly as you can:

On one item

#[allow(clippy::mixed_attributes_style)]
fn my_function() { /* ... */ }

Whole crate (Cargo.toml)

[lints.clippy]
mixed_attributes_style = "allow"

One run

cargo clippy -- -A clippy::mixed-attributes-style

The [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.

Stylegroup
warndefault level
nofixed by cargo clippy --fix
1.78.0added in Rust

Clippy's own documentation

What it does

Checks for items that have the same kind of attributes with mixed styles (inner/outer).

Why is this bad?

Having both style of said attributes makes it more complicated to read code.

Known problems

This lint currently has false-negatives when mixing same attributes but they have different path symbols, for example:

#[custom_attribute]
pub fn foo() {
    #![my_crate::custom_attribute]
}

Example

#[cfg(linux)]
pub fn foo() {
    #![cfg(windows)]
}

Use instead:

#[cfg(linux)]
#[cfg(windows)]
pub fn foo() {
}

From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.

Related lints

All 847 Clippy lints · Rust compiler errors · Cargo.toml checker

Up next

Related lintclippy::needless_returnunneeded `return` statementRead it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ