Skip to content

Commit 3db6951

Browse files
committed
expected word diagnostic test
1 parent d4efab1 commit 3db6951

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<S: Stage> SingleAttributeParser<S> for ColdParser {
4949

5050
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
5151
if !args.no_args() {
52-
cx.expected_no_args(cx.attr_span);
52+
cx.expected_no_args(args.span().unwrap_or(cx.attr_span));
5353
return None;
5454
};
5555

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
234234
})
235235
}
236236

237-
pub(crate) fn expected_no_args(&self, span: Span) -> ErrorGuaranteed {
237+
pub(crate) fn expected_no_args(&self, args_span: Span) -> ErrorGuaranteed {
238238
self.emit_err(AttributeParseError {
239-
span,
239+
span: args_span,
240240
attr_span: self.attr_span,
241241
template: self.template.clone(),
242242
attribute: self.attr_path.clone(),

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ fn emit_malformed_attribute(
291291
| sym::repr
292292
| sym::deprecated
293293
| sym::optimize
294+
| sym::cold
294295
) {
295296
return;
296297
}

tests/ui/attributes/expected-word.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[cold = true]
2+
//~^ ERROR malformed `cold` attribute input [E0565]
3+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0565]: malformed `cold` attribute input
2+
--> $DIR/expected-word.rs:1:1
3+
|
4+
LL | #[cold = true]
5+
| ^^^^^^^------^
6+
| | |
7+
| | didn't expect any arguments here
8+
| help: must be of the form: `#[cold]`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0565`.

0 commit comments

Comments
 (0)