diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs
index 24cc8a81dc0..a3f2cc6a23b 100644
--- a/clippy_lints/src/attrs.rs
+++ b/clippy_lints/src/attrs.rs
@@ -511,18 +511,17 @@ impl EarlyLintPass for CfgAttrPass {
             // check for `rustfmt_skip` and `rustfmt::skip`
             if let Some(skip_item) = &items[1].meta_item();
             if skip_item.name() == "rustfmt_skip" || skip_item.name() == "skip";
+            // Only lint outer attributes, because custom inner attributes are unstable
+            // Tracking issue: https://github.com/rust-lang/rust/issues/54726
+            if let AttrStyle::Outer = attr.style;
             then {
-                let attr_style = match attr.style {
-                    AttrStyle::Outer => "#[",
-                    AttrStyle::Inner => "#![",
-                };
                 span_lint_and_sugg(
                     cx,
                     DEPRECATED_CFG_ATTR,
                     attr.span,
                     "`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
                     "use",
-                    format!("{}rustfmt::skip]", attr_style),
+                    "#[rustfmt::skip]".to_string(),
                     Applicability::MachineApplicable,
                 );
             }
diff --git a/tests/ui/cfg_attr_rustfmt.fixed b/tests/ui/cfg_attr_rustfmt.fixed
new file mode 100644
index 00000000000..4e583a25b94
--- /dev/null
+++ b/tests/ui/cfg_attr_rustfmt.fixed
@@ -0,0 +1,31 @@
+// run-rustfix
+#![feature(stmt_expr_attributes)]
+
+#![allow(unused, clippy::no_effect)]
+#![warn(clippy::deprecated_cfg_attr)]
+
+// This doesn't get linted, see known problems
+#![cfg_attr(rustfmt, rustfmt_skip)]
+
+#[rustfmt::skip]
+trait Foo
+{
+fn foo(
+);
+}
+
+fn skip_on_statements() {
+    #[rustfmt::skip]
+    5+3;
+}
+
+#[rustfmt::skip]
+fn main() {
+    foo::f();
+}
+
+mod foo {
+    #![cfg_attr(rustfmt, rustfmt_skip)]
+
+    pub fn f() {}
+}
diff --git a/tests/ui/cfg_attr_rustfmt.rs b/tests/ui/cfg_attr_rustfmt.rs
index 7f4a86ae185..9c0fcf6fb45 100644
--- a/tests/ui/cfg_attr_rustfmt.rs
+++ b/tests/ui/cfg_attr_rustfmt.rs
@@ -1,5 +1,7 @@
+// run-rustfix
 #![feature(stmt_expr_attributes)]
 
+#![allow(unused, clippy::no_effect)]
 #![warn(clippy::deprecated_cfg_attr)]
 
 // This doesn't get linted, see known problems
diff --git a/tests/ui/cfg_attr_rustfmt.stderr b/tests/ui/cfg_attr_rustfmt.stderr
index e60f5f25535..09971caceea 100644
--- a/tests/ui/cfg_attr_rustfmt.stderr
+++ b/tests/ui/cfg_attr_rustfmt.stderr
@@ -1,5 +1,5 @@
 error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
-  --> $DIR/cfg_attr_rustfmt.rs:16:5
+  --> $DIR/cfg_attr_rustfmt.rs:18:5
    |
 LL |     #[cfg_attr(rustfmt, rustfmt::skip)]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
@@ -7,16 +7,10 @@ LL |     #[cfg_attr(rustfmt, rustfmt::skip)]
    = note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings`
 
 error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
-  --> $DIR/cfg_attr_rustfmt.rs:20:1
+  --> $DIR/cfg_attr_rustfmt.rs:22:1
    |
 LL | #[cfg_attr(rustfmt, rustfmt_skip)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
 
-error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes
-  --> $DIR/cfg_attr_rustfmt.rs:26:5
-   |
-LL |     #![cfg_attr(rustfmt, rustfmt_skip)]
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#![rustfmt::skip]`
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors