Skip to content

Commit 244990a

Browse files
committed
rustc_attr remove ref patterns
...and some if-let-elses too :P
1 parent c75817f commit 244990a

File tree

1 file changed

+69
-65
lines changed

1 file changed

+69
-65
lines changed

compiler/rustc_attr/src/builtin.rs

+69-65
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ where
277277
allowed_through_unstable_modules = true;
278278
}
279279
// attributes with data
280-
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
281-
let meta = meta.as_ref().unwrap();
280+
else if let Some(meta @ MetaItem { kind: MetaItemKind::List(metas), .. }) = &meta {
282281
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
283282
if item.is_some() {
284283
handle_errors(
@@ -533,25 +532,24 @@ where
533532

534533
// Merge the const-unstable info into the stability info
535534
if promotable {
536-
if let Some((ref mut stab, _)) = const_stab {
537-
stab.promotable = promotable;
538-
} else {
539-
sess.emit_err(session_diagnostics::RustcPromotablePairing { span: item_sp });
535+
match &mut const_stab {
536+
Some((stab, _)) => stab.promotable = promotable,
537+
_ => _ = sess.emit_err(session_diagnostics::RustcPromotablePairing { span: item_sp }),
540538
}
541539
}
542540

543541
if allowed_through_unstable_modules {
544-
if let Some((
545-
Stability {
546-
level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. },
547-
..
548-
},
549-
_,
550-
)) = stab
551-
{
552-
*allowed_through_unstable_modules = true;
553-
} else {
554-
sess.emit_err(session_diagnostics::RustcAllowedUnstablePairing { span: item_sp });
542+
match &mut stab {
543+
Some((
544+
Stability {
545+
level: StabilityLevel::Stable { allowed_through_unstable_modules, .. },
546+
..
547+
},
548+
_,
549+
)) => *allowed_through_unstable_modules = true,
550+
_ => {
551+
sess.emit_err(session_diagnostics::RustcAllowedUnstablePairing { span: item_sp });
552+
}
555553
}
556554
}
557555

@@ -654,8 +652,8 @@ pub fn eval_condition(
654652
features: Option<&Features>,
655653
eval: &mut impl FnMut(Condition) -> bool,
656654
) -> bool {
657-
match cfg.kind {
658-
ast::MetaItemKind::List(ref mis) if cfg.name_or_empty() == sym::version => {
655+
match &cfg.kind {
656+
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
659657
try_gate_cfg(sym::version, cfg.span, sess, features);
660658
let (min_version, span) = match &mis[..] {
661659
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
@@ -688,7 +686,7 @@ pub fn eval_condition(
688686
rustc_version >= min_version
689687
}
690688
}
691-
ast::MetaItemKind::List(ref mis) => {
689+
ast::MetaItemKind::List(mis) => {
692690
for mi in mis.iter() {
693691
if !mi.is_meta_item() {
694692
handle_errors(
@@ -759,7 +757,7 @@ pub fn eval_condition(
759757
sess.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span });
760758
true
761759
}
762-
MetaItemKind::NameValue(ref lit) if !lit.kind.is_str() => {
760+
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
763761
handle_errors(
764762
sess,
765763
lit.span,
@@ -1036,52 +1034,58 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10361034
});
10371035
}
10381036
} else if let Some(meta_item) = item.meta_item() {
1039-
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
1040-
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
1041-
let name = meta_item.name_or_empty().to_ident_string();
1042-
recognised = true;
1043-
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
1044-
span: item.span(),
1045-
repr_arg: &name,
1046-
cause: IncorrectReprFormatGenericCause::from_lit_kind(
1047-
item.span(),
1048-
&value.kind,
1049-
&name,
1050-
),
1051-
});
1052-
} else if matches!(
1053-
meta_item.name_or_empty(),
1054-
sym::C | sym::simd | sym::transparent
1055-
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1056-
{
1057-
recognised = true;
1058-
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1059-
span: meta_item.span,
1060-
name: meta_item.name_or_empty().to_ident_string(),
1061-
});
1037+
match &meta_item.kind {
1038+
MetaItemKind::NameValue(value) => {
1039+
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
1040+
let name = meta_item.name_or_empty().to_ident_string();
1041+
recognised = true;
1042+
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
1043+
span: item.span(),
1044+
repr_arg: &name,
1045+
cause: IncorrectReprFormatGenericCause::from_lit_kind(
1046+
item.span(),
1047+
&value.kind,
1048+
&name,
1049+
),
1050+
});
1051+
} else if matches!(
1052+
meta_item.name_or_empty(),
1053+
sym::C | sym::simd | sym::transparent
1054+
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1055+
{
1056+
recognised = true;
1057+
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1058+
span: meta_item.span,
1059+
name: meta_item.name_or_empty().to_ident_string(),
1060+
});
1061+
}
10621062
}
1063-
} else if let MetaItemKind::List(_) = meta_item.kind {
1064-
if meta_item.has_name(sym::align) {
1065-
recognised = true;
1066-
sess.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
1067-
span: meta_item.span,
1068-
});
1069-
} else if meta_item.has_name(sym::packed) {
1070-
recognised = true;
1071-
sess.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
1072-
span: meta_item.span,
1073-
});
1074-
} else if matches!(
1075-
meta_item.name_or_empty(),
1076-
sym::C | sym::simd | sym::transparent
1077-
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1078-
{
1079-
recognised = true;
1080-
sess.emit_err(session_diagnostics::InvalidReprHintNoParen {
1081-
span: meta_item.span,
1082-
name: meta_item.name_or_empty().to_ident_string(),
1083-
});
1063+
MetaItemKind::List(_) => {
1064+
if meta_item.has_name(sym::align) {
1065+
recognised = true;
1066+
sess.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
1067+
span: meta_item.span,
1068+
});
1069+
} else if meta_item.has_name(sym::packed) {
1070+
recognised = true;
1071+
sess.emit_err(
1072+
session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
1073+
span: meta_item.span,
1074+
},
1075+
);
1076+
} else if matches!(
1077+
meta_item.name_or_empty(),
1078+
sym::C | sym::simd | sym::transparent
1079+
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1080+
{
1081+
recognised = true;
1082+
sess.emit_err(session_diagnostics::InvalidReprHintNoParen {
1083+
span: meta_item.span,
1084+
name: meta_item.name_or_empty().to_ident_string(),
1085+
});
1086+
}
10841087
}
1088+
_ => (),
10851089
}
10861090
}
10871091
if !recognised {

0 commit comments

Comments
 (0)