diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-16 17:23:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-16 17:23:07 +0100 |
| commit | 7407c4e37d3342c20835bc2caaff28863078b266 (patch) | |
| tree | 1fecadb33da818198fe0d125d4e1025d4f817c35 /src/test/ui | |
| parent | f8402169aaa12e7bbb9630796a8caec90a3055ca (diff) | |
| parent | 2be94d43019961f855589c1c6e2e27063537d30a (diff) | |
| download | rust-7407c4e37d3342c20835bc2caaff28863078b266.tar.gz rust-7407c4e37d3342c20835bc2caaff28863078b266.zip | |
Rollup merge of #91172 - Ethiraric:ethiraric/fix90979, r=petrochenkov
Warn when a `#[test]`-like built-in attribute macro is present multiple times. Fixes #90979.
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/attributes/duplicated-attributes.rs | 41 | ||||
| -rw-r--r-- | src/test/ui/attributes/duplicated-attributes.stderr | 22 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/test/ui/attributes/duplicated-attributes.rs b/src/test/ui/attributes/duplicated-attributes.rs new file mode 100644 index 00000000000..84a5abcf8b4 --- /dev/null +++ b/src/test/ui/attributes/duplicated-attributes.rs @@ -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() {} diff --git a/src/test/ui/attributes/duplicated-attributes.stderr b/src/test/ui/attributes/duplicated-attributes.stderr new file mode 100644 index 00000000000..735d950b27c --- /dev/null +++ b/src/test/ui/attributes/duplicated-attributes.stderr @@ -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 + |
