Skip to content

Commit f77fc05

Browse files
committed
Add AcceptContext::expect_no_args
1 parent f53b654 commit f77fc05

13 files changed

Lines changed: 36 additions & 56 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/autodiff.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ impl SingleAttributeParser for RustcAutodiffParser {
5252
cx.adcx().expected_identifier(mode.span());
5353
return None;
5454
};
55-
let Ok(()) = mode.args().no_args() else {
56-
cx.adcx().expected_identifier(mode.span());
57-
return None;
58-
};
55+
cx.expect_no_args(mode.args())?;
5956
let Some(mode) = mode.path().word() else {
6057
cx.adcx().expected_identifier(mode.span());
6158
return None;
@@ -85,11 +82,7 @@ impl SingleAttributeParser for RustcAutodiffParser {
8582
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
8683
return None;
8784
};
88-
let Ok(()) = activity.args().no_args() else {
89-
cx.adcx()
90-
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
91-
return None;
92-
};
85+
cx.expect_no_args(activity.args())?;
9386
let Some(activity) = activity.path().word() else {
9487
cx.adcx()
9588
.expected_specific_argument(activity.span(), DiffActivity::all_activities());

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ pub(crate) struct NakedParser {
195195
impl AttributeParser for NakedParser {
196196
const ATTRIBUTES: AcceptMapping<Self> =
197197
&[(&[sym::naked], template!(Word), |this, cx, args| {
198-
if let Err(span) = args.no_args() {
199-
cx.adcx().expected_no_args(span);
198+
let Some(()) = cx.expect_no_args(args) else {
200199
return;
201-
}
200+
};
202201

203202
if let Some(earlier) = this.span {
204203
let span = cx.attr_span;

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,9 @@ impl CombineAttributeParser for FeatureParser {
299299
cx.adcx().expected_identifier(elem.span());
300300
continue;
301301
};
302-
if let Err(arg_span) = elem.args().no_args() {
303-
cx.adcx().expected_no_args(arg_span);
302+
let Some(()) = cx.expect_no_args(elem.args()) else {
304303
continue;
305-
}
306-
304+
};
307305
let path = elem.path();
308306
let Some(ident) = path.word() else {
309307
cx.adcx().expected_identifier(path.span());
@@ -345,10 +343,9 @@ impl CombineAttributeParser for RegisterToolParser {
345343
cx.adcx().expected_identifier(elem.span());
346344
continue;
347345
};
348-
if let Err(arg_span) = elem.args().no_args() {
349-
cx.adcx().expected_no_args(arg_span);
346+
let Some(()) = cx.expect_no_args(elem.args()) else {
350347
continue;
351-
}
348+
};
352349

353350
let path = elem.path();
354351
let Some(ident) = path.word() else {

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl DocParser {
162162

163163
match path.word_sym() {
164164
Some(sym::no_crate_inject) => {
165-
if let Err(span) = args.no_args() {
165+
if let Err(span) = args.as_no_args() {
166166
expected_no_args(cx, span);
167167
return;
168168
}
@@ -295,7 +295,7 @@ impl DocParser {
295295
args: &ArgParser,
296296
inline: DocInline,
297297
) {
298-
if let Err(span) = args.no_args() {
298+
if let Err(span) = args.as_no_args() {
299299
expected_no_args(cx, span);
300300
return;
301301
}
@@ -449,7 +449,7 @@ impl DocParser {
449449

450450
macro_rules! no_args {
451451
($ident: ident) => {{
452-
if let Err(span) = args.no_args() {
452+
if let Err(span) = args.as_no_args() {
453453
expected_no_args(cx, span);
454454
return;
455455
}
@@ -468,7 +468,7 @@ impl DocParser {
468468
}
469469
macro_rules! no_args_and_not_crate_level {
470470
($ident: ident) => {{
471-
if let Err(span) = args.no_args() {
471+
if let Err(span) = args.as_no_args() {
472472
expected_no_args(cx, span);
473473
return;
474474
}
@@ -484,7 +484,7 @@ impl DocParser {
484484
no_args_and_crate_level!($ident, |span| {});
485485
}};
486486
($ident: ident, |$span:ident| $extra_validation:block) => {{
487-
if let Err(span) = args.no_args() {
487+
if let Err(span) = args.as_no_args() {
488488
expected_no_args(cx, span);
489489
return;
490490
}

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ impl AttributeParser for MacroUseParser {
8686
cx.adcx().expected_identifier(item.span());
8787
continue;
8888
};
89-
if let Err(err_span) = item.args().no_args() {
90-
cx.adcx().expected_no_args(err_span);
89+
let Some(()) = cx.expect_no_args(item.args()) else {
9190
continue;
92-
}
91+
};
9392
let Some(item) = item.path().word() else {
9493
cx.adcx().expected_identifier(item.span());
9594
continue;
@@ -179,9 +178,7 @@ impl SingleAttributeParser for CollapseDebugInfoParser {
179178
cx.adcx().expected_not_literal(single.span());
180179
return None;
181180
};
182-
if let Err(err) = mi.args().no_args() {
183-
cx.adcx().expected_no_args(err);
184-
}
181+
let _ = cx.expect_no_args(mi.args());
185182
let path = mi.path().word_sym();
186183
let info = match path {
187184
Some(sym::yes) => CollapseMacroDebuginfo::Yes,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ impl<T: NoArgsAttributeParser> SingleAttributeParser for WithoutArgs<T> {
258258
const TEMPLATE: AttributeTemplate = template!(Word);
259259

260260
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
261-
if let Err(span) = args.no_args() {
262-
cx.adcx().expected_no_args(span);
263-
}
261+
let _ = cx.expect_no_args(args);
264262
Some(T::CREATE(cx.attr_span))
265263
}
266264
}

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn parse_derive_like(
5959
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
6060
let Some(list) = args.as_list() else {
6161
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
62-
if args.no_args().is_ok() && !trait_name_mandatory {
62+
if args.as_no_args().is_ok() && !trait_name_mandatory {
6363
return Some((None, ThinVec::new()));
6464
}
6565
let attr_span = cx.attr_span;
@@ -85,10 +85,7 @@ fn parse_derive_like(
8585
cx.adcx().expected_identifier(trait_ident.span);
8686
return None;
8787
}
88-
if let Err(e) = trait_attr.args().no_args() {
89-
cx.adcx().expected_no_args(e);
90-
return None;
91-
};
88+
cx.expect_no_args(trait_attr.args())?;
9289

9390
// Parse optional attributes
9491
let mut attributes = ThinVec::new();
@@ -109,10 +106,7 @@ fn parse_derive_like(
109106
cx.adcx().expected_identifier(attr.span());
110107
return None;
111108
};
112-
if let Err(e) = attr.args().no_args() {
113-
cx.adcx().expected_no_args(e);
114-
return None;
115-
};
109+
cx.expect_no_args(attr.args())?;
116110
let Some(ident) = attr.path().word() else {
117111
cx.adcx().expected_identifier(attr.path().span());
118112
return None;

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ impl SingleAttributeParser for RustcDumpDefPathParser {
3636
]);
3737
const TEMPLATE: AttributeTemplate = template!(Word);
3838
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
39-
if let Err(span) = args.no_args() {
40-
cx.adcx().expected_no_args(span);
41-
return None;
42-
}
39+
cx.expect_no_args(args)?;
4340
Some(AttributeKind::RustcDumpDefPath(cx.attr_span))
4441
}
4542
}
@@ -203,10 +200,7 @@ impl SingleAttributeParser for RustcDumpSymbolNameParser {
203200
]);
204201
const TEMPLATE: AttributeTemplate = template!(Word);
205202
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
206-
if let Err(span) = args.no_args() {
207-
cx.adcx().expected_no_args(span);
208-
return None;
209-
}
203+
cx.expect_no_args(args)?;
210204
Some(AttributeKind::RustcDumpSymbolName(cx.attr_span))
211205
}
212206
}

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl SingleAttributeParser for RustcScalableVectorParser {
555555
const TEMPLATE: AttributeTemplate = template!(Word, List: &["count"]);
556556

557557
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
558-
if args.no_args().is_ok() {
558+
if args.as_no_args().is_ok() {
559559
return Some(AttributeKind::RustcScalableVector {
560560
element_count: None,
561561
span: cx.attr_span,

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl SingleAttributeParser for IgnoreParser {
3030
ArgParser::List(list) => {
3131
let help =
3232
list.as_single().and_then(|item| item.meta_item()).and_then(|item| {
33-
item.args().no_args().ok()?;
33+
item.args().as_no_args().ok()?;
3434
Some(item.path().to_string())
3535
});
3636
cx.adcx().warn_ill_formed_attribute_input_with_help(

0 commit comments

Comments
 (0)