@@ -206,7 +206,7 @@ pub type UsePath<'hir> = Path<'hir, SmallVec<[Res; 3]>>;
206
206
207
207
impl Path < ' _ > {
208
208
pub fn is_global ( & self ) -> bool {
209
- ! self . segments . is_empty ( ) && self . segments [ 0 ] . ident . name == kw:: PathRoot
209
+ self . segments . first ( ) . is_some_and ( |segment| segment . ident . name == kw:: PathRoot )
210
210
}
211
211
}
212
212
@@ -1061,10 +1061,7 @@ impl Attribute {
1061
1061
1062
1062
pub fn value_lit ( & self ) -> Option < & MetaItemLit > {
1063
1063
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) ,
1068
1065
_ => None ,
1069
1066
}
1070
1067
}
@@ -1077,12 +1074,9 @@ impl AttributeExt for Attribute {
1077
1074
1078
1075
fn meta_item_list ( & self ) -> Option < ThinVec < ast:: MetaItemInner > > {
1079
1076
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
+ }
1086
1080
_ => None ,
1087
1081
}
1088
1082
}
@@ -1098,23 +1092,16 @@ impl AttributeExt for Attribute {
1098
1092
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
1099
1093
fn ident ( & self ) -> Option < Ident > {
1100
1094
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 ,
1109
1099
}
1110
1100
}
1111
1101
1112
1102
fn path_matches ( & self , name : & [ Symbol ] ) -> bool {
1113
1103
match & self . kind {
1114
- AttrKind :: Normal ( n) => {
1115
- n. path . segments . len ( ) == name. len ( )
1116
- && n. path . segments . iter ( ) . zip ( name) . all ( |( s, n) | s. name == * n)
1117
- }
1104
+ AttrKind :: Normal ( n) => n. path . segments . iter ( ) . map ( |segment| & segment. name ) . eq ( name) ,
1118
1105
AttrKind :: DocComment ( ..) => false ,
1119
1106
}
1120
1107
}
@@ -1128,12 +1115,7 @@ impl AttributeExt for Attribute {
1128
1115
}
1129
1116
1130
1117
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
- }
1118
+ matches ! ( self . kind, AttrKind :: Normal ( box AttrItem { args: AttrArgs :: Empty , .. } ) )
1137
1119
}
1138
1120
1139
1121
fn ident_path ( & self ) -> Option < SmallVec < [ Ident ; 1 ] > > {
@@ -1990,7 +1972,7 @@ impl fmt::Display for ConstContext {
1990
1972
}
1991
1973
1992
1974
// NOTE: `IntoDiagArg` impl for `ConstContext` lives in `rustc_errors`
1993
- // due to a cyclical dependency between hir that crate.
1975
+ // due to a cyclical dependency between hir and that crate.
1994
1976
1995
1977
/// A literal.
1996
1978
pub type Lit = Spanned < LitKind > ;
@@ -3604,10 +3586,10 @@ impl<'hir> FnRetTy<'hir> {
3604
3586
}
3605
3587
3606
3588
pub fn is_suggestable_infer_ty ( & self ) -> Option < & ' hir Ty < ' hir > > {
3607
- if let Self :: Return ( ty) = self {
3608
- if ty. is_suggestable_infer_ty ( ) {
3609
- return Some ( * ty ) ;
3610
- }
3589
+ if let Self :: Return ( ty) = self
3590
+ && ty. is_suggestable_infer_ty ( )
3591
+ {
3592
+ return Some ( * ty ) ;
3611
3593
}
3612
3594
None
3613
3595
}
@@ -3976,11 +3958,11 @@ pub struct FnHeader {
3976
3958
3977
3959
impl FnHeader {
3978
3960
pub fn is_async ( & self ) -> bool {
3979
- matches ! ( & self . asyncness, IsAsync :: Async ( _) )
3961
+ matches ! ( self . asyncness, IsAsync :: Async ( _) )
3980
3962
}
3981
3963
3982
3964
pub fn is_const ( & self ) -> bool {
3983
- matches ! ( & self . constness, Constness :: Const )
3965
+ matches ! ( self . constness, Constness :: Const )
3984
3966
}
3985
3967
3986
3968
pub fn is_unsafe ( & self ) -> bool {
@@ -4076,16 +4058,16 @@ pub struct Impl<'hir> {
4076
4058
4077
4059
impl ItemKind < ' _ > {
4078
4060
pub fn generics ( & self ) -> Option < & Generics < ' _ > > {
4079
- Some ( match * self {
4080
- ItemKind :: Fn { ref generics, .. }
4081
- | ItemKind :: TyAlias ( _, ref generics)
4082
- | ItemKind :: Const ( _, ref generics, _)
4083
- | ItemKind :: Enum ( _, ref generics)
4084
- | ItemKind :: Struct ( _, ref generics)
4085
- | ItemKind :: Union ( _, ref generics)
4086
- | ItemKind :: Trait ( _, _, ref generics, _, _)
4087
- | ItemKind :: TraitAlias ( ref generics, _)
4088
- | ItemKind :: Impl ( Impl { ref generics, .. } ) => generics,
4061
+ Some ( match self {
4062
+ ItemKind :: Fn { generics, .. }
4063
+ | ItemKind :: TyAlias ( _, generics)
4064
+ | ItemKind :: Const ( _, generics, _)
4065
+ | ItemKind :: Enum ( _, generics)
4066
+ | ItemKind :: Struct ( _, generics)
4067
+ | ItemKind :: Union ( _, generics)
4068
+ | ItemKind :: Trait ( _, _, generics, _, _)
4069
+ | ItemKind :: TraitAlias ( generics, _)
4070
+ | ItemKind :: Impl ( Impl { generics, .. } ) => generics,
4089
4071
_ => return None ,
4090
4072
} )
4091
4073
}
@@ -4484,16 +4466,14 @@ impl<'hir> Node<'hir> {
4484
4466
4485
4467
/// Get a `hir::Impl` if the node is an impl block for the given `trait_def_id`.
4486
4468
pub fn impl_block_of_trait ( self , trait_def_id : DefId ) -> Option < & ' hir Impl < ' hir > > {
4487
- match self {
4488
- Node :: Item ( Item { kind : ItemKind :: Impl ( impl_block) , .. } )
4489
- if impl_block
4490
- . of_trait
4491
- . and_then ( |trait_ref| trait_ref. trait_def_id ( ) )
4492
- . is_some_and ( |trait_id| trait_id == trait_def_id) =>
4493
- {
4494
- Some ( impl_block)
4495
- }
4496
- _ => None ,
4469
+ if let Node :: Item ( Item { kind : ItemKind :: Impl ( impl_block) , .. } ) = self
4470
+ && let Some ( trait_ref) = impl_block. of_trait
4471
+ && let Some ( trait_id) = trait_ref. trait_def_id ( )
4472
+ && trait_id == trait_def_id
4473
+ {
4474
+ Some ( impl_block)
4475
+ } else {
4476
+ None
4497
4477
}
4498
4478
}
4499
4479
0 commit comments