Skip to content

Commit

Permalink
Inline and remove check_builtin_attribute.
Browse files Browse the repository at this point in the history
It's small and has a single call site.

Also change the second `parse_meta` call to use a simple `match`, like
the first `parse_meta` call, instead of a confusing `map_err`+`ok`
combination.
  • Loading branch information
nnethercote committed Jun 5, 2024
1 parent 13f2bc9 commit 4c731c2
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
match attr_info {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => {
check_builtin_attribute(psess, attr, *name, *template)
match parse_meta(psess, attr) {
Ok(meta) => check_builtin_meta_item(psess, &meta, attr.style, *name, *template),
Err(err) => {
err.emit();
}
}
}
_ if let AttrArgs::Eq(..) = attr.get_normal_item().args => {
// All key-value attributes are restricted to meta-item syntax.
parse_meta(psess, attr)
.map_err(|err| {
match parse_meta(psess, attr) {
Ok(_) => {}
Err(err) => {
err.emit();
})
.ok();
}
}
}
_ => {}
}
Expand Down Expand Up @@ -133,20 +139,6 @@ fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaIte
}
}

fn check_builtin_attribute(
psess: &ParseSess,
attr: &Attribute,
name: Symbol,
template: AttributeTemplate,
) {
match parse_meta(psess, attr) {
Ok(meta) => check_builtin_meta_item(psess, &meta, attr.style, name, template),
Err(err) => {
err.emit();
}
}
}

pub fn check_builtin_meta_item(
psess: &ParseSess,
meta: &MetaItem,
Expand Down

0 comments on commit 4c731c2

Please sign in to comment.