Stop relying on rustc_type_ir in non-type-system crates
This commit is contained in:
@@ -270,14 +270,12 @@ fn structurally_same_type_impl<'tcx>(
|
||||
true
|
||||
} else {
|
||||
// Do a full, depth-first comparison between the two.
|
||||
use rustc_type_ir::TyKind::*;
|
||||
|
||||
let is_primitive_or_pointer =
|
||||
|ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), RawPtr(..) | Ref(..));
|
||||
|ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), ty::RawPtr(..) | ty::Ref(..));
|
||||
|
||||
ensure_sufficient_stack(|| {
|
||||
match (a.kind(), b.kind()) {
|
||||
(&Adt(a_def, a_gen_args), &Adt(b_def, b_gen_args)) => {
|
||||
(&ty::Adt(a_def, a_gen_args), &ty::Adt(b_def, b_gen_args)) => {
|
||||
// Only `repr(C)` types can be compared structurally.
|
||||
if !(a_def.repr().c() && b_def.repr().c()) {
|
||||
return false;
|
||||
@@ -308,30 +306,30 @@ fn structurally_same_type_impl<'tcx>(
|
||||
},
|
||||
)
|
||||
}
|
||||
(Array(a_ty, a_len), Array(b_ty, b_len)) => {
|
||||
(ty::Array(a_ty, a_len), ty::Array(b_ty, b_len)) => {
|
||||
// For arrays, we also check the length.
|
||||
a_len == b_len
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(Slice(a_ty), Slice(b_ty)) => {
|
||||
(ty::Slice(a_ty), ty::Slice(b_ty)) => {
|
||||
structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty, ckind)
|
||||
}
|
||||
(RawPtr(a_ty, a_mutbl), RawPtr(b_ty, b_mutbl)) => {
|
||||
(ty::RawPtr(a_ty, a_mutbl), ty::RawPtr(b_ty, b_mutbl)) => {
|
||||
a_mutbl == b_mutbl
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => {
|
||||
(ty::Ref(_a_region, a_ty, a_mut), ty::Ref(_b_region, b_ty, b_mut)) => {
|
||||
// For structural sameness, we don't need the region to be same.
|
||||
a_mut == b_mut
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(FnDef(..), FnDef(..)) => {
|
||||
(ty::FnDef(..), ty::FnDef(..)) => {
|
||||
let a_poly_sig = a.fn_sig(tcx);
|
||||
let b_poly_sig = b.fn_sig(tcx);
|
||||
|
||||
@@ -354,35 +352,38 @@ fn structurally_same_type_impl<'tcx>(
|
||||
ckind,
|
||||
)
|
||||
}
|
||||
(Tuple(..), Tuple(..)) => {
|
||||
(ty::Tuple(..), ty::Tuple(..)) => {
|
||||
// Tuples are not `repr(C)` so these cannot be compared structurally.
|
||||
false
|
||||
}
|
||||
// For these, it's not quite as easy to define structural-sameness quite so easily.
|
||||
// For the purposes of this lint, take the conservative approach and mark them as
|
||||
// not structurally same.
|
||||
(Dynamic(..), Dynamic(..))
|
||||
| (Error(..), Error(..))
|
||||
| (Closure(..), Closure(..))
|
||||
| (Coroutine(..), Coroutine(..))
|
||||
| (CoroutineWitness(..), CoroutineWitness(..))
|
||||
| (Alias(ty::Projection, ..), Alias(ty::Projection, ..))
|
||||
| (Alias(ty::Inherent, ..), Alias(ty::Inherent, ..))
|
||||
| (Alias(ty::Opaque, ..), Alias(ty::Opaque, ..)) => false,
|
||||
(ty::Dynamic(..), ty::Dynamic(..))
|
||||
| (ty::Error(..), ty::Error(..))
|
||||
| (ty::Closure(..), ty::Closure(..))
|
||||
| (ty::Coroutine(..), ty::Coroutine(..))
|
||||
| (ty::CoroutineWitness(..), ty::CoroutineWitness(..))
|
||||
| (ty::Alias(ty::Projection, ..), ty::Alias(ty::Projection, ..))
|
||||
| (ty::Alias(ty::Inherent, ..), ty::Alias(ty::Inherent, ..))
|
||||
| (ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => false,
|
||||
|
||||
// These definitely should have been caught above.
|
||||
(Bool, Bool) | (Char, Char) | (Never, Never) | (Str, Str) => unreachable!(),
|
||||
(ty::Bool, ty::Bool)
|
||||
| (ty::Char, ty::Char)
|
||||
| (ty::Never, ty::Never)
|
||||
| (ty::Str, ty::Str) => unreachable!(),
|
||||
|
||||
// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
|
||||
// enum layout optimisation is being applied.
|
||||
(Adt(..) | Pat(..), _) if is_primitive_or_pointer(b) => {
|
||||
(ty::Adt(..) | ty::Pat(..), _) if is_primitive_or_pointer(b) => {
|
||||
if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a, ckind) {
|
||||
a_inner == b
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(_, Adt(..) | Pat(..)) if is_primitive_or_pointer(a) => {
|
||||
(_, ty::Adt(..) | ty::Pat(..)) if is_primitive_or_pointer(a) => {
|
||||
if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b, ckind) {
|
||||
b_inner == a
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user