1
- #[ cfg( feature = "full" ) ]
2
- use crate :: expr:: Expr ;
3
- #[ cfg( any( feature = "printing" , feature = "full" ) ) ]
4
- use crate :: generics:: TypeParamBound ;
5
- #[ cfg( any( feature = "printing" , feature = "full" ) ) ]
6
- use crate :: path:: { Path , PathArguments } ;
7
- #[ cfg( any( feature = "printing" , feature = "full" ) ) ]
8
- use crate :: punctuated:: Punctuated ;
9
- #[ cfg( any( feature = "printing" , feature = "full" ) ) ]
10
- use crate :: ty:: { ReturnType , Type } ;
11
- #[ cfg( feature = "full" ) ]
12
1
use proc_macro2:: { Delimiter , TokenStream , TokenTree } ;
13
- #[ cfg( any( feature = "printing" , feature = "full" ) ) ]
14
2
use std:: ops:: ControlFlow ;
3
+ use syn:: punctuated:: Punctuated ;
4
+ use syn:: { Expr , MacroDelimiter , Path , PathArguments , ReturnType , Token , Type , TypeParamBound } ;
15
5
16
- #[ cfg( feature = "full" ) ]
17
6
pub ( crate ) fn requires_semi_to_be_stmt ( expr : & Expr ) -> bool {
18
7
match expr {
19
- Expr :: Macro ( expr) => !expr. mac . delimiter . is_brace ( ) ,
8
+ Expr :: Macro ( expr) => !matches ! ( expr. mac. delimiter, MacroDelimiter :: Brace ( _ ) ) ,
20
9
_ => requires_comma_to_be_match_arm ( expr) ,
21
10
}
22
11
}
23
12
24
- #[ cfg( feature = "full" ) ]
25
13
pub ( crate ) fn requires_comma_to_be_match_arm ( expr : & Expr ) -> bool {
26
14
match expr {
15
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
27
16
Expr :: If ( _)
28
17
| Expr :: Match ( _)
29
18
| Expr :: Block ( _) | Expr :: Unsafe ( _) // both under ExprKind::Block in rustc
@@ -64,13 +53,15 @@ pub(crate) fn requires_comma_to_be_match_arm(expr: &Expr) -> bool {
64
53
| Expr :: Unary ( _)
65
54
| Expr :: Yield ( _)
66
55
| Expr :: Verbatim ( _) => true ,
56
+
57
+ _ => true ,
67
58
}
68
59
}
69
60
70
- #[ cfg( feature = "printing" ) ]
71
61
pub ( crate ) fn trailing_unparameterized_path ( mut ty : & Type ) -> bool {
72
62
loop {
73
63
match ty {
64
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
74
65
Type :: BareFn ( t) => match & t. output {
75
66
ReturnType :: Default => return false ,
76
67
ReturnType :: Type ( _, ret) => ty = ret,
@@ -99,6 +90,8 @@ pub(crate) fn trailing_unparameterized_path(mut ty: &Type) -> bool {
99
90
| Type :: Slice ( _)
100
91
| Type :: Tuple ( _)
101
92
| Type :: Verbatim ( _) => return false ,
93
+
94
+ _ => return false ,
102
95
}
103
96
}
104
97
@@ -117,19 +110,21 @@ pub(crate) fn trailing_unparameterized_path(mut ty: &Type) -> bool {
117
110
bounds : & Punctuated < TypeParamBound , Token ! [ +] > ,
118
111
) -> ControlFlow < bool , & Type > {
119
112
match bounds. last ( ) . unwrap ( ) {
113
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
120
114
TypeParamBound :: Trait ( t) => last_type_in_path ( & t. path ) ,
121
115
TypeParamBound :: Lifetime ( _)
122
116
| TypeParamBound :: PreciseCapture ( _)
123
117
| TypeParamBound :: Verbatim ( _) => ControlFlow :: Break ( false ) ,
118
+ _ => ControlFlow :: Break ( false ) ,
124
119
}
125
120
}
126
121
}
127
122
128
123
/// Whether the expression's first token is the label of a loop/block.
129
- #[ cfg( all( feature = "printing" , feature = "full" ) ) ]
130
124
pub ( crate ) fn expr_leading_label ( mut expr : & Expr ) -> bool {
131
125
loop {
132
126
match expr {
127
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
133
128
Expr :: Block ( e) => return e. label . is_some ( ) ,
134
129
Expr :: ForLoop ( e) => return e. label . is_some ( ) ,
135
130
Expr :: Loop ( e) => return e. label . is_some ( ) ,
@@ -175,15 +170,17 @@ pub(crate) fn expr_leading_label(mut expr: &Expr) -> bool {
175
170
| Expr :: Unsafe ( _)
176
171
| Expr :: Verbatim ( _)
177
172
| Expr :: Yield ( _) => return false ,
173
+
174
+ _ => return false ,
178
175
}
179
176
}
180
177
}
181
178
182
179
/// Whether the expression's last token is `}`.
183
- #[ cfg( feature = "full" ) ]
184
180
pub ( crate ) fn expr_trailing_brace ( mut expr : & Expr ) -> bool {
185
181
loop {
186
182
match expr {
183
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
187
184
Expr :: Async ( _)
188
185
| Expr :: Block ( _)
189
186
| Expr :: Const ( _)
@@ -205,7 +202,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
205
202
Expr :: Cast ( e) => return type_trailing_brace ( & e. ty ) ,
206
203
Expr :: Closure ( e) => expr = & e. body ,
207
204
Expr :: Let ( e) => expr = & e. expr ,
208
- Expr :: Macro ( e) => return e. mac . delimiter . is_brace ( ) ,
205
+ Expr :: Macro ( e) => return matches ! ( e. mac. delimiter, MacroDelimiter :: Brace ( _ ) ) ,
209
206
Expr :: Range ( e) => match & e. end {
210
207
Some ( end) => expr = end,
211
208
None => return false ,
@@ -238,12 +235,15 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
238
235
| Expr :: Repeat ( _)
239
236
| Expr :: Try ( _)
240
237
| Expr :: Tuple ( _) => return false ,
238
+
239
+ _ => return false ,
241
240
}
242
241
}
243
242
244
243
fn type_trailing_brace ( mut ty : & Type ) -> bool {
245
244
loop {
246
245
match ty {
246
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
247
247
Type :: BareFn ( t) => match & t. output {
248
248
ReturnType :: Default => return false ,
249
249
ReturnType :: Type ( _, ret) => ty = ret,
@@ -252,7 +252,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
252
252
ControlFlow :: Break ( trailing_brace) => return trailing_brace,
253
253
ControlFlow :: Continue ( t) => ty = t,
254
254
} ,
255
- Type :: Macro ( t) => return t. mac . delimiter . is_brace ( ) ,
255
+ Type :: Macro ( t) => return matches ! ( t. mac. delimiter, MacroDelimiter :: Brace ( _ ) ) ,
256
256
Type :: Path ( t) => match last_type_in_path ( & t. path ) {
257
257
Some ( t) => ty = t,
258
258
None => return false ,
@@ -272,6 +272,8 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
272
272
| Type :: Paren ( _)
273
273
| Type :: Slice ( _)
274
274
| Type :: Tuple ( _) => return false ,
275
+
276
+ _ => return false ,
275
277
}
276
278
}
277
279
}
@@ -290,6 +292,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
290
292
bounds : & Punctuated < TypeParamBound , Token ! [ +] > ,
291
293
) -> ControlFlow < bool , & Type > {
292
294
match bounds. last ( ) . unwrap ( ) {
295
+ #![ cfg_attr( all( test, exhaustive) , deny( non_exhaustive_omitted_patterns) ) ]
293
296
TypeParamBound :: Trait ( t) => match last_type_in_path ( & t. path ) {
294
297
Some ( t) => ControlFlow :: Continue ( t) ,
295
298
None => ControlFlow :: Break ( false ) ,
@@ -298,6 +301,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
298
301
ControlFlow :: Break ( false )
299
302
}
300
303
TypeParamBound :: Verbatim ( t) => ControlFlow :: Break ( tokens_trailing_brace ( t) ) ,
304
+ _ => ControlFlow :: Break ( false ) ,
301
305
}
302
306
}
303
307
0 commit comments