about summary refs log tree commit diff
path: root/tests/ui/attributes
diff options
context:
space:
mode:
authorUrgau <urgau@numericable.fr>2024-09-30 12:13:17 +0200
committerUrgau <urgau@numericable.fr>2024-09-30 12:15:08 +0200
commit9cb540a13cb2249754ea3e755cb1472151d061db (patch)
treea7553337b4ac13f67cf91165e2dea839a2ead4d6 /tests/ui/attributes
parent2da3cb9cab706ff029ee5a40c6dee1c1f188e0bb (diff)
downloadrust-9cb540a13cb2249754ea3e755cb1472151d061db.tar.gz
rust-9cb540a13cb2249754ea3e755cb1472151d061db.zip
Reject leading unsafe in `cfg!(...)` and `--check-cfg`.
Diffstat (limited to 'tests/ui/attributes')
-rw-r--r--tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs6
-rw-r--r--tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr20
2 files changed, 24 insertions, 2 deletions
diff --git a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs
index b561550c198..273b127bf9c 100644
--- a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs
+++ b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs
@@ -27,4 +27,8 @@ mod inner {
 #[unsafe(used)] //~ ERROR: is not an unsafe attribute
 static FOO: usize = 0;
 
-fn main() {}
+fn main() {
+    let _a = cfg!(unsafe(foo));
+    //~^ ERROR: expected identifier, found keyword `unsafe`
+    //~^^ ERROR: invalid predicate `r#unsafe`
+}
diff --git a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr
index 9fb7f062b91..445d239d867 100644
--- a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr
+++ b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr
@@ -22,6 +22,23 @@ LL | #[unsafe(test)]
    |
    = note: extraneous unsafe is not allowed in attributes
 
+error: expected identifier, found keyword `unsafe`
+  --> $DIR/extraneous-unsafe-attributes.rs:31:19
+   |
+LL |     let _a = cfg!(unsafe(foo));
+   |                   ^^^^^^ expected identifier, found keyword
+   |
+help: escape `unsafe` to use it as an identifier
+   |
+LL |     let _a = cfg!(r#unsafe(foo));
+   |                   ++
+
+error[E0537]: invalid predicate `r#unsafe`
+  --> $DIR/extraneous-unsafe-attributes.rs:31:19
+   |
+LL |     let _a = cfg!(unsafe(foo));
+   |                   ^^^^^^^^^^^
+
 error: `ignore` is not an unsafe attribute
   --> $DIR/extraneous-unsafe-attributes.rs:13:3
    |
@@ -62,5 +79,6 @@ LL | #[unsafe(used)]
    |
    = note: extraneous unsafe is not allowed in attributes
 
-error: aborting due to 8 previous errors
+error: aborting due to 10 previous errors
 
+For more information about this error, try `rustc --explain E0537`.