rustc_attr
remove ref
patterns
...and some if-let-elses too :P
This commit is contained in:
parent
c75817fb1b
commit
244990a6e9
1 changed files with 69 additions and 65 deletions
|
@ -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,25 +532,24 @@ 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 {
|
||||||
Stability {
|
Some((
|
||||||
level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. },
|
Stability {
|
||||||
..
|
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 });
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,52 +1034,58 @@ 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 {
|
||||||
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
|
MetaItemKind::NameValue(value) => {
|
||||||
let name = meta_item.name_or_empty().to_ident_string();
|
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
|
||||||
recognised = true;
|
let name = meta_item.name_or_empty().to_ident_string();
|
||||||
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
|
recognised = true;
|
||||||
span: item.span(),
|
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
|
||||||
repr_arg: &name,
|
span: item.span(),
|
||||||
cause: IncorrectReprFormatGenericCause::from_lit_kind(
|
repr_arg: &name,
|
||||||
item.span(),
|
cause: IncorrectReprFormatGenericCause::from_lit_kind(
|
||||||
&value.kind,
|
item.span(),
|
||||||
&name,
|
&value.kind,
|
||||||
),
|
&name,
|
||||||
});
|
),
|
||||||
} else if matches!(
|
});
|
||||||
meta_item.name_or_empty(),
|
} else if matches!(
|
||||||
sym::C | sym::simd | sym::transparent
|
meta_item.name_or_empty(),
|
||||||
) || int_type_of_word(meta_item.name_or_empty()).is_some()
|
sym::C | sym::simd | sym::transparent
|
||||||
{
|
) || int_type_of_word(meta_item.name_or_empty()).is_some()
|
||||||
recognised = true;
|
{
|
||||||
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
|
recognised = true;
|
||||||
span: meta_item.span,
|
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
|
||||||
name: meta_item.name_or_empty().to_ident_string(),
|
span: meta_item.span,
|
||||||
});
|
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 {
|
||||||
span: meta_item.span,
|
span: meta_item.span,
|
||||||
});
|
});
|
||||||
} 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(
|
||||||
span: meta_item.span,
|
session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
|
||||||
});
|
span: meta_item.span,
|
||||||
} else if matches!(
|
},
|
||||||
meta_item.name_or_empty(),
|
);
|
||||||
sym::C | sym::simd | sym::transparent
|
} else if matches!(
|
||||||
) || int_type_of_word(meta_item.name_or_empty()).is_some()
|
meta_item.name_or_empty(),
|
||||||
{
|
sym::C | sym::simd | sym::transparent
|
||||||
recognised = true;
|
) || int_type_of_word(meta_item.name_or_empty()).is_some()
|
||||||
sess.emit_err(session_diagnostics::InvalidReprHintNoParen {
|
{
|
||||||
span: meta_item.span,
|
recognised = true;
|
||||||
name: meta_item.name_or_empty().to_ident_string(),
|
sess.emit_err(session_diagnostics::InvalidReprHintNoParen {
|
||||||
});
|
span: meta_item.span,
|
||||||
|
name: meta_item.name_or_empty().to_ident_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !recognised {
|
if !recognised {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue