@@ -265,8 +265,6 @@ fn structurally_same_type_impl<'tcx>(
265
265
} else {
266
266
// Do a full, depth-first comparison between the two.
267
267
use rustc_type_ir:: TyKind :: * ;
268
- let a_kind = a. kind ( ) ;
269
- let b_kind = b. kind ( ) ;
270
268
271
269
let compare_layouts = |a, b| -> Result < bool , & ' tcx LayoutError < ' tcx > > {
272
270
debug ! ( "compare_layouts({:?}, {:?})" , a, b) ;
@@ -281,12 +279,11 @@ fn structurally_same_type_impl<'tcx>(
281
279
Ok ( a_layout == b_layout)
282
280
} ;
283
281
284
- #[ allow( rustc:: usage_of_ty_tykind) ]
285
282
let is_primitive_or_pointer =
286
- |kind : & ty:: TyKind < ' _ > | kind . is_primitive ( ) || matches ! ( kind, RawPtr ( ..) | Ref ( ..) ) ;
283
+ |ty : Ty < ' tcx > | ty . is_primitive ( ) || matches ! ( ty . kind( ) , RawPtr ( ..) | Ref ( ..) ) ;
287
284
288
285
ensure_sufficient_stack ( || {
289
- match ( a_kind , b_kind ) {
286
+ match ( a . kind ( ) , b . kind ( ) ) {
290
287
( Adt ( a_def, _) , Adt ( b_def, _) ) => {
291
288
// We can immediately rule out these types as structurally same if
292
289
// their layouts differ.
@@ -382,17 +379,21 @@ fn structurally_same_type_impl<'tcx>(
382
379
383
380
// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
384
381
// enum layout optimisation is being applied.
385
- ( Adt ( ..) , other_kind) | ( other_kind, Adt ( ..) )
386
- if is_primitive_or_pointer ( other_kind) =>
387
- {
388
- let ( primitive, adt) =
389
- if is_primitive_or_pointer ( a. kind ( ) ) { ( a, b) } else { ( b, a) } ;
390
- if let Some ( ty) = types:: repr_nullable_ptr ( tcx, param_env, adt, ckind) {
391
- ty == primitive
382
+ ( Adt ( ..) , _) if is_primitive_or_pointer ( b) => {
383
+ if let Some ( ty) = types:: repr_nullable_ptr ( tcx, param_env, a, ckind) {
384
+ ty == b
392
385
} else {
393
386
compare_layouts ( a, b) . unwrap_or ( false )
394
387
}
395
388
}
389
+ ( _, Adt ( ..) ) if is_primitive_or_pointer ( a) => {
390
+ if let Some ( ty) = types:: repr_nullable_ptr ( tcx, param_env, b, ckind) {
391
+ ty == a
392
+ } else {
393
+ compare_layouts ( a, b) . unwrap_or ( false )
394
+ }
395
+ }
396
+
396
397
// Otherwise, just compare the layouts. This may fail to lint for some
397
398
// incompatible types, but at the very least, will stop reads into
398
399
// uninitialised memory.
0 commit comments