Skip to content

Commit 362e0f9

Browse files
committed
special case expected_single_argument when no argument is provided
1 parent 4c42051 commit 362e0f9

26 files changed

Lines changed: 57 additions & 38 deletions

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn parse_cfg<S: Stage>(
7878
}
7979
}
8080

81-
adcx.expected_single_argument(list.span);
81+
adcx.expected_single_argument(list.span, list.len());
8282
return None;
8383
};
8484
parse_cfg_entry(cx, single).ok()
@@ -93,7 +93,7 @@ pub fn parse_cfg_entry<S: Stage>(
9393
ArgParser::List(list) => match meta.path().word_sym() {
9494
Some(sym::not) => {
9595
let Some(single) = list.single() else {
96-
return Err(cx.adcx().expected_single_argument(list.span));
96+
return Err(cx.adcx().expected_single_argument(list.span, list.len()));
9797
};
9898
CfgEntry::Not(Box::new(parse_cfg_entry(cx, single)?), list.span)
9999
}

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
3030
};
3131

3232
let Some(single) = list.single() else {
33-
cx.adcx().expected_single_argument(list.span);
33+
cx.adcx().expected_single_argument(list.span, list.len());
3434
return None;
3535
};
3636

@@ -91,7 +91,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
9191
};
9292

9393
let Some(arg) = args.single() else {
94-
cx.adcx().expected_single_argument(args.span);
94+
cx.adcx().expected_single_argument(args.span, args.len());
9595
return None;
9696
};
9797

@@ -394,7 +394,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
394394
ArgParser::NoArgs => UsedBy::Default,
395395
ArgParser::List(list) => {
396396
let Some(l) = list.single() else {
397-
cx.adcx().expected_single_argument(list.span);
397+
cx.adcx().expected_single_argument(list.span, list.len());
398398
return;
399399
};
400400

compiler/rustc_attr_parsing/src/attributes/debugger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<S: Stage> CombineAttributeParser<S> for DebuggerViualizerParser {
2626
return None;
2727
};
2828
let Some(single) = l.single() else {
29-
cx.adcx().expected_single_argument(l.span);
29+
cx.adcx().expected_single_argument(l.span, l.len());
3030
return None;
3131
};
3232
let Some(mi) = single.meta_item() else {

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
3838
ArgParser::NoArgs => Some(AttributeKind::Inline(InlineAttr::Hint, cx.attr_span)),
3939
ArgParser::List(list) => {
4040
let Some(l) = list.single() else {
41-
cx.adcx().expected_single_argument(list.span);
41+
cx.adcx().expected_single_argument(list.span, list.len());
4242
return None;
4343
};
4444

@@ -80,7 +80,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
8080
ArgParser::NoArgs => None,
8181
ArgParser::List(list) => {
8282
let Some(l) = list.single() else {
83-
cx.adcx().expected_single_argument(list.span);
83+
cx.adcx().expected_single_argument(list.span, list.len());
8484
return None;
8585
};
8686

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl LinkParser {
393393
return true;
394394
};
395395
let Some(link_cfg) = link_cfg.single() else {
396-
cx.adcx().expected_single_argument(item.span());
396+
cx.adcx().expected_single_argument(item.span(), link_cfg.len());
397397
return true;
398398
};
399399
if !features.link_cfg() {

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
181181
return None;
182182
};
183183
let Some(single) = list.single() else {
184-
cx.adcx().expected_single_argument(list.span);
184+
cx.adcx().expected_single_argument(list.span, list.len());
185185
return None;
186186
};
187187
let Some(mi) = single.meta_item() else {

compiler/rustc_attr_parsing/src/attributes/prototype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn extract_value<S: Stage>(
8282
}
8383

8484
let Some(val) = arg.name_value() else {
85-
cx.adcx().expected_single_argument(arg.span().unwrap_or(span));
85+
cx.adcx().expected_single_argument(arg.span().unwrap_or(span), 2);
8686
*failed = true;
8787
return;
8888
};

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl RustcAlignParser {
297297
}
298298
ArgParser::List(list) => {
299299
let Some(align) = list.single() else {
300-
cx.adcx().expected_single_argument(list.span);
300+
cx.adcx().expected_single_argument(list.span, list.len());
301301
return;
302302
};
303303

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLintOptDenyFieldAccessParser {
197197
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
198198
let Some(arg) = args.list().and_then(MetaItemListParser::single) else {
199199
let attr_span = cx.attr_span;
200-
cx.adcx().expected_single_argument(attr_span);
200+
cx.adcx().expected_single_argument(attr_span, 2);
201201
return None;
202202
};
203203

@@ -382,7 +382,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcDeprecatedSafe2024Parser {
382382
};
383383

384384
let Some(single) = args.single() else {
385-
cx.adcx().expected_single_argument(args.span);
385+
cx.adcx().expected_single_argument(args.span, args.len());
386386
return None;
387387
};
388388

@@ -1022,7 +1022,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcIfThisChangedParser {
10221022
ArgParser::List(list) => {
10231023
let Some(item) = list.single() else {
10241024
let attr_span = cx.attr_span;
1025-
cx.adcx().expected_single_argument(attr_span);
1025+
cx.adcx().expected_single_argument(attr_span, list.len());
10261026
return None;
10271027
};
10281028
let Some(ident) = item.meta_item().and_then(|item| item.ident()) else {
@@ -1084,7 +1084,7 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
10841084
}
10851085
let Some(item) = args.list().and_then(|l| l.single()) else {
10861086
let inner_span = cx.inner_span;
1087-
cx.adcx().expected_single_argument(inner_span);
1087+
cx.adcx().expected_single_argument(inner_span, 2);
10881088
return None;
10891089
};
10901090
let Some(ident) = item.meta_item().and_then(|item| item.ident()) else {

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser {
7272
}
7373
ArgParser::List(list) => {
7474
let Some(single) = list.single() else {
75-
cx.adcx().expected_single_argument(list.span);
75+
cx.adcx().expected_single_argument(list.span, list.len());
7676
return None;
7777
};
7878
let Some(single) = single.meta_item() else {
@@ -150,7 +150,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcAbiParser {
150150

151151
let Some(arg) = args.single() else {
152152
let attr_span = cx.attr_span;
153-
cx.adcx().expected_single_argument(attr_span);
153+
cx.adcx().expected_single_argument(attr_span, args.len());
154154
return None;
155155
};
156156

@@ -215,7 +215,7 @@ impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
215215
};
216216

217217
let Some(single) = list.single() else {
218-
cx.adcx().expected_single_argument(list.span);
218+
cx.adcx().expected_single_argument(list.span, list.len());
219219
return None;
220220
};
221221

0 commit comments

Comments
 (0)