@@ -128,7 +128,9 @@ pub fn implements_trait<'tcx>(
128128 return false ;
129129 }
130130 let ty_params = cx. tcx . mk_substs ( ty_params. iter ( ) ) ;
131- cx. tcx . type_implements_trait ( ( trait_id, ty, ty_params, cx. param_env ) )
131+ cx. tcx
132+ . type_implements_trait ( ( trait_id, ty, ty_params, cx. param_env ) )
133+ . must_apply_modulo_regions ( )
132134}
133135
134136/// Checks whether this type implements `Drop`.
@@ -144,22 +146,26 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
144146 match ty. kind ( ) {
145147 ty:: Adt ( adt, _) => must_use_attr ( cx. tcx . get_attrs ( adt. did ) ) . is_some ( ) ,
146148 ty:: Foreign ( ref did) => must_use_attr ( cx. tcx . get_attrs ( * did) ) . is_some ( ) ,
147- ty:: Slice ( ty) | ty:: Array ( ty, _) | ty:: RawPtr ( ty:: TypeAndMut { ty, .. } ) | ty:: Ref ( _, ty, _) => {
149+ ty:: Slice ( ty)
150+ | ty:: Array ( ty, _)
151+ | ty:: RawPtr ( ty:: TypeAndMut { ty, .. } )
152+ | ty:: Ref ( _, ty, _) => {
148153 // for the Array case we don't need to care for the len == 0 case
149154 // because we don't want to lint functions returning empty arrays
150155 is_must_use_ty ( cx, * ty)
151- } ,
156+ }
152157 ty:: Tuple ( substs) => substs. types ( ) . any ( |ty| is_must_use_ty ( cx, ty) ) ,
153158 ty:: Opaque ( ref def_id, _) => {
154159 for ( predicate, _) in cx. tcx . explicit_item_bounds ( * def_id) {
155- if let ty:: PredicateKind :: Trait ( trait_predicate, _) = predicate. kind ( ) . skip_binder ( ) {
160+ if let ty:: PredicateKind :: Trait ( trait_predicate, _) = predicate. kind ( ) . skip_binder ( )
161+ {
156162 if must_use_attr ( cx. tcx . get_attrs ( trait_predicate. trait_ref . def_id ) ) . is_some ( ) {
157163 return true ;
158164 }
159165 }
160166 }
161167 false
162- } ,
168+ }
163169 ty:: Dynamic ( binder, _) => {
164170 for predicate in binder. iter ( ) {
165171 if let ty:: ExistentialPredicate :: Trait ( ref trait_ref) = predicate. skip_binder ( ) {
@@ -169,7 +175,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
169175 }
170176 }
171177 false
172- } ,
178+ }
173179 _ => false ,
174180 }
175181}
@@ -179,7 +185,11 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
179185// not succeed
180186/// Checks if `Ty` is normalizable. This function is useful
181187/// to avoid crashes on `layout_of`.
182- pub fn is_normalizable < ' tcx > ( cx : & LateContext < ' tcx > , param_env : ty:: ParamEnv < ' tcx > , ty : Ty < ' tcx > ) -> bool {
188+ pub fn is_normalizable < ' tcx > (
189+ cx : & LateContext < ' tcx > ,
190+ param_env : ty:: ParamEnv < ' tcx > ,
191+ ty : Ty < ' tcx > ,
192+ ) -> bool {
183193 is_normalizable_helper ( cx, param_env, ty, & mut FxHashMap :: default ( ) )
184194}
185195
@@ -199,15 +209,14 @@ fn is_normalizable_helper<'tcx>(
199209 if infcx. at ( & cause, param_env) . normalize ( ty) . is_ok ( ) {
200210 match ty. kind ( ) {
201211 ty:: Adt ( def, substs) => def. variants . iter ( ) . all ( |variant| {
202- variant
203- . fields
204- . iter ( )
205- . all ( |field| is_normalizable_helper ( cx, param_env, field. ty ( cx. tcx , substs) , cache) )
212+ variant. fields . iter ( ) . all ( |field| {
213+ is_normalizable_helper ( cx, param_env, field. ty ( cx. tcx , substs) , cache)
214+ } )
206215 } ) ,
207216 _ => ty. walk ( ) . all ( |generic_arg| match generic_arg. unpack ( ) {
208217 GenericArgKind :: Type ( inner_ty) if inner_ty != ty => {
209218 is_normalizable_helper ( cx, param_env, inner_ty, cache)
210- } ,
219+ }
211220 _ => true , // if inner_ty == ty, we've already checked it
212221 } ) ,
213222 }
@@ -225,7 +234,9 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
225234 match ty. kind ( ) {
226235 ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Str => true ,
227236 ty:: Ref ( _, inner, _) if * inner. kind ( ) == ty:: Str => true ,
228- ty:: Array ( inner_type, _) | ty:: Slice ( inner_type) => is_recursively_primitive_type ( inner_type) ,
237+ ty:: Array ( inner_type, _) | ty:: Slice ( inner_type) => {
238+ is_recursively_primitive_type ( inner_type)
239+ }
229240 ty:: Tuple ( inner_types) => inner_types. types ( ) . all ( is_recursively_primitive_type) ,
230241 _ => false ,
231242 }
@@ -269,11 +280,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
269280/// removed.
270281pub fn peel_mid_ty_refs ( ty : Ty < ' _ > ) -> ( Ty < ' _ > , usize ) {
271282 fn peel ( ty : Ty < ' _ > , count : usize ) -> ( Ty < ' _ > , usize ) {
272- if let ty:: Ref ( _, ty, _) = ty. kind ( ) {
273- peel ( ty, count + 1 )
274- } else {
275- ( ty, count)
276- }
283+ if let ty:: Ref ( _, ty, _) = ty. kind ( ) { peel ( ty, count + 1 ) } else { ( ty, count) }
277284 }
278285 peel ( ty, 0 )
279286}
@@ -328,17 +335,18 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
328335 return false ;
329336 }
330337
331- substs_a
332- . iter ( )
333- . zip ( substs_b . iter ( ) )
334- . all ( | ( arg_a , arg_b ) | match ( arg_a . unpack ( ) , arg_b . unpack ( ) ) {
335- ( GenericArgKind :: Const ( inner_a ) , GenericArgKind :: Const ( inner_b ) ) => inner_a == inner_b ,
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+ }
336343 ( GenericArgKind :: Type ( type_a) , GenericArgKind :: Type ( type_b) ) => {
337344 same_type_and_consts ( type_a, type_b)
338- } ,
345+ }
339346 _ => true ,
340- } )
341- } ,
347+ }
348+ } )
349+ }
342350 _ => a == b,
343351 }
344352}
0 commit comments