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:
Matthias Krüger 2021-12-16 17:23:07 +01:00 committed by GitHub
commit 7407c4e37d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 134 additions and 4 deletions

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

View 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