@@ -265,8 +265,6 @@ fn structurally_same_type_impl<'tcx>(
265265 } else {
266266 // Do a full, depth-first comparison between the two.
267267 use rustc_type_ir:: TyKind :: * ;
268- let a_kind = a. kind ( ) ;
269- let b_kind = b. kind ( ) ;
270268
271269 let compare_layouts = |a, b| -> Result < bool , & ' tcx LayoutError < ' tcx > > {
272270 debug ! ( "compare_layouts({:?}, {:?})" , a, b) ;
@@ -281,12 +279,11 @@ fn structurally_same_type_impl<'tcx>(
281279 Ok ( a_layout == b_layout)
282280 } ;
283281
284- #[ allow( rustc:: usage_of_ty_tykind) ]
285282 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 ( ..) ) ;
287284
288285 ensure_sufficient_stack ( || {
289- match ( a_kind , b_kind ) {
286+ match ( a . kind ( ) , b . kind ( ) ) {
290287 ( Adt ( a_def, _) , Adt ( b_def, _) ) => {
291288 // We can immediately rule out these types as structurally same if
292289 // their layouts differ.
@@ -382,17 +379,21 @@ fn structurally_same_type_impl<'tcx>(
382379
383380 // An Adt and a primitive or pointer type. This can be FFI-safe if non-null
384381 // 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
392385 } else {
393386 compare_layouts ( a, b) . unwrap_or ( false )
394387 }
395388 }
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+
396397 // Otherwise, just compare the layouts. This may fail to lint for some
397398 // incompatible types, but at the very least, will stop reads into
398399 // uninitialised memory.
0 commit comments