diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 66f452040954b..27d13cb85c14b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -159,9 +159,9 @@ impl, S: Stage> AttributeParser for Single if let Some(pa) = T::convert(cx, args) { if let Some((_, used)) = group.1 { T::ON_DUPLICATE.exec::(cx, used, cx.attr_span); + } else { + group.1 = Some((pa, cx.attr_span)); } - - group.1 = Some((pa, cx.attr_span)); } }, )]; diff --git a/tests/ui/attributes/attr-order-deprecated.rs b/tests/ui/attributes/attr-order-deprecated.rs new file mode 100644 index 0000000000000..606e714819b50 --- /dev/null +++ b/tests/ui/attributes/attr-order-deprecated.rs @@ -0,0 +1,11 @@ +#[deprecated = "AAA"] +//~^ NOTE also specified here +#[deprecated = "BBB"] +//~^ ERROR multiple `deprecated` attributes +fn deprecated() { } + +fn main() { + deprecated(); + //~^ WARN use of deprecated function `deprecated`: AAA [deprecated] + //~| NOTE `#[warn(deprecated)]` on by default +} diff --git a/tests/ui/attributes/attr-order-deprecated.stderr b/tests/ui/attributes/attr-order-deprecated.stderr new file mode 100644 index 0000000000000..41e26bec761ee --- /dev/null +++ b/tests/ui/attributes/attr-order-deprecated.stderr @@ -0,0 +1,22 @@ +error: multiple `deprecated` attributes + --> $DIR/attr-order-deprecated.rs:3:1 + | +LL | #[deprecated = "BBB"] + | ^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/attr-order-deprecated.rs:1:1 + | +LL | #[deprecated = "AAA"] + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: use of deprecated function `deprecated`: AAA + --> $DIR/attr-order-deprecated.rs:8:5 + | +LL | deprecated(); + | ^^^^^^^^^^ + | + = note: `#[warn(deprecated)]` on by default + +error: aborting due to 1 previous error; 1 warning emitted + diff --git a/tests/ui/attributes/attr-order-must-use.rs b/tests/ui/attributes/attr-order-must-use.rs new file mode 100644 index 0000000000000..36ffe9d5ed708 --- /dev/null +++ b/tests/ui/attributes/attr-order-must-use.rs @@ -0,0 +1,19 @@ +#![deny(unused)] +//~^ NOTE lint level is defined here + +#[must_use = "AAA"] +//~^ NOTE also specified here +#[must_use = "BBB"] +//~^ ERROR unused attribute +//~| WARN previously accepted +//~| NOTE `#[deny(unused_attributes)]` implied by `#[deny(unused)]` +fn must_use() -> usize { + 0 +} + +fn main() { + must_use(); + //~^ ERROR unused return value of `must_use` that must be used + //~| NOTE AAA + //~| NOTE `#[deny(unused_must_use)]` implied by `#[deny(unused)]` +} diff --git a/tests/ui/attributes/attr-order-must-use.stderr b/tests/ui/attributes/attr-order-must-use.stderr new file mode 100644 index 0000000000000..18b5811623017 --- /dev/null +++ b/tests/ui/attributes/attr-order-must-use.stderr @@ -0,0 +1,34 @@ +error: unused attribute + --> $DIR/attr-order-must-use.rs:6:1 + | +LL | #[must_use = "BBB"] + | ^^^^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/attr-order-must-use.rs:4:1 + | +LL | #[must_use = "AAA"] + | ^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +note: the lint level is defined here + --> $DIR/attr-order-must-use.rs:1:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]` + +error: unused return value of `must_use` that must be used + --> $DIR/attr-order-must-use.rs:15:5 + | +LL | must_use(); + | ^^^^^^^^^^ + | + = note: AAA + = note: `#[deny(unused_must_use)]` implied by `#[deny(unused)]` +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = must_use(); + | +++++++ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/attributes/malformed-no-std.stderr b/tests/ui/attributes/malformed-no-std.stderr index e994e28e030fa..63b6d628970c7 100644 --- a/tests/ui/attributes/malformed-no-std.stderr +++ b/tests/ui/attributes/malformed-no-std.stderr @@ -101,10 +101,10 @@ LL | #![no_std(foo = "bar")] | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/malformed-no-std.rs:5:1 + --> $DIR/malformed-no-std.rs:3:1 | -LL | #![no_std("bar")] - | ^^^^^^^^^^^^^^^^^ +LL | #![no_std = "foo"] + | ^^^^^^^^^^^^^^^^^^ warning: unused attribute --> $DIR/malformed-no-std.rs:13:1 @@ -125,10 +125,10 @@ LL | #![no_core(foo = "bar")] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/malformed-no-std.rs:13:1 + --> $DIR/malformed-no-std.rs:11:1 | -LL | #![no_core("bar")] - | ^^^^^^^^^^^^^^^^^^ +LL | #![no_core = "foo"] + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 8 previous errors; 4 warnings emitted