about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJana Dönszelmann <jana@donsz.nl>2025-06-12 14:24:40 +0200
committerJana Dönszelmann <jana@donsz.nl>2025-06-20 15:06:29 +0200
commitb9107a83a1ace3f292641977df70e9610e0e4482 (patch)
tree57751c9ed9d6a7b125a4ab2fe2f506fbe45f3d62
parentde0fd27f347c783b45fc9764baa944455369cd33 (diff)
downloadrust-b9107a83a1ace3f292641977df70e9610e0e4482.tar.gz
rust-b9107a83a1ace3f292641977df70e9610e0e4482.zip
expected word diagnostic test
-rw-r--r--compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs2
-rw-r--r--compiler/rustc_attr_parsing/src/context.rs4
-rw-r--r--compiler/rustc_parse/src/validate_attr.rs1
-rw-r--r--src/rustdoc-json-types/lib.rs4
-rw-r--r--tests/ui/attributes/expected-word.rs3
-rw-r--r--tests/ui/attributes/expected-word.stderr12
6 files changed, 21 insertions, 5 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
index 1509531ca98..1b03525a5ce 100644
--- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
+++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
@@ -49,7 +49,7 @@ impl<S: Stage> SingleAttributeParser<S> for ColdParser {
 
     fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
         if !args.no_args() {
-            cx.expected_no_args(cx.attr_span);
+            cx.expected_no_args(args.span().unwrap_or(cx.attr_span));
             return None;
         };
 
diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs
index e8bcf57e109..648bd431898 100644
--- a/compiler/rustc_attr_parsing/src/context.rs
+++ b/compiler/rustc_attr_parsing/src/context.rs
@@ -235,9 +235,9 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
         })
     }
 
-    pub(crate) fn expected_no_args(&self, span: Span) -> ErrorGuaranteed {
+    pub(crate) fn expected_no_args(&self, args_span: Span) -> ErrorGuaranteed {
         self.emit_err(AttributeParseError {
-            span,
+            span: args_span,
             attr_span: self.attr_span,
             template: self.template.clone(),
             attribute: self.attr_path.clone(),
diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs
index 646e996ff30..ed1737bee33 100644
--- a/compiler/rustc_parse/src/validate_attr.rs
+++ b/compiler/rustc_parse/src/validate_attr.rs
@@ -292,6 +292,7 @@ fn emit_malformed_attribute(
             | sym::align
             | sym::deprecated
             | sym::optimize
+            | sym::cold
     ) {
         return;
     }
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs
index d5de43feb58..4d25124f9f2 100644
--- a/src/rustdoc-json-types/lib.rs
+++ b/src/rustdoc-json-types/lib.rs
@@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
 // will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
 // are deliberately not in a doc comment, because they need not be in public docs.)
 //
-// Latest feature: Pretty printing of optimize attributes changed
-pub const FORMAT_VERSION: u32 = 49;
+// Latest feature: Pretty printing of cold attributes changed
+pub const FORMAT_VERSION: u32 = 50;
 
 /// The root of the emitted JSON blob.
 ///
diff --git a/tests/ui/attributes/expected-word.rs b/tests/ui/attributes/expected-word.rs
new file mode 100644
index 00000000000..246aa78db82
--- /dev/null
+++ b/tests/ui/attributes/expected-word.rs
@@ -0,0 +1,3 @@
+#[cold = true]
+//~^ ERROR malformed `cold` attribute input [E0565]
+fn main() {}
diff --git a/tests/ui/attributes/expected-word.stderr b/tests/ui/attributes/expected-word.stderr
new file mode 100644
index 00000000000..dcb10e7aee8
--- /dev/null
+++ b/tests/ui/attributes/expected-word.stderr
@@ -0,0 +1,12 @@
+error[E0565]: malformed `cold` attribute input
+  --> $DIR/expected-word.rs:1:1
+   |
+LL | #[cold = true]
+   | ^^^^^^^------^
+   | |      |
+   | |      didn't expect any arguments here
+   | help: must be of the form: `#[cold]`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0565`.