@@ -146,26 +146,22 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
146146 match ty. kind ( ) {
147147 ty:: Adt ( adt, _) => must_use_attr ( cx. tcx . get_attrs ( adt. did ) ) . is_some ( ) ,
148148 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, _) => {
153150 // for the Array case we don't need to care for the len == 0 case
154151 // because we don't want to lint functions returning empty arrays
155152 is_must_use_ty ( cx, * ty)
156- }
153+ } ,
157154 ty:: Tuple ( substs) => substs. types ( ) . any ( |ty| is_must_use_ty ( cx, ty) ) ,
158155 ty:: Opaque ( ref def_id, _) => {
159156 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 ( ) {
162158 if must_use_attr ( cx. tcx . get_attrs ( trait_predicate. trait_ref . def_id ) ) . is_some ( ) {
163159 return true ;
164160 }
165161 }
166162 }
167163 false
168- }
164+ } ,
169165 ty:: Dynamic ( binder, _) => {
170166 for predicate in binder. iter ( ) {
171167 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 {
175171 }
176172 }
177173 false
178- }
174+ } ,
179175 _ => false ,
180176 }
181177}
@@ -185,11 +181,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
185181// not succeed
186182/// Checks if `Ty` is normalizable. This function is useful
187183/// 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 {
193185 is_normalizable_helper ( cx, param_env, ty, & mut FxHashMap :: default ( ) )
194186}
195187
@@ -209,14 +201,15 @@ fn is_normalizable_helper<'tcx>(
209201 if infcx. at ( & cause, param_env) . normalize ( ty) . is_ok ( ) {
210202 match ty. kind ( ) {
211203 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) )
215208 } ) ,
216209 _ => ty. walk ( ) . all ( |generic_arg| match generic_arg. unpack ( ) {
217210 GenericArgKind :: Type ( inner_ty) if inner_ty != ty => {
218211 is_normalizable_helper ( cx, param_env, inner_ty, cache)
219- }
212+ } ,
220213 _ => true , // if inner_ty == ty, we've already checked it
221214 } ) ,
222215 }
@@ -234,9 +227,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
234227 match ty. kind ( ) {
235228 ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Str => true ,
236229 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) ,
240231 ty:: Tuple ( inner_types) => inner_types. types ( ) . all ( is_recursively_primitive_type) ,
241232 _ => false ,
242233 }
@@ -280,7 +271,11 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
280271/// removed.
281272pub fn peel_mid_ty_refs ( ty : Ty < ' _ > ) -> ( Ty < ' _ > , usize ) {
282273 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+ }
284279 }
285280 peel ( ty, 0 )
286281}
@@ -335,18 +330,17 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
335330 return false ;
336331 }
337332
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 ,
343338 ( GenericArgKind :: Type ( type_a) , GenericArgKind :: Type ( type_b) ) => {
344339 same_type_and_consts ( type_a, type_b)
345- }
340+ } ,
346341 _ => true ,
347- }
348- } )
349- }
342+ } )
343+ } ,
350344 _ => a == b,
351345 }
352346}
0 commit comments