@@ -44,16 +44,16 @@ impl MarkedAttrs {
44
44
impl NestedMetaItem {
45
45
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
46
46
pub fn meta_item ( & self ) -> Option < & MetaItem > {
47
- match * self {
48
- NestedMetaItem :: MetaItem ( ref item) => Some ( item) ,
47
+ match self {
48
+ NestedMetaItem :: MetaItem ( item) => Some ( item) ,
49
49
_ => None ,
50
50
}
51
51
}
52
52
53
53
/// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s.
54
54
pub fn literal ( & self ) -> Option < & Lit > {
55
- match * self {
56
- NestedMetaItem :: Literal ( ref lit) => Some ( lit) ,
55
+ match self {
56
+ NestedMetaItem :: Literal ( lit) => Some ( lit) ,
57
57
_ => None ,
58
58
}
59
59
}
@@ -116,18 +116,18 @@ impl NestedMetaItem {
116
116
impl Attribute {
117
117
#[ inline]
118
118
pub fn has_name ( & self , name : Symbol ) -> bool {
119
- match self . kind {
120
- AttrKind :: Normal ( ref normal) => normal. item . path == name,
119
+ match & self . kind {
120
+ AttrKind :: Normal ( normal) => normal. item . path == name,
121
121
AttrKind :: DocComment ( ..) => false ,
122
122
}
123
123
}
124
124
125
125
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
126
126
pub fn ident ( & self ) -> Option < Ident > {
127
- match self . kind {
128
- AttrKind :: Normal ( ref normal) => {
129
- if normal. item . path . segments . len ( ) == 1 {
130
- Some ( normal . item . path . segments [ 0 ] . ident )
127
+ match & self . kind {
128
+ AttrKind :: Normal ( normal) => {
129
+ if let [ ident ] = & * normal. item . path . segments {
130
+ Some ( ident . ident )
131
131
} else {
132
132
None
133
133
}
@@ -140,17 +140,15 @@ impl Attribute {
140
140
}
141
141
142
142
pub fn value_str ( & self ) -> Option < Symbol > {
143
- match self . kind {
144
- AttrKind :: Normal ( ref normal) => {
145
- normal. item . meta_kind ( ) . and_then ( |kind| kind. value_str ( ) )
146
- }
143
+ match & self . kind {
144
+ AttrKind :: Normal ( normal) => normal. item . meta_kind ( ) . and_then ( |kind| kind. value_str ( ) ) ,
147
145
AttrKind :: DocComment ( ..) => None ,
148
146
}
149
147
}
150
148
151
149
pub fn meta_item_list ( & self ) -> Option < Vec < NestedMetaItem > > {
152
- match self . kind {
153
- AttrKind :: Normal ( ref normal) => match normal. item . meta_kind ( ) {
150
+ match & self . kind {
151
+ AttrKind :: Normal ( normal) => match normal. item . meta_kind ( ) {
154
152
Some ( MetaItemKind :: List ( list) ) => Some ( list) ,
155
153
_ => None ,
156
154
} ,
@@ -191,8 +189,8 @@ impl MetaItem {
191
189
}
192
190
193
191
pub fn meta_item_list ( & self ) -> Option < & [ NestedMetaItem ] > {
194
- match self . kind {
195
- MetaItemKind :: List ( ref l) => Some ( & l [ .. ] ) ,
192
+ match & self . kind {
193
+ MetaItemKind :: List ( l) => Some ( & * * l ) ,
196
194
_ => None ,
197
195
}
198
196
}
@@ -268,9 +266,9 @@ impl Attribute {
268
266
/// * `#[doc = "doc"]` returns `Some("doc")`.
269
267
/// * `#[doc(...)]` returns `None`.
270
268
pub fn doc_str ( & self ) -> Option < Symbol > {
271
- match self . kind {
272
- AttrKind :: DocComment ( .., data) => Some ( data) ,
273
- AttrKind :: Normal ( ref normal) if normal. item . path == sym:: doc => {
269
+ match & self . kind {
270
+ AttrKind :: DocComment ( .., data) => Some ( * data) ,
271
+ AttrKind :: Normal ( normal) if normal. item . path == sym:: doc => {
274
272
normal. item . meta_kind ( ) . and_then ( |kind| kind. value_str ( ) )
275
273
}
276
274
_ => None ,
@@ -282,8 +280,8 @@ impl Attribute {
282
280
}
283
281
284
282
pub fn get_normal_item ( & self ) -> & AttrItem {
285
- match self . kind {
286
- AttrKind :: Normal ( ref normal) => & normal. item ,
283
+ match & self . kind {
284
+ AttrKind :: Normal ( normal) => & normal. item ,
287
285
AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
288
286
}
289
287
}
@@ -297,28 +295,28 @@ impl Attribute {
297
295
298
296
/// Extracts the MetaItem from inside this Attribute.
299
297
pub fn meta ( & self ) -> Option < MetaItem > {
300
- match self . kind {
301
- AttrKind :: Normal ( ref normal) => normal. item . meta ( self . span ) ,
298
+ match & self . kind {
299
+ AttrKind :: Normal ( normal) => normal. item . meta ( self . span ) ,
302
300
AttrKind :: DocComment ( ..) => None ,
303
301
}
304
302
}
305
303
306
304
pub fn meta_kind ( & self ) -> Option < MetaItemKind > {
307
- match self . kind {
308
- AttrKind :: Normal ( ref normal) => normal. item . meta_kind ( ) ,
305
+ match & self . kind {
306
+ AttrKind :: Normal ( normal) => normal. item . meta_kind ( ) ,
309
307
AttrKind :: DocComment ( ..) => None ,
310
308
}
311
309
}
312
310
313
311
pub fn tokens ( & self ) -> TokenStream {
314
- match self . kind {
315
- AttrKind :: Normal ( ref normal) => normal
312
+ match & self . kind {
313
+ AttrKind :: Normal ( normal) => normal
316
314
. tokens
317
315
. as_ref ( )
318
316
. unwrap_or_else ( || panic ! ( "attribute is missing tokens: {:?}" , self ) )
319
317
. to_attr_token_stream ( )
320
318
. to_tokenstream ( ) ,
321
- AttrKind :: DocComment ( comment_kind, data) => TokenStream :: new ( vec ! [ TokenTree :: Token (
319
+ & AttrKind :: DocComment ( comment_kind, data) => TokenStream :: new ( vec ! [ TokenTree :: Token (
322
320
Token :: new( token:: DocComment ( comment_kind, self . style, data) , self . span) ,
323
321
Spacing :: Alone ,
324
322
) ] ) ,
@@ -496,17 +494,17 @@ impl MetaItem {
496
494
let span = span. with_hi ( segments. last ( ) . unwrap ( ) . ident . span . hi ( ) ) ;
497
495
Path { span, segments, tokens : None }
498
496
}
499
- Some ( TokenTree :: Token ( Token { kind : token:: Interpolated ( nt) , .. } , _) ) => match * nt {
500
- token:: Nonterminal :: NtMeta ( ref item) => return item. meta ( item. path . span ) ,
501
- token:: Nonterminal :: NtPath ( ref path) => ( * * path) . clone ( ) ,
497
+ Some ( TokenTree :: Token ( Token { kind : token:: Interpolated ( nt) , .. } , _) ) => match & * nt {
498
+ token:: Nonterminal :: NtMeta ( item) => return item. meta ( item. path . span ) ,
499
+ token:: Nonterminal :: NtPath ( path) => ( * * path) . clone ( ) ,
502
500
_ => return None ,
503
501
} ,
504
502
_ => return None ,
505
503
} ;
506
504
let list_closing_paren_pos = tokens. peek ( ) . map ( |tt| tt. span ( ) . hi ( ) ) ;
507
505
let kind = MetaItemKind :: from_tokens ( tokens) ?;
508
- let hi = match kind {
509
- MetaItemKind :: NameValue ( ref lit) => lit. span . hi ( ) ,
506
+ let hi = match & kind {
507
+ MetaItemKind :: NameValue ( lit) => lit. span . hi ( ) ,
510
508
MetaItemKind :: List ( ..) => list_closing_paren_pos. unwrap_or ( path. span . hi ( ) ) ,
511
509
_ => path. span . hi ( ) ,
512
510
} ;
@@ -518,8 +516,8 @@ impl MetaItem {
518
516
impl MetaItemKind {
519
517
pub fn value_str ( & self ) -> Option < Symbol > {
520
518
match self {
521
- MetaItemKind :: NameValue ( ref v) => match v. kind {
522
- LitKind :: Str ( ref s, _) => Some ( * s) ,
519
+ MetaItemKind :: NameValue ( v) => match v. kind {
520
+ LitKind :: Str ( s, _) => Some ( s) ,
523
521
_ => None ,
524
522
} ,
525
523
_ => None ,
@@ -557,15 +555,15 @@ impl MetaItemKind {
557
555
}
558
556
559
557
fn token_trees ( & self , span : Span ) -> Vec < TokenTree > {
560
- match * self {
558
+ match self {
561
559
MetaItemKind :: Word => vec ! [ ] ,
562
- MetaItemKind :: NameValue ( ref lit) => {
560
+ MetaItemKind :: NameValue ( lit) => {
563
561
vec ! [
564
562
TokenTree :: token_alone( token:: Eq , span) ,
565
563
TokenTree :: Token ( lit. to_token( ) , Spacing :: Alone ) ,
566
564
]
567
565
}
568
- MetaItemKind :: List ( ref list) => {
566
+ MetaItemKind :: List ( list) => {
569
567
let mut tokens = Vec :: new ( ) ;
570
568
for ( i, item) in list. iter ( ) . enumerate ( ) {
571
569
if i > 0 {
@@ -648,16 +646,16 @@ impl MetaItemKind {
648
646
649
647
impl NestedMetaItem {
650
648
pub fn span ( & self ) -> Span {
651
- match * self {
652
- NestedMetaItem :: MetaItem ( ref item) => item. span ,
653
- NestedMetaItem :: Literal ( ref lit) => lit. span ,
649
+ match self {
650
+ NestedMetaItem :: MetaItem ( item) => item. span ,
651
+ NestedMetaItem :: Literal ( lit) => lit. span ,
654
652
}
655
653
}
656
654
657
655
fn token_trees ( & self ) -> Vec < TokenTree > {
658
- match * self {
659
- NestedMetaItem :: MetaItem ( ref item) => item. token_trees ( ) ,
660
- NestedMetaItem :: Literal ( ref lit) => {
656
+ match self {
657
+ NestedMetaItem :: MetaItem ( item) => item. token_trees ( ) ,
658
+ NestedMetaItem :: Literal ( lit) => {
661
659
vec ! [ TokenTree :: Token ( lit. to_token( ) , Spacing :: Alone ) ]
662
660
}
663
661
}
0 commit comments