Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ impl SingleAttributeParser for RustcAutodiffParser {
cx.adcx().expected_identifier(mode.span());
return None;
};
let Ok(()) = mode.args().no_args() else {
cx.adcx().expected_identifier(mode.span());
return None;
};
cx.expect_no_args(mode.args())?;
let Some(mode) = mode.path().word() else {
cx.adcx().expected_identifier(mode.span());
return None;
Expand Down Expand Up @@ -85,11 +82,7 @@ impl SingleAttributeParser for RustcAutodiffParser {
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
return None;
};
let Ok(()) = activity.args().no_args() else {
cx.adcx()
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
return None;
};
cx.expect_no_args(activity.args())?;
let Some(activity) = activity.path().word() else {
cx.adcx()
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,9 @@ pub(crate) struct NakedParser {
impl AttributeParser for NakedParser {
const ATTRIBUTES: AcceptMapping<Self> =
&[(&[sym::naked], template!(Word), |this, cx, args| {
if let Err(span) = args.no_args() {
cx.adcx().expected_no_args(span);
let Some(()) = cx.expect_no_args(args) else {
return;
}
};

if let Some(earlier) = this.span {
let span = cx.attr_span;
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,9 @@ impl CombineAttributeParser for FeatureParser {
cx.adcx().expected_identifier(elem.span());
continue;
};
if let Err(arg_span) = elem.args().no_args() {
cx.adcx().expected_no_args(arg_span);
let Some(()) = cx.expect_no_args(elem.args()) else {
continue;
}

};
let path = elem.path();
let Some(ident) = path.word() else {
cx.adcx().expected_identifier(path.span());
Expand Down Expand Up @@ -345,10 +343,9 @@ impl CombineAttributeParser for RegisterToolParser {
cx.adcx().expected_identifier(elem.span());
continue;
};
if let Err(arg_span) = elem.args().no_args() {
cx.adcx().expected_no_args(arg_span);
let Some(()) = cx.expect_no_args(elem.args()) else {
continue;
}
};

let path = elem.path();
let Some(ident) = path.word() else {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl DocParser {

match path.word_sym() {
Some(sym::no_crate_inject) => {
if let Err(span) = args.no_args() {
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
Expand Down Expand Up @@ -295,7 +295,7 @@ impl DocParser {
args: &ArgParser,
inline: DocInline,
) {
if let Err(span) = args.no_args() {
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
Expand Down Expand Up @@ -449,7 +449,7 @@ impl DocParser {

macro_rules! no_args {
($ident: ident) => {{
if let Err(span) = args.no_args() {
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
Expand All @@ -468,7 +468,7 @@ impl DocParser {
}
macro_rules! no_args_and_not_crate_level {
($ident: ident) => {{
if let Err(span) = args.no_args() {
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
Expand All @@ -484,7 +484,7 @@ impl DocParser {
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.no_args() {
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ impl AttributeParser for MacroUseParser {
cx.adcx().expected_identifier(item.span());
continue;
};
if let Err(err_span) = item.args().no_args() {
cx.adcx().expected_no_args(err_span);
let Some(()) = cx.expect_no_args(item.args()) else {
continue;
}
};
let Some(item) = item.path().word() else {
cx.adcx().expected_identifier(item.span());
continue;
Expand Down Expand Up @@ -179,9 +178,7 @@ impl SingleAttributeParser for CollapseDebugInfoParser {
cx.adcx().expected_not_literal(single.span());
return None;
};
if let Err(err) = mi.args().no_args() {
cx.adcx().expected_no_args(err);
}
let _ = cx.expect_no_args(mi.args());
let path = mi.path().word_sym();
let info = match path {
Some(sym::yes) => CollapseMacroDebuginfo::Yes,
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ impl<T: NoArgsAttributeParser> SingleAttributeParser for WithoutArgs<T> {
const TEMPLATE: AttributeTemplate = template!(Word);

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
if let Err(span) = args.no_args() {
cx.adcx().expected_no_args(span);
}
let _ = cx.expect_no_args(args);
Some(T::CREATE(cx.attr_span))
}
}
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn parse_derive_like(
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
let Some(list) = args.as_list() else {
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
if args.no_args().is_ok() && !trait_name_mandatory {
if args.as_no_args().is_ok() && !trait_name_mandatory {
return Some((None, ThinVec::new()));
}
let attr_span = cx.attr_span;
Expand All @@ -85,10 +85,7 @@ fn parse_derive_like(
cx.adcx().expected_identifier(trait_ident.span);
return None;
}
if let Err(e) = trait_attr.args().no_args() {
cx.adcx().expected_no_args(e);
return None;
};
cx.expect_no_args(trait_attr.args())?;

// Parse optional attributes
let mut attributes = ThinVec::new();
Expand All @@ -109,10 +106,7 @@ fn parse_derive_like(
cx.adcx().expected_identifier(attr.span());
return None;
};
if let Err(e) = attr.args().no_args() {
cx.adcx().expected_no_args(e);
return None;
};
cx.expect_no_args(attr.args())?;
let Some(ident) = attr.path().word() else {
cx.adcx().expected_identifier(attr.path().span());
return None;
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ impl SingleAttributeParser for RustcDumpDefPathParser {
]);
const TEMPLATE: AttributeTemplate = template!(Word);
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
if let Err(span) = args.no_args() {
cx.adcx().expected_no_args(span);
return None;
}
cx.expect_no_args(args)?;
Some(AttributeKind::RustcDumpDefPath(cx.attr_span))
}
}
Expand Down Expand Up @@ -203,10 +200,7 @@ impl SingleAttributeParser for RustcDumpSymbolNameParser {
]);
const TEMPLATE: AttributeTemplate = template!(Word);
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
if let Err(span) = args.no_args() {
cx.adcx().expected_no_args(span);
return None;
}
cx.expect_no_args(args)?;
Some(AttributeKind::RustcDumpSymbolName(cx.attr_span))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl SingleAttributeParser for RustcScalableVectorParser {
const TEMPLATE: AttributeTemplate = template!(Word, List: &["count"]);

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
if args.no_args().is_ok() {
if args.as_no_args().is_ok() {
return Some(AttributeKind::RustcScalableVector {
element_count: None,
span: cx.attr_span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl SingleAttributeParser for IgnoreParser {
ArgParser::List(list) => {
let help =
list.as_single().and_then(|item| item.meta_item()).and_then(|item| {
item.args().no_args().ok()?;
item.args().as_no_args().ok()?;
Some(item.path().to_string())
});
cx.adcx().warn_ill_formed_attribute_input_with_help(
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_attr_parsing/src/attributes/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ impl SingleAttributeParser for RustcSkipDuringMethodDispatchParser {
cx.adcx().expected_not_literal(arg.span());
continue;
};
if let Err(span) = arg.args().no_args() {
cx.adcx().expected_no_args(span);
}
let _ = cx.expect_no_args(arg.args());
let path = arg.path();
let (key, skip): (Symbol, &mut bool) = match path.word_sym() {
Some(key @ sym::array) => (key, &mut array),
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
{
arg.expect_name_value(self, span, name)
}

/// Assert that an [`ArgParser`] has no args, or emits an error and return `None`.
pub(crate) fn expect_no_args<'arg>(&mut self, arg: &'arg ArgParser) -> Option<()> {
if let Err(span) = arg.as_no_args() {
self.adcx().expected_no_args(span);
return None;
}

Some(())
}
}

pub(crate) trait ExpectNameValue {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl ArgParser {
/// Assert that there were no args.
/// If there were, get a span to the arguments
/// (to pass to [`AttributeDiagnosticContext::expected_no_args`](crate::context::AttributeDiagnosticContext::expected_no_args)).
pub fn no_args(&self) -> Result<(), Span> {
pub fn as_no_args(&self) -> Result<(), Span> {
match self {
Self::NoArgs => Ok(()),
Self::List(args) => Err(args.span),
Expand Down
Loading