about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-08-31 10:08:53 +0200
committerGitHub <noreply@github.com>2024-08-31 10:08:53 +0200
commit2a321e14a5c041a7accf4c166c8c0a6860ce2292 (patch)
treef330c744145afd74244e0f0d98fac792a05287a7
parent9f3ce40718a2df2adec1fcf94506df7da4432a83 (diff)
parent42a901acd9c9d3a0c9ca7adf2470b789f9c81a5b (diff)
downloadrust-2a321e14a5c041a7accf4c166c8c0a6860ce2292.tar.gz
rust-2a321e14a5c041a7accf4c166c8c0a6860ce2292.zip
Rollup merge of #129527 - compiler-errors:lint-nit, r=Nadrieril
Don't use `TyKind` in a lint

Allows us to remove an inherent method from `TyKind` from the type ir crate.
-rw-r--r--compiler/rustc_lint/src/foreign_modules.rs25
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs2
-rw-r--r--compiler/rustc_type_ir/src/ty_kind.rs7
3 files changed, 14 insertions, 20 deletions
diff --git a/compiler/rustc_lint/src/foreign_modules.rs b/compiler/rustc_lint/src/foreign_modules.rs
index 5da1cbc2283..a60fc0ffbbb 100644
--- a/compiler/rustc_lint/src/foreign_modules.rs
+++ b/compiler/rustc_lint/src/foreign_modules.rs
@@ -265,8 +265,6 @@ fn structurally_same_type_impl<'tcx>(
     } else {
         // Do a full, depth-first comparison between the two.
         use rustc_type_ir::TyKind::*;
-        let a_kind = a.kind();
-        let b_kind = b.kind();
 
         let compare_layouts = |a, b| -> Result<bool, &'tcx LayoutError<'tcx>> {
             debug!("compare_layouts({:?}, {:?})", a, b);
@@ -281,12 +279,11 @@ fn structurally_same_type_impl<'tcx>(
             Ok(a_layout == b_layout)
         };
 
-        #[allow(rustc::usage_of_ty_tykind)]
         let is_primitive_or_pointer =
-            |kind: &ty::TyKind<'_>| kind.is_primitive() || matches!(kind, RawPtr(..) | Ref(..));
+            |ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), RawPtr(..) | Ref(..));
 
         ensure_sufficient_stack(|| {
-            match (a_kind, b_kind) {
+            match (a.kind(), b.kind()) {
                 (Adt(a_def, _), Adt(b_def, _)) => {
                     // We can immediately rule out these types as structurally same if
                     // their layouts differ.
@@ -382,17 +379,21 @@ fn structurally_same_type_impl<'tcx>(
 
                 // An Adt and a primitive or pointer type. This can be FFI-safe if non-null
                 // enum layout optimisation is being applied.
-                (Adt(..), other_kind) | (other_kind, Adt(..))
-                    if is_primitive_or_pointer(other_kind) =>
-                {
-                    let (primitive, adt) =
-                        if is_primitive_or_pointer(a.kind()) { (a, b) } else { (b, a) };
-                    if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, adt, ckind) {
-                        ty == primitive
+                (Adt(..), _) if is_primitive_or_pointer(b) => {
+                    if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, a, ckind) {
+                        ty == b
                     } else {
                         compare_layouts(a, b).unwrap_or(false)
                     }
                 }
+                (_, Adt(..)) if is_primitive_or_pointer(a) => {
+                    if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, b, ckind) {
+                        ty == a
+                    } else {
+                        compare_layouts(a, b).unwrap_or(false)
+                    }
+                }
+
                 // Otherwise, just compare the layouts. This may fail to lint for some
                 // incompatible types, but at the very least, will stop reads into
                 // uninitialised memory.
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index d60bfb9faa1..c6621a7a643 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -1000,7 +1000,7 @@ impl<'tcx> Ty<'tcx> {
 
     #[inline]
     pub fn is_primitive(self) -> bool {
-        self.kind().is_primitive()
+        matches!(self.kind(), Bool | Char | Int(_) | Uint(_) | Float(_))
     }
 
     #[inline]
diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs
index 328b6739d97..80c3565911e 100644
--- a/compiler/rustc_type_ir/src/ty_kind.rs
+++ b/compiler/rustc_type_ir/src/ty_kind.rs
@@ -254,13 +254,6 @@ pub enum TyKind<I: Interner> {
     Error(I::ErrorGuaranteed),
 }
 
-impl<I: Interner> TyKind<I> {
-    #[inline]
-    pub fn is_primitive(&self) -> bool {
-        matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
-    }
-}
-
 // This is manually implemented because a derive would require `I: Debug`
 impl<I: Interner> fmt::Debug for TyKind<I> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {