about summary refs log tree commit diff
path: root/tests/ui/parser/attribute
diff options
context:
space:
mode:
authorsjwang05 <63834813+sjwang05@users.noreply.github.com>2023-12-26 18:34:44 -0800
committersjwang05 <63834813+sjwang05@users.noreply.github.com>2024-01-12 13:59:47 -0800
commitaa8ecd0652afbecd6549d2f6e53c0a5f6aa76d8f (patch)
tree33eac55b0dacdca88146661ac85fe53b386362d7 /tests/ui/parser/attribute
parent6029085a6f7b2a15a43f83bcea730d9786d7d5a1 (diff)
Suggest quoting unquoted idents in attrs
Diffstat (limited to 'tests/ui/parser/attribute')
-rw-r--r--tests/ui/parser/attribute/attr-unquoted-ident.fixed15
-rw-r--r--tests/ui/parser/attribute/attr-unquoted-ident.rs15
-rw-r--r--tests/ui/parser/attribute/attr-unquoted-ident.stderr24
3 files changed, 54 insertions, 0 deletions
diff --git a/tests/ui/parser/attribute/attr-unquoted-ident.fixed b/tests/ui/parser/attribute/attr-unquoted-ident.fixed
new file mode 100644
index 00000000000..6cdf22f7ec0
--- /dev/null
+++ b/tests/ui/parser/attribute/attr-unquoted-ident.fixed
@@ -0,0 +1,15 @@
+// compile-flags: -Zdeduplicate-diagnostics=yes
+// run-rustfix
+
+fn main() {
+    #[cfg(key="foo")]
+    //~^ ERROR expected unsuffixed literal, found `foo`
+    //~| HELP surround the identifier with quotation marks to parse it as a string
+    println!();
+    #[cfg(key="bar")]
+    println!();
+    #[cfg(key="foo bar baz")]
+    //~^ ERROR expected unsuffixed literal, found `foo`
+    //~| HELP surround the identifier with quotation marks to parse it as a string
+    println!();
+}
diff --git a/tests/ui/parser/attribute/attr-unquoted-ident.rs b/tests/ui/parser/attribute/attr-unquoted-ident.rs
new file mode 100644
index 00000000000..75af015c9fe
--- /dev/null
+++ b/tests/ui/parser/attribute/attr-unquoted-ident.rs
@@ -0,0 +1,15 @@
+// compile-flags: -Zdeduplicate-diagnostics=yes
+// run-rustfix
+
+fn main() {
+    #[cfg(key=foo)]
+    //~^ ERROR expected unsuffixed literal, found `foo`
+    //~| HELP surround the identifier with quotation marks to parse it as a string
+    println!();
+    #[cfg(key="bar")]
+    println!();
+    #[cfg(key=foo bar baz)]
+    //~^ ERROR expected unsuffixed literal, found `foo`
+    //~| HELP surround the identifier with quotation marks to parse it as a string
+    println!();
+}
diff --git a/tests/ui/parser/attribute/attr-unquoted-ident.stderr b/tests/ui/parser/attribute/attr-unquoted-ident.stderr
new file mode 100644
index 00000000000..bc028f39be6
--- /dev/null
+++ b/tests/ui/parser/attribute/attr-unquoted-ident.stderr
@@ -0,0 +1,24 @@
+error: expected unsuffixed literal, found `foo`
+  --> $DIR/attr-unquoted-ident.rs:5:15
+   |
+LL |     #[cfg(key=foo)]
+   |               ^^^
+   |
+help: surround the identifier with quotation marks to parse it as a string
+   |
+LL |     #[cfg(key="foo")]
+   |               +   +
+
+error: expected unsuffixed literal, found `foo`
+  --> $DIR/attr-unquoted-ident.rs:11:15
+   |
+LL |     #[cfg(key=foo bar baz)]
+   |               ^^^
+   |
+help: surround the identifier with quotation marks to parse it as a string
+   |
+LL |     #[cfg(key="foo bar baz")]
+   |               +           +
+
+error: aborting due to 2 previous errors
+