Rollup merge of #91172 - Ethiraric:ethiraric/fix90979, r=petrochenkov
Warn when a `#[test]`-like built-in attribute macro is present multiple times. Fixes #90979.
This commit is contained in:
commit
7407c4e37d
8 changed files with 134 additions and 4 deletions
41
src/test/ui/attributes/duplicated-attributes.rs
Normal file
41
src/test/ui/attributes/duplicated-attributes.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Test that, if an item is annotated with a builtin attribute more than once, a warning is
|
||||
// emitted.
|
||||
// Tests https://github.com/rust-lang/rust/issues/90979
|
||||
|
||||
// check-pass
|
||||
// compile-flags: --test
|
||||
|
||||
#![feature(test)]
|
||||
#![feature(cfg_eval)]
|
||||
|
||||
#[test]
|
||||
#[test]
|
||||
//~^ WARNING duplicated attribute
|
||||
fn f() {}
|
||||
|
||||
// The following shouldn't trigger an error. The attribute is not duplicated.
|
||||
#[test]
|
||||
fn f2() {}
|
||||
|
||||
// The following shouldn't trigger an error either. The second attribute is not #[test].
|
||||
#[test]
|
||||
#[inline]
|
||||
fn f3() {}
|
||||
|
||||
extern crate test;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
#[bench]
|
||||
//~^ WARNING duplicated attribute
|
||||
fn f4(_: &mut Bencher) {}
|
||||
|
||||
#[cfg_eval]
|
||||
#[cfg_eval]
|
||||
//~^ WARNING duplicated attribute
|
||||
struct S;
|
||||
|
||||
#[cfg_eval]
|
||||
struct S2;
|
||||
|
||||
fn main() {}
|
||||
22
src/test/ui/attributes/duplicated-attributes.stderr
Normal file
22
src/test/ui/attributes/duplicated-attributes.stderr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
warning: duplicated attribute
|
||||
--> $DIR/duplicated-attributes.rs:12:1
|
||||
|
|
||||
LL | #[test]
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `#[warn(duplicate_macro_attributes)]` on by default
|
||||
|
||||
warning: duplicated attribute
|
||||
--> $DIR/duplicated-attributes.rs:29:1
|
||||
|
|
||||
LL | #[bench]
|
||||
| ^^^^^^^^
|
||||
|
||||
warning: duplicated attribute
|
||||
--> $DIR/duplicated-attributes.rs:34:1
|
||||
|
|
||||
LL | #[cfg_eval]
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
warning: 3 warnings emitted
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue