@@ -146,26 +146,22 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
146
146
match ty. kind ( ) {
147
147
ty:: Adt ( adt, _) => must_use_attr ( cx. tcx . get_attrs ( adt. did ) ) . is_some ( ) ,
148
148
ty:: Foreign ( ref did) => must_use_attr ( cx. tcx . get_attrs ( * did) ) . is_some ( ) ,
149
- ty:: Slice ( ty)
150
- | ty:: Array ( ty, _)
151
- | ty:: RawPtr ( ty:: TypeAndMut { ty, .. } )
152
- | ty:: Ref ( _, ty, _) => {
149
+ ty:: Slice ( ty) | ty:: Array ( ty, _) | ty:: RawPtr ( ty:: TypeAndMut { ty, .. } ) | ty:: Ref ( _, ty, _) => {
153
150
// for the Array case we don't need to care for the len == 0 case
154
151
// because we don't want to lint functions returning empty arrays
155
152
is_must_use_ty ( cx, * ty)
156
- }
153
+ } ,
157
154
ty:: Tuple ( substs) => substs. types ( ) . any ( |ty| is_must_use_ty ( cx, ty) ) ,
158
155
ty:: Opaque ( ref def_id, _) => {
159
156
for ( predicate, _) in cx. tcx . explicit_item_bounds ( * def_id) {
160
- if let ty:: PredicateKind :: Trait ( trait_predicate, _) = predicate. kind ( ) . skip_binder ( )
161
- {
157
+ if let ty:: PredicateKind :: Trait ( trait_predicate, _) = predicate. kind ( ) . skip_binder ( ) {
162
158
if must_use_attr ( cx. tcx . get_attrs ( trait_predicate. trait_ref . def_id ) ) . is_some ( ) {
163
159
return true ;
164
160
}
165
161
}
166
162
}
167
163
false
168
- }
164
+ } ,
169
165
ty:: Dynamic ( binder, _) => {
170
166
for predicate in binder. iter ( ) {
171
167
if let ty:: ExistentialPredicate :: Trait ( ref trait_ref) = predicate. skip_binder ( ) {
@@ -175,7 +171,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
175
171
}
176
172
}
177
173
false
178
- }
174
+ } ,
179
175
_ => false ,
180
176
}
181
177
}
@@ -185,11 +181,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
185
181
// not succeed
186
182
/// Checks if `Ty` is normalizable. This function is useful
187
183
/// to avoid crashes on `layout_of`.
188
- pub fn is_normalizable < ' tcx > (
189
- cx : & LateContext < ' tcx > ,
190
- param_env : ty:: ParamEnv < ' tcx > ,
191
- ty : Ty < ' tcx > ,
192
- ) -> bool {
184
+ pub fn is_normalizable < ' tcx > ( cx : & LateContext < ' tcx > , param_env : ty:: ParamEnv < ' tcx > , ty : Ty < ' tcx > ) -> bool {
193
185
is_normalizable_helper ( cx, param_env, ty, & mut FxHashMap :: default ( ) )
194
186
}
195
187
@@ -209,14 +201,15 @@ fn is_normalizable_helper<'tcx>(
209
201
if infcx. at ( & cause, param_env) . normalize ( ty) . is_ok ( ) {
210
202
match ty. kind ( ) {
211
203
ty:: Adt ( def, substs) => def. variants . iter ( ) . all ( |variant| {
212
- variant. fields . iter ( ) . all ( |field| {
213
- is_normalizable_helper ( cx, param_env, field. ty ( cx. tcx , substs) , cache)
214
- } )
204
+ variant
205
+ . fields
206
+ . iter ( )
207
+ . all ( |field| is_normalizable_helper ( cx, param_env, field. ty ( cx. tcx , substs) , cache) )
215
208
} ) ,
216
209
_ => ty. walk ( ) . all ( |generic_arg| match generic_arg. unpack ( ) {
217
210
GenericArgKind :: Type ( inner_ty) if inner_ty != ty => {
218
211
is_normalizable_helper ( cx, param_env, inner_ty, cache)
219
- }
212
+ } ,
220
213
_ => true , // if inner_ty == ty, we've already checked it
221
214
} ) ,
222
215
}
@@ -234,9 +227,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
234
227
match ty. kind ( ) {
235
228
ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Str => true ,
236
229
ty:: Ref ( _, inner, _) if * inner. kind ( ) == ty:: Str => true ,
237
- ty:: Array ( inner_type, _) | ty:: Slice ( inner_type) => {
238
- is_recursively_primitive_type ( inner_type)
239
- }
230
+ ty:: Array ( inner_type, _) | ty:: Slice ( inner_type) => is_recursively_primitive_type ( inner_type) ,
240
231
ty:: Tuple ( inner_types) => inner_types. types ( ) . all ( is_recursively_primitive_type) ,
241
232
_ => false ,
242
233
}
@@ -280,7 +271,11 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
280
271
/// removed.
281
272
pub fn peel_mid_ty_refs ( ty : Ty < ' _ > ) -> ( Ty < ' _ > , usize ) {
282
273
fn peel ( ty : Ty < ' _ > , count : usize ) -> ( Ty < ' _ > , usize ) {
283
- if let ty:: Ref ( _, ty, _) = ty. kind ( ) { peel ( ty, count + 1 ) } else { ( ty, count) }
274
+ if let ty:: Ref ( _, ty, _) = ty. kind ( ) {
275
+ peel ( ty, count + 1 )
276
+ } else {
277
+ ( ty, count)
278
+ }
284
279
}
285
280
peel ( ty, 0 )
286
281
}
@@ -335,18 +330,17 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
335
330
return false ;
336
331
}
337
332
338
- substs_a. iter ( ) . zip ( substs_b . iter ( ) ) . all ( | ( arg_a , arg_b ) | {
339
- match ( arg_a . unpack ( ) , arg_b . unpack ( ) ) {
340
- ( GenericArgKind :: Const ( inner_a ) , GenericArgKind :: Const ( inner_b ) ) => {
341
- inner_a == inner_b
342
- }
333
+ substs_a
334
+ . iter ( )
335
+ . zip ( substs_b . iter ( ) )
336
+ . all ( | ( arg_a , arg_b ) | match ( arg_a . unpack ( ) , arg_b . unpack ( ) ) {
337
+ ( GenericArgKind :: Const ( inner_a ) , GenericArgKind :: Const ( inner_b ) ) => inner_a == inner_b ,
343
338
( GenericArgKind :: Type ( type_a) , GenericArgKind :: Type ( type_b) ) => {
344
339
same_type_and_consts ( type_a, type_b)
345
- }
340
+ } ,
346
341
_ => true ,
347
- }
348
- } )
349
- }
342
+ } )
343
+ } ,
350
344
_ => a == b,
351
345
}
352
346
}
0 commit comments