Skip to content

Commit 3802225

Browse files
committed
rustc_hir: use box patterns to flatten some nested pattern matches
1 parent 0baa100 commit 3802225

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,7 @@ impl Attribute {
10611061

10621062
pub fn value_lit(&self) -> Option<&MetaItemLit> {
10631063
match &self.kind {
1064-
AttrKind::Normal(n) => match n.as_ref() {
1065-
AttrItem { args: AttrArgs::Eq { expr, .. }, .. } => Some(expr),
1066-
_ => None,
1067-
},
1064+
AttrKind::Normal(box AttrItem { args: AttrArgs::Eq { expr, .. }, .. }) => Some(expr),
10681065
_ => None,
10691066
}
10701067
}
@@ -1077,12 +1074,9 @@ impl AttributeExt for Attribute {
10771074

10781075
fn meta_item_list(&self) -> Option<ThinVec<ast::MetaItemInner>> {
10791076
match &self.kind {
1080-
AttrKind::Normal(n) => match n.as_ref() {
1081-
AttrItem { args: AttrArgs::Delimited(d), .. } => {
1082-
ast::MetaItemKind::list_from_tokens(d.tokens.clone())
1083-
}
1084-
_ => None,
1085-
},
1077+
AttrKind::Normal(box AttrItem { args: AttrArgs::Delimited(d), .. }) => {
1078+
ast::MetaItemKind::list_from_tokens(d.tokens.clone())
1079+
}
10861080
_ => None,
10871081
}
10881082
}
@@ -1098,14 +1092,10 @@ impl AttributeExt for Attribute {
10981092
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
10991093
fn ident(&self) -> Option<Ident> {
11001094
match &self.kind {
1101-
AttrKind::Normal(n) => {
1102-
if let [ident] = n.path.segments.as_ref() {
1103-
Some(*ident)
1104-
} else {
1105-
None
1106-
}
1107-
}
1108-
AttrKind::DocComment(..) => None,
1095+
AttrKind::Normal(box AttrItem {
1096+
path: AttrPath { segments: box [ident], .. }, ..
1097+
}) => Some(*ident),
1098+
_ => None,
11091099
}
11101100
}
11111101

@@ -1128,12 +1118,7 @@ impl AttributeExt for Attribute {
11281118
}
11291119

11301120
fn is_word(&self) -> bool {
1131-
match &self.kind {
1132-
AttrKind::Normal(n) => {
1133-
matches!(n.args, AttrArgs::Empty)
1134-
}
1135-
AttrKind::DocComment(..) => false,
1136-
}
1121+
matches!(self.kind, AttrKind::Normal(box AttrItem { args: AttrArgs::Empty, .. }))
11371122
}
11381123

11391124
fn ident_path(&self) -> Option<SmallVec<[Ident; 1]>> {

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// tidy-alphabetical-start
66
#![allow(internal_features)]
77
#![feature(associated_type_defaults)]
8+
#![feature(box_patterns)]
89
#![feature(closure_track_caller)]
910
#![feature(debug_closure_helpers)]
1011
#![feature(exhaustive_patterns)]

0 commit comments

Comments
 (0)