File tree 4 files changed +10
-10
lines changed
4 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ pub struct Path {
100
100
impl PartialEq < Symbol > for Path {
101
101
#[ inline]
102
102
fn eq ( & self , symbol : & Symbol ) -> bool {
103
- self . segments . len ( ) == 1 && { self . segments [ 0 ] . ident . name == * symbol }
103
+ matches ! ( & self . segments[ .. ] , [ segment ] if segment . ident. name == * symbol)
104
104
}
105
105
}
106
106
@@ -121,13 +121,13 @@ impl Path {
121
121
}
122
122
123
123
pub fn is_global ( & self ) -> bool {
124
- ! self . segments . is_empty ( ) && self . segments [ 0 ] . ident . name == kw:: PathRoot
124
+ self . segments . first ( ) . is_some_and ( |segment| segment . ident . name == kw:: PathRoot )
125
125
}
126
126
127
127
/// If this path is a single identifier with no arguments, does not ensure
128
128
/// that the path resolves to a const param, the caller should check this.
129
129
pub fn is_potential_trivial_const_arg ( & self ) -> bool {
130
- self . segments . len ( ) == 1 && self . segments [ 0 ] . args . is_none ( )
130
+ matches ! ( self . segments[ .. ] , [ PathSegment { args : None , .. } ] )
131
131
}
132
132
}
133
133
Original file line number Diff line number Diff line change @@ -302,7 +302,7 @@ impl AttrItem {
302
302
impl MetaItem {
303
303
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
304
304
pub fn ident ( & self ) -> Option < Ident > {
305
- if self . path . segments . len ( ) == 1 { Some ( self . path . segments [ 0 ] . ident ) } else { None }
305
+ if let [ PathSegment { ident , .. } ] = self . path . segments [ .. ] { Some ( ident) } else { None }
306
306
}
307
307
308
308
pub fn name_or_empty ( & self ) -> Symbol {
Original file line number Diff line number Diff line change @@ -1813,10 +1813,10 @@ pub fn walk_flat_map_stmt<T: MutVisitor>(
1813
1813
. into_iter ( )
1814
1814
. map ( |kind| Stmt { id, kind, span } )
1815
1815
. collect ( ) ;
1816
- match stmts. len ( ) {
1817
- 0 => { }
1818
- 1 => vis. visit_span ( & mut stmts [ 0 ] . span ) ,
1819
- 2 .. => panic ! (
1816
+ match & mut stmts[ .. ] {
1817
+ [ ] => { }
1818
+ [ stmt ] => vis. visit_span ( & mut stmt . span ) ,
1819
+ _ => panic ! (
1820
1820
"cloning statement `NodeId`s is prohibited by default, \
1821
1821
the visitor should implement custom statement visiting"
1822
1822
) ,
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
39
39
let mut i = 0 ;
40
40
let mut j = lines. len ( ) ;
41
41
// first line of all-stars should be omitted
42
- if ! lines. is_empty ( ) && lines [ 0 ] . chars ( ) . all ( |c| c == '*' ) {
42
+ if lines. first ( ) . is_some_and ( |line| line . chars ( ) . all ( |c| c == '*' ) ) {
43
43
i += 1 ;
44
44
}
45
45
@@ -97,7 +97,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
97
97
return None ;
98
98
}
99
99
}
100
- if lines. is_empty ( ) { None } else { Some ( lines [ 0 ] [ ..i] . into ( ) ) }
100
+ Some ( lines. first ( ) ? [ ..i] . to_string ( ) )
101
101
}
102
102
103
103
let data_s = data. as_str ( ) ;
You can’t perform that action at this time.
0 commit comments