about summary refs log tree commit diff
path: root/tests/ui/resolve/attr-macros-positional-rejection.rs
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-12-17 19:40:31 +0800
committer许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-12-17 19:57:42 +0800
commit836a0e00e5d29b845748cf42713445076418473b (patch)
tree776ad47e0896dca3611c09ded944ed787c0f8c0e /tests/ui/resolve/attr-macros-positional-rejection.rs
parent7424b898e94b019b49e0854ec061abfdc071e61e (diff)
downloadrust-836a0e00e5d29b845748cf42713445076418473b.tar.gz
rust-836a0e00e5d29b845748cf42713445076418473b.zip
Adjust `tests/ui/attrs-resolution-errors.rs`
- Move `tests/ui/attrs-resolution-errors.rs` to `tests/ui/resolve/`.
- Document test intent.
- Rename test to `attr-macros-positional-rejection.rs` to better reflect
  test intent.
Diffstat (limited to 'tests/ui/resolve/attr-macros-positional-rejection.rs')
-rw-r--r--tests/ui/resolve/attr-macros-positional-rejection.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/ui/resolve/attr-macros-positional-rejection.rs b/tests/ui/resolve/attr-macros-positional-rejection.rs
new file mode 100644
index 00000000000..11382ff1399
--- /dev/null
+++ b/tests/ui/resolve/attr-macros-positional-rejection.rs
@@ -0,0 +1,49 @@
+//! Check that certain positions (listed below) only permit *non-macro* attributes and reject
+//! attribute macros:
+//!
+//! - Enum variants
+//! - Struct fields
+//! - Field in a struct pattern
+//! - Match arm
+//! - Field in struct initialization expression
+
+enum FooEnum {
+    #[test]
+    //~^ ERROR expected non-macro attribute, found attribute macro
+    Bar(i32),
+}
+
+struct FooStruct {
+    #[test]
+    //~^ ERROR expected non-macro attribute, found attribute macro
+    bar: i32,
+}
+
+fn main() {
+    let foo_enum_bar = FooEnum::Bar(1);
+    match foo_enum_bar {
+        FooEnum::Bar(x) => {},
+        _ => {}
+    }
+
+    let foo_struct = FooStruct { bar: 1 };
+    match foo_struct {
+        FooStruct {
+            #[test] bar
+            //~^ ERROR expected non-macro attribute, found attribute macro
+        } => {}
+    }
+
+    match 1 {
+        0 => {}
+        #[test]
+        //~^ ERROR expected non-macro attribute, found attribute macro
+        _ => {}
+    }
+
+    let _another_foo_struct = FooStruct {
+        #[test]
+        //~^ ERROR expected non-macro attribute, found attribute macro
+        bar: 1,
+    };
+}