Skip to content

Commit ea7eb49

Browse files
committed
Disable deprecated_cfg_attr lint for inner attributes
1 parent c0083e2 commit ea7eb49

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

clippy_lints/src/attrs.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,17 @@ impl EarlyLintPass for CfgAttrPass {
511511
// check for `rustfmt_skip` and `rustfmt::skip`
512512
if let Some(skip_item) = &items[1].meta_item();
513513
if skip_item.name() == "rustfmt_skip" || skip_item.name() == "skip";
514+
// Only lint outer attributes, because custom inner attributes are unstable
515+
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
516+
if let AttrStyle::Outer = attr.style;
514517
then {
515-
let attr_style = match attr.style {
516-
AttrStyle::Outer => "#[",
517-
AttrStyle::Inner => "#![",
518-
};
519518
span_lint_and_sugg(
520519
cx,
521520
DEPRECATED_CFG_ATTR,
522521
attr.span,
523522
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
524523
"use",
525-
format!("{}rustfmt::skip]", attr_style),
524+
"#[rustfmt::skip]".to_string(),
526525
Applicability::MachineApplicable,
527526
);
528527
}

tests/ui/cfg_attr_rustfmt.fixed

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// run-rustfix
2+
#![feature(stmt_expr_attributes)]
3+
4+
#![allow(unused, clippy::no_effect)]
5+
#![warn(clippy::deprecated_cfg_attr)]
6+
7+
// This doesn't get linted, see known problems
8+
#![cfg_attr(rustfmt, rustfmt_skip)]
9+
10+
#[rustfmt::skip]
11+
trait Foo
12+
{
13+
fn foo(
14+
);
15+
}
16+
17+
fn skip_on_statements() {
18+
#[rustfmt::skip]
19+
5+3;
20+
}
21+
22+
#[rustfmt::skip]
23+
fn main() {
24+
foo::f();
25+
}
26+
27+
mod foo {
28+
#![cfg_attr(rustfmt, rustfmt_skip)]
29+
30+
pub fn f() {}
31+
}

tests/ui/cfg_attr_rustfmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// run-rustfix
12
#![feature(stmt_expr_attributes)]
23

4+
#![allow(unused, clippy::no_effect)]
35
#![warn(clippy::deprecated_cfg_attr)]
46

57
// This doesn't get linted, see known problems

tests/ui/cfg_attr_rustfmt.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
2-
--> $DIR/cfg_attr_rustfmt.rs:16:5
2+
--> $DIR/cfg_attr_rustfmt.rs:18:5
33
|
44
LL | #[cfg_attr(rustfmt, rustfmt::skip)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
66
|
77
= note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings`
88

99
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
10-
--> $DIR/cfg_attr_rustfmt.rs:20:1
10+
--> $DIR/cfg_attr_rustfmt.rs:22:1
1111
|
1212
LL | #[cfg_attr(rustfmt, rustfmt_skip)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
1414

15-
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
16-
--> $DIR/cfg_attr_rustfmt.rs:26:5
17-
|
18-
LL | #![cfg_attr(rustfmt, rustfmt_skip)]
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#![rustfmt::skip]`
20-
21-
error: aborting due to 3 previous errors
15+
error: aborting due to 2 previous errors
2216

0 commit comments

Comments
 (0)