1
Fork 0

rustc_attr remove ref patterns

...and some if-let-elses too :P
This commit is contained in:
Maybe Waffle 2022-12-06 12:24:57 +00:00
parent c75817fb1b
commit 244990a6e9

View file

@ -277,8 +277,7 @@ where
allowed_through_unstable_modules = true; allowed_through_unstable_modules = true;
} }
// attributes with data // attributes with data
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta { else if let Some(meta @ MetaItem { kind: MetaItemKind::List(metas), .. }) = &meta {
let meta = meta.as_ref().unwrap();
let get = |meta: &MetaItem, item: &mut Option<Symbol>| { let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
if item.is_some() { if item.is_some() {
handle_errors( handle_errors(
@ -533,27 +532,26 @@ where
// Merge the const-unstable info into the stability info // Merge the const-unstable info into the stability info
if promotable { if promotable {
if let Some((ref mut stab, _)) = const_stab { match &mut const_stab {
stab.promotable = promotable; Some((stab, _)) => stab.promotable = promotable,
} else { _ => _ = sess.emit_err(session_diagnostics::RustcPromotablePairing { span: item_sp }),
sess.emit_err(session_diagnostics::RustcPromotablePairing { span: item_sp });
} }
} }
if allowed_through_unstable_modules { if allowed_through_unstable_modules {
if let Some(( match &mut stab {
Some((
Stability { Stability {
level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. }, level: StabilityLevel::Stable { allowed_through_unstable_modules, .. },
.. ..
}, },
_, _,
)) = stab )) => *allowed_through_unstable_modules = true,
{ _ => {
*allowed_through_unstable_modules = true;
} else {
sess.emit_err(session_diagnostics::RustcAllowedUnstablePairing { span: item_sp }); sess.emit_err(session_diagnostics::RustcAllowedUnstablePairing { span: item_sp });
} }
} }
}
(stab, const_stab, body_stab) (stab, const_stab, body_stab)
} }
@ -654,8 +652,8 @@ pub fn eval_condition(
features: Option<&Features>, features: Option<&Features>,
eval: &mut impl FnMut(Condition) -> bool, eval: &mut impl FnMut(Condition) -> bool,
) -> bool { ) -> bool {
match cfg.kind { match &cfg.kind {
ast::MetaItemKind::List(ref mis) if cfg.name_or_empty() == sym::version => { ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
try_gate_cfg(sym::version, cfg.span, sess, features); try_gate_cfg(sym::version, cfg.span, sess, features);
let (min_version, span) = match &mis[..] { let (min_version, span) = match &mis[..] {
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => { [NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
@ -688,7 +686,7 @@ pub fn eval_condition(
rustc_version >= min_version rustc_version >= min_version
} }
} }
ast::MetaItemKind::List(ref mis) => { ast::MetaItemKind::List(mis) => {
for mi in mis.iter() { for mi in mis.iter() {
if !mi.is_meta_item() { if !mi.is_meta_item() {
handle_errors( handle_errors(
@ -759,7 +757,7 @@ pub fn eval_condition(
sess.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span }); sess.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span });
true true
} }
MetaItemKind::NameValue(ref lit) if !lit.kind.is_str() => { MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
handle_errors( handle_errors(
sess, sess,
lit.span, lit.span,
@ -1036,7 +1034,8 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
}); });
} }
} else if let Some(meta_item) = item.meta_item() { } else if let Some(meta_item) = item.meta_item() {
if let MetaItemKind::NameValue(ref value) = meta_item.kind { match &meta_item.kind {
MetaItemKind::NameValue(value) => {
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) { if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
let name = meta_item.name_or_empty().to_ident_string(); let name = meta_item.name_or_empty().to_ident_string();
recognised = true; recognised = true;
@ -1060,7 +1059,8 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
name: meta_item.name_or_empty().to_ident_string(), name: meta_item.name_or_empty().to_ident_string(),
}); });
} }
} else if let MetaItemKind::List(_) = meta_item.kind { }
MetaItemKind::List(_) => {
if meta_item.has_name(sym::align) { if meta_item.has_name(sym::align) {
recognised = true; recognised = true;
sess.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg { sess.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
@ -1068,9 +1068,11 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
}); });
} else if meta_item.has_name(sym::packed) { } else if meta_item.has_name(sym::packed) {
recognised = true; recognised = true;
sess.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg { sess.emit_err(
session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
span: meta_item.span, span: meta_item.span,
}); },
);
} else if matches!( } else if matches!(
meta_item.name_or_empty(), meta_item.name_or_empty(),
sym::C | sym::simd | sym::transparent sym::C | sym::simd | sym::transparent
@ -1083,6 +1085,8 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
}); });
} }
} }
_ => (),
}
} }
if !recognised { if !recognised {
// Not a word we recognize. This will be caught and reported by // Not a word we recognize. This will be caught and reported by