Disable deprecated_cfg_attr lint for inner attributes

This commit is contained in:
Wilco Kusee 2019-01-13 11:53:43 +01:00
parent c0083e2b98
commit ea7eb49b47
4 changed files with 40 additions and 14 deletions

View File

@ -511,18 +511,17 @@ impl EarlyLintPass for CfgAttrPass {
// check for `rustfmt_skip` and `rustfmt::skip` // check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item(); if let Some(skip_item) = &items[1].meta_item();
if skip_item.name() == "rustfmt_skip" || skip_item.name() == "skip"; 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 { then {
let attr_style = match attr.style {
AttrStyle::Outer => "#[",
AttrStyle::Inner => "#![",
};
span_lint_and_sugg( span_lint_and_sugg(
cx, cx,
DEPRECATED_CFG_ATTR, DEPRECATED_CFG_ATTR,
attr.span, attr.span,
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes", "`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
"use", "use",
format!("{}rustfmt::skip]", attr_style), "#[rustfmt::skip]".to_string(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} }

View File

@ -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() {}
}

View File

@ -1,5 +1,7 @@
// run-rustfix
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]
#![allow(unused, clippy::no_effect)]
#![warn(clippy::deprecated_cfg_attr)] #![warn(clippy::deprecated_cfg_attr)]
// This doesn't get linted, see known problems // This doesn't get linted, see known problems

View File

@ -1,5 +1,5 @@
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes 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)] LL | #[cfg_attr(rustfmt, rustfmt::skip)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[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` = note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings`
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes 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)] LL | #[cfg_attr(rustfmt, rustfmt_skip)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes error: aborting due to 2 previous errors
--> $DIR/cfg_attr_rustfmt.rs:26:5
|
LL | #![cfg_attr(rustfmt, rustfmt_skip)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#![rustfmt::skip]`
error: aborting due to 3 previous errors