@@ -128,7 +128,9 @@ pub fn implements_trait<'tcx>(
128
128
return false ;
129
129
}
130
130
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 ( )
132
134
}
133
135
134
136
/// Checks whether this type implements `Drop`.
@@ -144,22 +146,26 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
144
146
match ty. kind ( ) {
145
147
ty:: Adt ( adt, _) => must_use_attr ( cx. tcx . get_attrs ( adt. did ) ) . is_some ( ) ,
146
148
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, _) => {
148
153
// for the Array case we don't need to care for the len == 0 case
149
154
// because we don't want to lint functions returning empty arrays
150
155
is_must_use_ty ( cx, * ty)
151
- } ,
156
+ }
152
157
ty:: Tuple ( substs) => substs. types ( ) . any ( |ty| is_must_use_ty ( cx, ty) ) ,
153
158
ty:: Opaque ( ref def_id, _) => {
154
159
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
+ {
156
162
if must_use_attr ( cx. tcx . get_attrs ( trait_predicate. trait_ref . def_id ) ) . is_some ( ) {
157
163
return true ;
158
164
}
159
165
}
160
166
}
161
167
false
162
- } ,
168
+ }
163
169
ty:: Dynamic ( binder, _) => {
164
170
for predicate in binder. iter ( ) {
165
171
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 {
169
175
}
170
176
}
171
177
false
172
- } ,
178
+ }
173
179
_ => false ,
174
180
}
175
181
}
@@ -179,7 +185,11 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
179
185
// not succeed
180
186
/// Checks if `Ty` is normalizable. This function is useful
181
187
/// 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 {
183
193
is_normalizable_helper ( cx, param_env, ty, & mut FxHashMap :: default ( ) )
184
194
}
185
195
@@ -199,15 +209,14 @@ fn is_normalizable_helper<'tcx>(
199
209
if infcx. at ( & cause, param_env) . normalize ( ty) . is_ok ( ) {
200
210
match ty. kind ( ) {
201
211
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
+ } )
206
215
} ) ,
207
216
_ => ty. walk ( ) . all ( |generic_arg| match generic_arg. unpack ( ) {
208
217
GenericArgKind :: Type ( inner_ty) if inner_ty != ty => {
209
218
is_normalizable_helper ( cx, param_env, inner_ty, cache)
210
- } ,
219
+ }
211
220
_ => true , // if inner_ty == ty, we've already checked it
212
221
} ) ,
213
222
}
@@ -225,7 +234,9 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
225
234
match ty. kind ( ) {
226
235
ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Str => true ,
227
236
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
+ }
229
240
ty:: Tuple ( inner_types) => inner_types. types ( ) . all ( is_recursively_primitive_type) ,
230
241
_ => false ,
231
242
}
@@ -269,11 +280,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
269
280
/// removed.
270
281
pub fn peel_mid_ty_refs ( ty : Ty < ' _ > ) -> ( Ty < ' _ > , usize ) {
271
282
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) }
277
284
}
278
285
peel ( ty, 0 )
279
286
}
@@ -328,17 +335,18 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
328
335
return false ;
329
336
}
330
337
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
+ }
336
343
( GenericArgKind :: Type ( type_a) , GenericArgKind :: Type ( type_b) ) => {
337
344
same_type_and_consts ( type_a, type_b)
338
- } ,
345
+ }
339
346
_ => true ,
340
- } )
341
- } ,
347
+ }
348
+ } )
349
+ }
342
350
_ => a == b,
343
351
}
344
352
}
0 commit comments