Skip to content

Commit 73a791c

Browse files
Rollup merge of rust-lang#156037 - scrabsha:attributes/expect-no-args, r=JonathanBrouwer
Add AcceptContext::expect_no_args
2 parents 87319ed + f77fc05 commit 73a791c

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
@@ -294,11 +294,9 @@ impl CombineAttributeParser for FeatureParser {
294294
cx.adcx().expected_identifier(elem.span());
295295
continue;
296296
};
297-
if let Err(arg_span) = elem.args().no_args() {
298-
cx.adcx().expected_no_args(arg_span);
297+
let Some(()) = cx.expect_no_args(elem.args()) else {
299298
continue;
300-
}
301-
299+
};
302300
let path = elem.path();
303301
let Some(ident) = path.word() else {
304302
cx.adcx().expected_identifier(path.span());
@@ -340,10 +338,9 @@ impl CombineAttributeParser for RegisterToolParser {
340338
cx.adcx().expected_identifier(elem.span());
341339
continue;
342340
};
343-
if let Err(arg_span) = elem.args().no_args() {
344-
cx.adcx().expected_no_args(arg_span);
341+
let Some(()) = cx.expect_no_args(elem.args()) else {
345342
continue;
346-
}
343+
};
347344

348345
let path = elem.path();
349346
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
@@ -150,7 +150,7 @@ impl DocParser {
150150

151151
match path.word_sym() {
152152
Some(sym::no_crate_inject) => {
153-
if let Err(span) = args.no_args() {
153+
if let Err(span) = args.as_no_args() {
154154
expected_no_args(cx, span);
155155
return;
156156
}
@@ -280,7 +280,7 @@ impl DocParser {
280280
args: &ArgParser,
281281
inline: DocInline,
282282
) {
283-
if let Err(span) = args.no_args() {
283+
if let Err(span) = args.as_no_args() {
284284
expected_no_args(cx, span);
285285
return;
286286
}
@@ -426,7 +426,7 @@ impl DocParser {
426426

427427
macro_rules! no_args {
428428
($ident: ident) => {{
429-
if let Err(span) = args.no_args() {
429+
if let Err(span) = args.as_no_args() {
430430
expected_no_args(cx, span);
431431
return;
432432
}
@@ -445,7 +445,7 @@ impl DocParser {
445445
}
446446
macro_rules! no_args_and_not_crate_level {
447447
($ident: ident) => {{
448-
if let Err(span) = args.no_args() {
448+
if let Err(span) = args.as_no_args() {
449449
expected_no_args(cx, span);
450450
return;
451451
}
@@ -461,7 +461,7 @@ impl DocParser {
461461
no_args_and_crate_level!($ident, |span| {});
462462
}};
463463
($ident: ident, |$span:ident| $extra_validation:block) => {{
464-
if let Err(span) = args.no_args() {
464+
if let Err(span) = args.as_no_args() {
465465
expected_no_args(cx, span);
466466
return;
467467
}

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
@@ -58,7 +58,7 @@ fn parse_derive_like(
5858
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
5959
let Some(list) = args.as_list() else {
6060
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
61-
if args.no_args().is_ok() && !trait_name_mandatory {
61+
if args.as_no_args().is_ok() && !trait_name_mandatory {
6262
return Some((None, ThinVec::new()));
6363
}
6464
let attr_span = cx.attr_span;
@@ -84,10 +84,7 @@ fn parse_derive_like(
8484
cx.adcx().expected_identifier(trait_ident.span);
8585
return None;
8686
}
87-
if let Err(e) = trait_attr.args().no_args() {
88-
cx.adcx().expected_no_args(e);
89-
return None;
90-
};
87+
cx.expect_no_args(trait_attr.args())?;
9188

9289
// Parse optional attributes
9390
let mut attributes = ThinVec::new();
@@ -108,10 +105,7 @@ fn parse_derive_like(
108105
cx.adcx().expected_identifier(attr.span());
109106
return None;
110107
};
111-
if let Err(e) = attr.args().no_args() {
112-
cx.adcx().expected_no_args(e);
113-
return None;
114-
};
108+
cx.expect_no_args(attr.args())?;
115109
let Some(ident) = attr.path().word() else {
116110
cx.adcx().expected_identifier(attr.path().span());
117111
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)