From 712106b1229f48e71a6365f5e5bf171403105750 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 23 Oct 2023 16:34:33 +0000 Subject: [PATCH] Add regression test for #117058 --- .../statement-attribute-validation.rs | 39 +++++++++++++ .../statement-attribute-validation.stderr | 56 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/ui/attributes/statement-attribute-validation.rs create mode 100644 tests/ui/attributes/statement-attribute-validation.stderr diff --git a/tests/ui/attributes/statement-attribute-validation.rs b/tests/ui/attributes/statement-attribute-validation.rs new file mode 100644 index 00000000000..31407364acf --- /dev/null +++ b/tests/ui/attributes/statement-attribute-validation.rs @@ -0,0 +1,39 @@ +// test for #117058 - check that attributes are validated on various kinds of statements. + +struct A; + +fn func() {} + +fn main() { + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + if true { + } else { + } + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + (1); + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + match 1 { + _ => {} + } + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + while false {} + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + {} + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + A {}; + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + func(); + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + A; + #[allow(two-words)] + //~^ ERROR expected one of `(`, `,`, `::`, or `=`, found `-` + loop {} +} diff --git a/tests/ui/attributes/statement-attribute-validation.stderr b/tests/ui/attributes/statement-attribute-validation.stderr new file mode 100644 index 00000000000..06f447be562 --- /dev/null +++ b/tests/ui/attributes/statement-attribute-validation.stderr @@ -0,0 +1,56 @@ +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:8:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:13:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:16:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:21:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:24:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:27:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:30:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:33:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: expected one of `(`, `,`, `::`, or `=`, found `-` + --> $DIR/statement-attribute-validation.rs:36:16 + | +LL | #[allow(two-words)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error: aborting due to 9 previous errors +