Skip to content

Commit c2ee29d

Browse files
authored
Rollup merge of rust-lang#149949 - JonathanBrouwer:error_cleanup, r=jdonszelmann
Cleanup of attribute parsing errors Removes the specific `UnknownMetaItem` and `IllFormedAttributeInputLint` errors. Note that `IllFormedAttributeInputLint` is not a lint, contrary to its name r? ```@jdonszelmann```
2 parents a3c631d + ae39d3d commit c2ee29d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+288
-308
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 0 additions & 9 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
@@ -213,10 +208,6 @@ attr_parsing_stability_outside_std = stability attributes may not be used outsid
213208
attr_parsing_suffixed_literal_in_attribute = suffixed literals are not allowed in attributes
214209
.help = instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
215210
216-
attr_parsing_unknown_meta_item =
217-
unknown meta item '{$item}'
218-
.label = expected one of {$expected}
219-
220211
attr_parsing_unknown_version_literal =
221212
unknown version literal format, assuming it refers to a future version
222213

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn parse_cfg<S: Stage>(
4242
args: &ArgParser,
4343
) -> Option<CfgEntry> {
4444
let ArgParser::List(list) = args else {
45-
cx.expected_list(cx.attr_span);
45+
cx.expected_list(cx.attr_span, args);
4646
return None;
4747
};
4848
let Some(single) = list.single() else {

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
2525

2626
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
2727
let Some(list) = args.list() else {
28-
cx.expected_list(cx.attr_span);
28+
cx.expected_list(cx.attr_span, args);
2929
return None;
3030
};
3131

@@ -478,7 +478,7 @@ fn parse_tf_attribute<S: Stage>(
478478
) -> impl IntoIterator<Item = (Symbol, Span)> {
479479
let mut features = Vec::new();
480480
let ArgParser::List(list) = args else {
481-
cx.expected_list(cx.attr_span);
481+
cx.expected_list(cx.attr_span, args);
482482
return features;
483483
};
484484
if list.is_empty() {
@@ -601,7 +601,7 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
601601

602602
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
603603
let Some(list) = args.list() else {
604-
cx.expected_list(cx.attr_span);
604+
cx.expected_list(cx.attr_span, args);
605605
return None;
606606
};
607607

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
1313
template!(List: &[r#""name1", "name2", ..."#]),
1414
|this, cx, args| {
1515
let Some(list) = args.list() else {
16-
cx.expected_list(cx.attr_span);
16+
cx.expected_list(cx.attr_span, args);
1717
return;
1818
};
1919

compiler/rustc_attr_parsing/src/attributes/debugger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<S: Stage> CombineAttributeParser<S> for DebuggerViualizerParser {
2121
args: &ArgParser,
2222
) -> impl IntoIterator<Item = Self::Item> {
2323
let Some(l) = args.list() else {
24-
cx.expected_list(args.span().unwrap_or(cx.attr_span));
24+
cx.expected_list(cx.attr_span, args);
2525
return None;
2626
};
2727
let Some(single) = l.single() else {

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,12 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
110110
Some(get(cx, name, param.span(), param.args(), &suggestion)?);
111111
}
112112
_ => {
113-
cx.unknown_key(
113+
cx.expected_specific_argument(
114114
param.span(),
115-
param.path().to_string(),
116115
if features.deprecated_suggestion() {
117-
&["since", "note", "suggestion"]
116+
&[sym::since, sym::note, sym::suggestion]
118117
} else {
119-
&["since", "note"]
118+
&[sym::since, sym::note]
120119
},
121120
);
122121
return None;

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl DocParser {
106106
}
107107
Some(sym::attr) => {
108108
let Some(list) = args.list() else {
109-
cx.expected_list(cx.attr_span);
109+
cx.expected_list(cx.attr_span, args);
110110
return;
111111
};
112112

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
7676
return None;
7777
}
7878
_ => {
79-
cx.expected_list(cx.attr_span);
79+
cx.expected_list(cx.attr_span, args);
8080
return None;
8181
}
8282
};
@@ -379,7 +379,7 @@ impl LinkParser {
379379
return true;
380380
}
381381
let Some(link_cfg) = item.args().list() else {
382-
cx.expected_list(item.span());
382+
cx.expected_list(item.span(), item.args());
383383
return true;
384384
};
385385
let Some(link_cfg) = link_cfg.single() else {

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use rustc_errors::DiagArgValue;
21
use rustc_hir::attrs::MacroUseArgs;
32
use rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS;
43

54
use super::prelude::*;
6-
use crate::session_diagnostics::IllFormedAttributeInputLint;
75

86
pub(crate) struct MacroEscapeParser;
97
impl<S: Stage> NoArgsAttributeParser<S> for MacroEscapeParser {
@@ -101,15 +99,8 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
10199
}
102100
}
103101
}
104-
ArgParser::NameValue(_) => {
105-
let suggestions = cx.suggestions();
106-
cx.emit_err(IllFormedAttributeInputLint {
107-
num_suggestions: suggestions.len(),
108-
suggestions: DiagArgValue::StrListSepByAnd(
109-
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
110-
),
111-
span,
112-
});
102+
ArgParser::NameValue(nv) => {
103+
cx.expected_list_or_no_args(nv.args_span());
113104
}
114105
}
115106
},
@@ -164,16 +155,8 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
164155
}
165156
}
166157
}
167-
ArgParser::NameValue(_) => {
168-
let span = cx.attr_span;
169-
let suggestions = cx.suggestions();
170-
cx.emit_err(IllFormedAttributeInputLint {
171-
num_suggestions: suggestions.len(),
172-
suggestions: DiagArgValue::StrListSepByAnd(
173-
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
174-
),
175-
span,
176-
});
158+
ArgParser::NameValue(nv) => {
159+
cx.expected_list_or_no_args(nv.args_span());
177160
return None;
178161
}
179162
};

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 2 additions & 12 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

@@ -44,15 +41,8 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
4441
};
4542
Some(value_str)
4643
}
47-
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-
});
44+
ArgParser::List(list) => {
45+
cx.expected_nv_or_no_args(list.span);
5646
return None;
5747
}
5848
},

0 commit comments

Comments
 (0)