Skip to content

Commit ee2bc6b

Browse files
Stop using IllFormedAttributeInputLint for must_use
1 parent 5e28944 commit ee2bc6b

File tree

7 files changed

+26
-29
lines changed

7 files changed

+26
-29
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ attr_parsing_expects_feature_list =
5050
attr_parsing_expects_features =
5151
`{$name}` expects feature names
5252
53-
attr_parsing_ill_formed_attribute_input = {$num_suggestions ->
54-
[1] attribute must be of the form {$suggestions}
55-
*[other] valid forms for the attribute are {$suggestions}
56-
}
57-
5853
attr_parsing_import_name_type_raw =
5954
import name type can only be used with link kind `raw-dylib`
6055

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use rustc_errors::DiagArgValue;
2-
31
use super::prelude::*;
4-
use crate::session_diagnostics::IllFormedAttributeInputLint;
52

63
pub(crate) struct MustUseParser;
74

@@ -45,14 +42,7 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
4542
Some(value_str)
4643
}
4744
ArgParser::List(_) => {
48-
let suggestions = cx.suggestions();
49-
cx.emit_err(IllFormedAttributeInputLint {
50-
num_suggestions: suggestions.len(),
51-
suggestions: DiagArgValue::StrListSepByAnd(
52-
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
53-
),
54-
span: cx.attr_span,
55-
});
45+
cx.expected_name_value(cx.attr_span, None);
5646
return None;
5747
}
5848
},

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,6 @@ pub(crate) struct UnusedMultiple {
380380
pub name: Symbol,
381381
}
382382

383-
#[derive(Diagnostic)]
384-
#[diag(attr_parsing_ill_formed_attribute_input)]
385-
pub(crate) struct IllFormedAttributeInputLint {
386-
#[primary_span]
387-
pub span: Span,
388-
pub num_suggestions: usize,
389-
pub suggestions: DiagArgValue,
390-
}
391-
392383
#[derive(Diagnostic)]
393384
#[diag(attr_parsing_null_on_export, code = E0648)]
394385
pub(crate) struct NullOnExport {

tests/ui/attributes/malformed-attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#[cold = 1]
6060
//~^ ERROR malformed
6161
#[must_use()]
62-
//~^ ERROR valid forms for the attribute are
62+
//~^ ERROR malformed
6363
#[no_mangle = 1]
6464
//~^ ERROR malformed
6565
#[unsafe(naked())]

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,21 @@ LL | #[cold = 1]
314314
| | didn't expect any arguments here
315315
| help: must be of the form: `#[cold]`
316316

317-
error: valid forms for the attribute are `#[must_use = "reason"]` and `#[must_use]`
317+
error[E0539]: malformed `must_use` attribute input
318318
--> $DIR/malformed-attrs.rs:61:1
319319
|
320320
LL | #[must_use()]
321321
| ^^^^^^^^^^^^^
322+
|
323+
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute>
324+
help: try changing it to one of the following valid forms of the attribute
325+
|
326+
LL - #[must_use()]
327+
LL + #[must_use = "reason"]
328+
|
329+
LL - #[must_use()]
330+
LL + #[must_use]
331+
|
322332

323333
error[E0565]: malformed `no_mangle` attribute input
324334
--> $DIR/malformed-attrs.rs:63:1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[must_use()] //~ ERROR valid forms for the attribute are `#[must_use = "reason"]` and `#[must_use]`
1+
#[must_use()] //~ ERROR malformed
22
struct Test;
33

44
fn main() {}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
error: valid forms for the attribute are `#[must_use = "reason"]` and `#[must_use]`
1+
error[E0539]: malformed `must_use` attribute input
22
--> $DIR/malformed-must_use.rs:1:1
33
|
44
LL | #[must_use()]
55
| ^^^^^^^^^^^^^
6+
|
7+
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute>
8+
help: try changing it to one of the following valid forms of the attribute
9+
|
10+
LL - #[must_use()]
11+
LL + #[must_use = "reason"]
12+
|
13+
LL - #[must_use()]
14+
LL + #[must_use]
15+
|
616

717
error: aborting due to 1 previous error
818

19+
For more information about this error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)