1
Fork 0

rustc_hir: use box patterns to flatten some nested pattern matches

This commit is contained in:
Yotam Ofek 2025-01-28 22:22:26 +00:00
parent 0baa100710
commit 3802225884
2 changed files with 10 additions and 24 deletions

View file

@ -1061,10 +1061,7 @@ impl Attribute {
pub fn value_lit(&self) -> Option<&MetaItemLit> { pub fn value_lit(&self) -> Option<&MetaItemLit> {
match &self.kind { match &self.kind {
AttrKind::Normal(n) => match n.as_ref() { AttrKind::Normal(box AttrItem { args: AttrArgs::Eq { expr, .. }, .. }) => Some(expr),
AttrItem { args: AttrArgs::Eq { expr, .. }, .. } => Some(expr),
_ => None,
},
_ => None, _ => None,
} }
} }
@ -1077,13 +1074,10 @@ impl AttributeExt for Attribute {
fn meta_item_list(&self) -> Option<ThinVec<ast::MetaItemInner>> { fn meta_item_list(&self) -> Option<ThinVec<ast::MetaItemInner>> {
match &self.kind { match &self.kind {
AttrKind::Normal(n) => match n.as_ref() { AttrKind::Normal(box AttrItem { args: AttrArgs::Delimited(d), .. }) => {
AttrItem { args: AttrArgs::Delimited(d), .. } => {
ast::MetaItemKind::list_from_tokens(d.tokens.clone()) ast::MetaItemKind::list_from_tokens(d.tokens.clone())
} }
_ => None, _ => None,
},
_ => None,
} }
} }
@ -1098,14 +1092,10 @@ impl AttributeExt for Attribute {
/// For a single-segment attribute, returns its name; otherwise, returns `None`. /// For a single-segment attribute, returns its name; otherwise, returns `None`.
fn ident(&self) -> Option<Ident> { fn ident(&self) -> Option<Ident> {
match &self.kind { match &self.kind {
AttrKind::Normal(n) => { AttrKind::Normal(box AttrItem {
if let [ident] = n.path.segments.as_ref() { path: AttrPath { segments: box [ident], .. }, ..
Some(*ident) }) => Some(*ident),
} else { _ => None,
None
}
}
AttrKind::DocComment(..) => None,
} }
} }
@ -1128,12 +1118,7 @@ impl AttributeExt for Attribute {
} }
fn is_word(&self) -> bool { fn is_word(&self) -> bool {
match &self.kind { matches!(self.kind, AttrKind::Normal(box AttrItem { args: AttrArgs::Empty, .. }))
AttrKind::Normal(n) => {
matches!(n.args, AttrArgs::Empty)
}
AttrKind::DocComment(..) => false,
}
} }
fn ident_path(&self) -> Option<SmallVec<[Ident; 1]>> { fn ident_path(&self) -> Option<SmallVec<[Ident; 1]>> {

View file

@ -5,6 +5,7 @@
// tidy-alphabetical-start // tidy-alphabetical-start
#![allow(internal_features)] #![allow(internal_features)]
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(box_patterns)]
#![feature(closure_track_caller)] #![feature(closure_track_caller)]
#![feature(debug_closure_helpers)] #![feature(debug_closure_helpers)]
#![feature(exhaustive_patterns)] #![feature(exhaustive_patterns)]