1use std::fmt::Debug;
2use std::hash::Hash;
3use std::iter;
4use std::marker::PhantomData;
5
6use rustc_ast_ir::Mutability;
7#[cfg(feature = "nightly")]
8use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash};
9
10use crate::inherent::*;
11use crate::visit::TypeVisitableExt as _;
12use crate::{self as ty, Const, Interner};
13
14#[derive(#[automatically_derived]impl<DefId: ::core::clone::Clone> ::core::clone::Clone
for SimplifiedType<DefId> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Bool => SimplifiedType::Bool,
Self::Char => SimplifiedType::Char,
Self::Int(__self_0) =>
SimplifiedType::Int(::core::clone::Clone::clone(__self_0)),
Self::Uint(__self_0) =>
SimplifiedType::Uint(::core::clone::Clone::clone(__self_0)),
Self::Float(__self_0) =>
SimplifiedType::Float(::core::clone::Clone::clone(__self_0)),
Self::Adt(__self_0) =>
SimplifiedType::Adt(::core::clone::Clone::clone(__self_0)),
Self::Foreign(__self_0) =>
SimplifiedType::Foreign(::core::clone::Clone::clone(__self_0)),
Self::Str => SimplifiedType::Str,
Self::Array => SimplifiedType::Array,
Self::Slice => SimplifiedType::Slice,
Self::Ref(__self_0) =>
SimplifiedType::Ref(::core::clone::Clone::clone(__self_0)),
Self::Ptr(__self_0) =>
SimplifiedType::Ptr(::core::clone::Clone::clone(__self_0)),
Self::Never => SimplifiedType::Never,
Self::Tuple(__self_0) =>
SimplifiedType::Tuple(::core::clone::Clone::clone(__self_0)),
Self::MarkerTraitObject => SimplifiedType::MarkerTraitObject,
Self::Trait(__self_0) =>
SimplifiedType::Trait(::core::clone::Clone::clone(__self_0)),
Self::Closure(__self_0) =>
SimplifiedType::Closure(::core::clone::Clone::clone(__self_0)),
Self::Coroutine(__self_0) =>
SimplifiedType::Coroutine(::core::clone::Clone::clone(__self_0)),
Self::CoroutineWitness(__self_0) =>
SimplifiedType::CoroutineWitness(::core::clone::Clone::clone(__self_0)),
Self::Function(__self_0) =>
SimplifiedType::Function(::core::clone::Clone::clone(__self_0)),
Self::View(__self_0) =>
SimplifiedType::View(::core::clone::Clone::clone(__self_0)),
Self::UnsafeBinder => SimplifiedType::UnsafeBinder,
Self::Placeholder => SimplifiedType::Placeholder,
Self::Error => SimplifiedType::Error,
}
}
}Clone, #[automatically_derived]impl<DefId: ::core::marker::Copy> ::core::marker::Copy
for SimplifiedType<DefId> {
}Copy, #[automatically_derived]impl<DefId: ::core::fmt::Debug> ::core::fmt::Debug for
SimplifiedType<DefId> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Bool => ::core::fmt::Formatter::write_str(f, "Bool"),
Self::Char => ::core::fmt::Formatter::write_str(f, "Char"),
Self::Int(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Int",
&__self_0),
Self::Uint(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Uint",
&__self_0),
Self::Float(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Float",
&__self_0),
Self::Adt(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Adt",
&__self_0),
Self::Foreign(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Foreign", &__self_0),
Self::Str => ::core::fmt::Formatter::write_str(f, "Str"),
Self::Array => ::core::fmt::Formatter::write_str(f, "Array"),
Self::Slice => ::core::fmt::Formatter::write_str(f, "Slice"),
Self::Ref(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Ref",
&__self_0),
Self::Ptr(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Ptr",
&__self_0),
Self::Never => ::core::fmt::Formatter::write_str(f, "Never"),
Self::Tuple(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Tuple",
&__self_0),
Self::MarkerTraitObject =>
::core::fmt::Formatter::write_str(f, "MarkerTraitObject"),
Self::Trait(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Trait",
&__self_0),
Self::Closure(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Closure", &__self_0),
Self::Coroutine(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Coroutine", &__self_0),
Self::CoroutineWitness(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CoroutineWitness", &__self_0),
Self::Function(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Function", &__self_0),
Self::View(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "View",
&__self_0),
Self::UnsafeBinder =>
::core::fmt::Formatter::write_str(f, "UnsafeBinder"),
Self::Placeholder =>
::core::fmt::Formatter::write_str(f, "Placeholder"),
Self::Error => ::core::fmt::Formatter::write_str(f, "Error"),
}
}
}Debug, #[automatically_derived]impl<DefId: ::core::cmp::PartialEq>
::core::marker::StructuralPartialEq for SimplifiedType<DefId> {
}
#[automatically_derived]impl<DefId: ::core::cmp::PartialEq>
::core::cmp::PartialEq for SimplifiedType<DefId> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Int(__self_0), Self::Int(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Uint(__self_0), Self::Uint(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Float(__self_0), Self::Float(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Adt(__self_0), Self::Adt(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Foreign(__self_0), Self::Foreign(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Ref(__self_0), Self::Ref(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Ptr(__self_0), Self::Ptr(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Tuple(__self_0), Self::Tuple(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Trait(__self_0), Self::Trait(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Closure(__self_0), Self::Closure(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Coroutine(__self_0), Self::Coroutine(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::CoroutineWitness(__self_0),
Self::CoroutineWitness(__arg1_0)) => __self_0 == __arg1_0,
(Self::Function(__self_0), Self::Function(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::View(__self_0), Self::View(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl<DefId: ::core::cmp::Eq> ::core::cmp::Eq for
SimplifiedType<DefId> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ty::IntTy>;
let _: ::core::cmp::AssertParamIsEq<ty::UintTy>;
let _: ::core::cmp::AssertParamIsEq<ty::FloatTy>;
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<Mutability>;
let _: ::core::cmp::AssertParamIsEq<usize>;
}
}Eq, #[automatically_derived]impl<DefId: ::core::hash::Hash> ::core::hash::Hash for
SimplifiedType<DefId> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Int(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::Uint(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::Float(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Adt(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::Foreign(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Ref(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::Ptr(__self_0) => ::core::hash::Hash::hash(__self_0, state),
Self::Tuple(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Trait(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Closure(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Coroutine(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::CoroutineWitness(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Function(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::View(__self_0) => ::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash)]
16#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<DefId, __E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for SimplifiedType<DefId> where
DefId: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
SimplifiedType::Bool => { 0usize }
SimplifiedType::Char => { 1usize }
SimplifiedType::Int(ref __binding_0) => { 2usize }
SimplifiedType::Uint(ref __binding_0) => { 3usize }
SimplifiedType::Float(ref __binding_0) => { 4usize }
SimplifiedType::Adt(ref __binding_0) => { 5usize }
SimplifiedType::Foreign(ref __binding_0) => { 6usize }
SimplifiedType::Str => { 7usize }
SimplifiedType::Array => { 8usize }
SimplifiedType::Slice => { 9usize }
SimplifiedType::Ref(ref __binding_0) => { 10usize }
SimplifiedType::Ptr(ref __binding_0) => { 11usize }
SimplifiedType::Never => { 12usize }
SimplifiedType::Tuple(ref __binding_0) => { 13usize }
SimplifiedType::MarkerTraitObject => { 14usize }
SimplifiedType::Trait(ref __binding_0) => { 15usize }
SimplifiedType::Closure(ref __binding_0) => { 16usize }
SimplifiedType::Coroutine(ref __binding_0) => { 17usize }
SimplifiedType::CoroutineWitness(ref __binding_0) => {
18usize
}
SimplifiedType::Function(ref __binding_0) => { 19usize }
SimplifiedType::View(ref __binding_0) => { 20usize }
SimplifiedType::UnsafeBinder => { 21usize }
SimplifiedType::Placeholder => { 22usize }
SimplifiedType::Error => { 23usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
SimplifiedType::Bool => {}
SimplifiedType::Char => {}
SimplifiedType::Int(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Uint(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Float(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Adt(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Foreign(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Str => {}
SimplifiedType::Array => {}
SimplifiedType::Slice => {}
SimplifiedType::Ref(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Ptr(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Never => {}
SimplifiedType::Tuple(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::MarkerTraitObject => {}
SimplifiedType::Trait(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Closure(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Coroutine(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::CoroutineWitness(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::Function(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::View(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
SimplifiedType::UnsafeBinder => {}
SimplifiedType::Placeholder => {}
SimplifiedType::Error => {}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<DefId, __D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for SimplifiedType<DefId> where
DefId: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { SimplifiedType::Bool }
1usize => { SimplifiedType::Char }
2usize => {
SimplifiedType::Int(::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
SimplifiedType::Uint(::rustc_serialize::Decodable::decode(__decoder))
}
4usize => {
SimplifiedType::Float(::rustc_serialize::Decodable::decode(__decoder))
}
5usize => {
SimplifiedType::Adt(::rustc_serialize::Decodable::decode(__decoder))
}
6usize => {
SimplifiedType::Foreign(::rustc_serialize::Decodable::decode(__decoder))
}
7usize => { SimplifiedType::Str }
8usize => { SimplifiedType::Array }
9usize => { SimplifiedType::Slice }
10usize => {
SimplifiedType::Ref(::rustc_serialize::Decodable::decode(__decoder))
}
11usize => {
SimplifiedType::Ptr(::rustc_serialize::Decodable::decode(__decoder))
}
12usize => { SimplifiedType::Never }
13usize => {
SimplifiedType::Tuple(::rustc_serialize::Decodable::decode(__decoder))
}
14usize => { SimplifiedType::MarkerTraitObject }
15usize => {
SimplifiedType::Trait(::rustc_serialize::Decodable::decode(__decoder))
}
16usize => {
SimplifiedType::Closure(::rustc_serialize::Decodable::decode(__decoder))
}
17usize => {
SimplifiedType::Coroutine(::rustc_serialize::Decodable::decode(__decoder))
}
18usize => {
SimplifiedType::CoroutineWitness(::rustc_serialize::Decodable::decode(__decoder))
}
19usize => {
SimplifiedType::Function(::rustc_serialize::Decodable::decode(__decoder))
}
20usize => {
SimplifiedType::View(::rustc_serialize::Decodable::decode(__decoder))
}
21usize => { SimplifiedType::UnsafeBinder }
22usize => { SimplifiedType::Placeholder }
23usize => { SimplifiedType::Error }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `SimplifiedType`, expected 0..24, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl<DefId> ::rustc_data_structures::stable_hash::StableHash for
SimplifiedType<DefId> where
DefId: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
SimplifiedType::Bool => 0u8.stable_hash(__hcx, __hasher),
SimplifiedType::Char => 1u8.stable_hash(__hcx, __hasher),
SimplifiedType::Int(ref __binding_0) =>
2u8.stable_hash(__hcx, __hasher),
SimplifiedType::Uint(ref __binding_0) =>
3u8.stable_hash(__hcx, __hasher),
SimplifiedType::Float(ref __binding_0) =>
4u8.stable_hash(__hcx, __hasher),
SimplifiedType::Adt(ref __binding_0) =>
5u8.stable_hash(__hcx, __hasher),
SimplifiedType::Foreign(ref __binding_0) =>
6u8.stable_hash(__hcx, __hasher),
SimplifiedType::Str => 7u8.stable_hash(__hcx, __hasher),
SimplifiedType::Array => 8u8.stable_hash(__hcx, __hasher),
SimplifiedType::Slice => 9u8.stable_hash(__hcx, __hasher),
SimplifiedType::Ref(ref __binding_0) =>
10u8.stable_hash(__hcx, __hasher),
SimplifiedType::Ptr(ref __binding_0) =>
11u8.stable_hash(__hcx, __hasher),
SimplifiedType::Never => 12u8.stable_hash(__hcx, __hasher),
SimplifiedType::Tuple(ref __binding_0) =>
13u8.stable_hash(__hcx, __hasher),
SimplifiedType::MarkerTraitObject =>
14u8.stable_hash(__hcx, __hasher),
SimplifiedType::Trait(ref __binding_0) =>
15u8.stable_hash(__hcx, __hasher),
SimplifiedType::Closure(ref __binding_0) =>
16u8.stable_hash(__hcx, __hasher),
SimplifiedType::Coroutine(ref __binding_0) =>
17u8.stable_hash(__hcx, __hasher),
SimplifiedType::CoroutineWitness(ref __binding_0) =>
18u8.stable_hash(__hcx, __hasher),
SimplifiedType::Function(ref __binding_0) =>
19u8.stable_hash(__hcx, __hasher),
SimplifiedType::View(ref __binding_0) =>
20u8.stable_hash(__hcx, __hasher),
SimplifiedType::UnsafeBinder =>
21u8.stable_hash(__hcx, __hasher),
SimplifiedType::Placeholder =>
22u8.stable_hash(__hcx, __hasher),
SimplifiedType::Error => 23u8.stable_hash(__hcx, __hasher),
}
match *self {
SimplifiedType::Bool => {}
SimplifiedType::Char => {}
SimplifiedType::Int(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Uint(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Float(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Adt(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Foreign(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Str => {}
SimplifiedType::Array => {}
SimplifiedType::Slice => {}
SimplifiedType::Ref(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Ptr(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Never => {}
SimplifiedType::Tuple(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::MarkerTraitObject => {}
SimplifiedType::Trait(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Closure(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Coroutine(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::CoroutineWitness(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::Function(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::View(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
SimplifiedType::UnsafeBinder => {}
SimplifiedType::Placeholder => {}
SimplifiedType::Error => {}
}
}
}
};StableHash))]
17pub enum SimplifiedType<DefId> {
18 Bool,
19 Char,
20 Int(ty::IntTy),
21 Uint(ty::UintTy),
22 Float(ty::FloatTy),
23 Adt(DefId),
24 Foreign(DefId),
25 Str,
26 Array,
27 Slice,
28 Ref(Mutability),
29 Ptr(Mutability),
30 Never,
31 Tuple(usize),
32 MarkerTraitObject,
35 Trait(DefId),
36 Closure(DefId),
37 Coroutine(DefId),
38 CoroutineWitness(DefId),
39 Function(usize),
40 View(DefId),
41 UnsafeBinder,
42 Placeholder,
43 Error,
44}
45
46#[derive(#[automatically_derived]impl ::core::marker::StructuralPartialEq for
TreatParams {
}
#[automatically_derived]impl ::core::cmp::PartialEq for TreatParams {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for TreatParams { }Eq, #[automatically_derived]impl ::core::fmt::Debug for TreatParams {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
TreatParams::InstantiateWithInfer => "InstantiateWithInfer",
TreatParams::AsRigid => "AsRigid",
})
}
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for TreatParams {
}
#[automatically_derived]impl ::core::clone::Clone for TreatParams {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for TreatParams { }Copy)]
59pub enum TreatParams {
60 InstantiateWithInfer,
63 AsRigid,
72}
73
74pub fn simplify_type<I: Interner>(
96 cx: I,
97 ty: I::Ty,
98 treat_params: TreatParams,
99) -> Option<SimplifiedType<I::DefId>> {
100 match ty.kind() {
101 ty::Bool => Some(SimplifiedType::Bool),
102 ty::Char => Some(SimplifiedType::Char),
103 ty::Int(int_type) => Some(SimplifiedType::Int(int_type)),
104 ty::Uint(uint_type) => Some(SimplifiedType::Uint(uint_type)),
105 ty::Float(float_type) => Some(SimplifiedType::Float(float_type)),
106 ty::Adt(def, _) => Some(SimplifiedType::Adt(def.def_id().into())),
107 ty::Str => Some(SimplifiedType::Str),
108 ty::Array(..) => Some(SimplifiedType::Array),
109 ty::Slice(..) => Some(SimplifiedType::Slice),
110 ty::Pat(ty, ..) => simplify_type(cx, ty, treat_params),
111 ty::RawPtr(_, mutbl) => Some(SimplifiedType::Ptr(mutbl)),
112 ty::Dynamic(trait_info, ..) => match trait_info.principal_def_id() {
113 Some(principal_def_id) if !cx.trait_is_auto(principal_def_id) => {
114 Some(SimplifiedType::Trait(principal_def_id.into()))
115 }
116 _ => Some(SimplifiedType::MarkerTraitObject),
117 },
118 ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)),
119 ty::FnDef(def_id, _) => Some(SimplifiedType::Closure(def_id.into())),
120 ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id.into())),
121 ty::CoroutineClosure(def_id, _) => Some(SimplifiedType::Closure(def_id.into())),
122 ty::Coroutine(def_id, _) => Some(SimplifiedType::Coroutine(def_id.into())),
123 ty::CoroutineWitness(def_id, _) => Some(SimplifiedType::CoroutineWitness(def_id.into())),
124 ty::Never => Some(SimplifiedType::Never),
125 ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())),
126 ty::FnPtr(sig_tys, _hdr) => {
127 Some(SimplifiedType::Function(sig_tys.skip_binder().inputs().len()))
128 }
129 ty::UnsafeBinder(_) => Some(SimplifiedType::UnsafeBinder),
130 ty::Placeholder(..) => Some(SimplifiedType::Placeholder),
131 ty::Param(_) => match treat_params {
132 TreatParams::AsRigid => Some(SimplifiedType::Placeholder),
133 TreatParams::InstantiateWithInfer => None,
134 },
135 ty::Alias(..) => match treat_params {
136 TreatParams::AsRigid
139 if !ty.has_non_region_infer() || cx.next_trait_solver_globally() =>
140 {
141 Some(SimplifiedType::Placeholder)
142 }
143 TreatParams::AsRigid | TreatParams::InstantiateWithInfer => None,
144 },
145 ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id.into())),
146 ty::View(def, _, _) => Some(SimplifiedType::View(def.def_id().into())),
147 ty::Error(_) => Some(SimplifiedType::Error),
148 ty::Bound(..) | ty::Infer(_) => None,
149 }
150}
151
152impl<DefId> SimplifiedType<DefId> {
153 pub fn def(self) -> Option<DefId> {
154 match self {
155 SimplifiedType::Adt(d)
156 | SimplifiedType::Foreign(d)
157 | SimplifiedType::Trait(d)
158 | SimplifiedType::Closure(d)
159 | SimplifiedType::Coroutine(d)
160 | SimplifiedType::CoroutineWitness(d) => Some(d),
161 _ => None,
162 }
163 }
164}
165
166#[derive(#[automatically_derived]impl<I: ::core::fmt::Debug + Interner, const
INSTANTIATE_LHS_WITH_INFER : bool, const INSTANTIATE_RHS_WITH_INFER :
bool> ::core::fmt::Debug for
DeepRejectCtxt<I, INSTANTIATE_LHS_WITH_INFER, INSTANTIATE_RHS_WITH_INFER>
{
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DeepRejectCtxt _interner", &&self._interner)
}
}Debug, #[automatically_derived]impl<I: ::core::clone::Clone + Interner, const
INSTANTIATE_LHS_WITH_INFER : bool, const INSTANTIATE_RHS_WITH_INFER :
bool> ::core::clone::Clone for
DeepRejectCtxt<I, INSTANTIATE_LHS_WITH_INFER, INSTANTIATE_RHS_WITH_INFER>
{
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
DeepRejectCtxt {
_interner: ::core::clone::Clone::clone(&self._interner),
}
}
}Clone, #[automatically_derived]impl<I: ::core::marker::Copy + Interner, const
INSTANTIATE_LHS_WITH_INFER : bool, const INSTANTIATE_RHS_WITH_INFER :
bool> ::core::marker::Copy for
DeepRejectCtxt<I, INSTANTIATE_LHS_WITH_INFER, INSTANTIATE_RHS_WITH_INFER>
{
}Copy)]
177pub struct DeepRejectCtxt<
178 I: Interner,
179 const INSTANTIATE_LHS_WITH_INFER: bool,
180 const INSTANTIATE_RHS_WITH_INFER: bool,
181> {
182 _interner: PhantomData<I>,
183}
184
185impl<I: Interner> DeepRejectCtxt<I, false, false> {
186 pub fn relate_rigid_rigid(_interner: I) -> DeepRejectCtxt<I, false, false> {
188 DeepRejectCtxt { _interner: PhantomData }
189 }
190}
191
192impl<I: Interner> DeepRejectCtxt<I, true, true> {
193 pub fn relate_infer_infer(_interner: I) -> DeepRejectCtxt<I, true, true> {
195 DeepRejectCtxt { _interner: PhantomData }
196 }
197}
198
199impl<I: Interner> DeepRejectCtxt<I, false, true> {
200 pub fn relate_rigid_infer(_interner: I) -> DeepRejectCtxt<I, false, true> {
202 DeepRejectCtxt { _interner: PhantomData }
203 }
204}
205
206impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_WITH_INFER: bool>
207 DeepRejectCtxt<I, INSTANTIATE_LHS_WITH_INFER, INSTANTIATE_RHS_WITH_INFER>
208{
209 const STARTING_DEPTH: usize = 8;
212
213 pub fn args_may_unify(
214 self,
215 obligation_args: I::GenericArgs,
216 impl_args: I::GenericArgs,
217 ) -> bool {
218 self.args_may_unify_inner(obligation_args, impl_args, Self::STARTING_DEPTH)
219 }
220
221 pub fn types_may_unify(self, lhs: I::Ty, rhs: I::Ty) -> bool {
222 self.types_may_unify_inner(lhs, rhs, Self::STARTING_DEPTH)
223 }
224
225 pub fn types_may_unify_with_depth(self, lhs: I::Ty, rhs: I::Ty, depth_limit: usize) -> bool {
226 self.types_may_unify_inner(lhs, rhs, depth_limit)
227 }
228
229 fn args_may_unify_inner(
230 self,
231 obligation_args: I::GenericArgs,
232 impl_args: I::GenericArgs,
233 depth: usize,
234 ) -> bool {
235 let may_unify = |(obl, imp): (I::GenericArg, I::GenericArg)| {
239 match obl.kind() {
240 ty::GenericArgKind::Lifetime(_) => {
242 if true {
if !#[allow(non_exhaustive_omitted_patterns)] match imp.kind() {
ty::GenericArgKind::Lifetime(_) => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(imp.kind(), ty::GenericArgKind::Lifetime(_))")
};
};debug_assert!(matches!(imp.kind(), ty::GenericArgKind::Lifetime(_)));
243 true
244 }
245 ty::GenericArgKind::Type(obl) if let ty::GenericArgKind::Type(imp) = imp.kind() => {
246 self.types_may_unify_inner(obl, imp, depth)
247 }
248 ty::GenericArgKind::Const(obl)
249 if let ty::GenericArgKind::Const(imp) = imp.kind() =>
250 {
251 self.consts_may_unify_inner(obl, imp)
252 }
253 _ => {
::core::panicking::panic_fmt(format_args!("kind mismatch: {0:?} {1:?}",
obl, imp));
}panic!("kind mismatch: {obl:?} {imp:?}"),
254 }
255 };
256
257 if let ([obl], [imp]) = (obligation_args.as_slice(), impl_args.as_slice()) {
259 return may_unify((*obl, *imp));
260 }
261
262 iter::zip(obligation_args.iter(), impl_args.iter()).all(may_unify)
263 }
264
265 fn types_may_unify_inner(self, lhs: I::Ty, rhs: I::Ty, depth: usize) -> bool {
266 if lhs == rhs {
267 return true;
268 }
269
270 match rhs.kind() {
271 ty::Param(_) | ty::Alias(ty::IsRigid::Yes, _) => {
274 if INSTANTIATE_RHS_WITH_INFER {
275 return true;
276 }
277 }
278 ty::Error(_) | ty::Alias(ty::IsRigid::No, _) | ty::Bound(..) => return true,
279 ty::Infer(var) => return self.var_and_ty_may_unify(var, lhs),
280
281 ty::Bool
284 | ty::Char
285 | ty::Int(_)
286 | ty::Uint(_)
287 | ty::Float(_)
288 | ty::Adt(..)
289 | ty::Str
290 | ty::Array(..)
291 | ty::Slice(..)
292 | ty::RawPtr(..)
293 | ty::Dynamic(..)
294 | ty::Pat(..)
295 | ty::Ref(..)
296 | ty::Never
297 | ty::Tuple(..)
298 | ty::FnDef(..)
299 | ty::FnPtr(..)
300 | ty::Closure(..)
301 | ty::CoroutineClosure(..)
302 | ty::Coroutine(..)
303 | ty::CoroutineWitness(..)
304 | ty::Foreign(_)
305 | ty::Placeholder(_)
306 | ty::UnsafeBinder(_) => {}
307
308 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
310 };
311
312 let Some(depth) = depth.checked_sub(1) else {
322 return true;
323 };
324
325 match lhs.kind() {
327 ty::Ref(_, lhs_ty, lhs_mutbl) => match rhs.kind() {
328 ty::Ref(_, rhs_ty, rhs_mutbl) => {
329 lhs_mutbl == rhs_mutbl && self.types_may_unify_inner(lhs_ty, rhs_ty, depth)
330 }
331 _ => false,
332 },
333
334 ty::Adt(lhs_def, lhs_args) => match rhs.kind() {
335 ty::Adt(rhs_def, rhs_args) => {
336 lhs_def == rhs_def && self.args_may_unify_inner(lhs_args, rhs_args, depth)
337 }
338 _ => false,
339 },
340
341 ty::Param(lhs) => {
344 INSTANTIATE_LHS_WITH_INFER
345 || match rhs.kind() {
346 ty::Param(rhs) => lhs == rhs,
347 _ => false,
348 }
349 }
350
351 ty::Placeholder(lhs) => {
353 #[allow(non_exhaustive_omitted_patterns)] match rhs.kind() {
ty::Placeholder(rhs) if lhs == rhs => true,
_ => false,
}matches!(rhs.kind(), ty::Placeholder(rhs) if lhs == rhs)
354 }
355
356 ty::Infer(var) => self.var_and_ty_may_unify(var, rhs),
357
358 ty::Alias(ty::IsRigid::Yes, lhs_alias) => {
361 INSTANTIATE_LHS_WITH_INFER
362 || match rhs.kind() {
363 ty::Alias(ty::IsRigid::Yes, rhs_alias) => {
364 lhs_alias.kind == rhs_alias.kind
365 && self.args_may_unify_inner(lhs_alias.args, rhs_alias.args, depth)
366 }
367 _ => false,
368 }
369 }
370 ty::Alias(ty::IsRigid::No, _) => true,
374
375 ty::Int(_)
376 | ty::Uint(_)
377 | ty::Float(_)
378 | ty::Str
379 | ty::Bool
380 | ty::Char
381 | ty::Never
382 | ty::Foreign(_) => lhs == rhs,
383
384 ty::Tuple(lhs) => match rhs.kind() {
385 ty::Tuple(rhs) => {
386 lhs.len() == rhs.len()
387 && iter::zip(lhs.iter(), rhs.iter())
388 .all(|(lhs, rhs)| self.types_may_unify_inner(lhs, rhs, depth))
389 }
390 _ => false,
391 },
392
393 ty::Array(lhs_ty, lhs_len) => match rhs.kind() {
394 ty::Array(rhs_ty, rhs_len) => {
395 self.types_may_unify_inner(lhs_ty, rhs_ty, depth)
396 && self.consts_may_unify_inner(lhs_len, rhs_len)
397 }
398 _ => false,
399 },
400
401 ty::RawPtr(lhs_ty, lhs_mutbl) => match rhs.kind() {
402 ty::RawPtr(rhs_ty, rhs_mutbl) => {
403 lhs_mutbl == rhs_mutbl && self.types_may_unify_inner(lhs_ty, rhs_ty, depth)
404 }
405 _ => false,
406 },
407
408 ty::Slice(lhs_ty) => {
409 #[allow(non_exhaustive_omitted_patterns)] match rhs.kind() {
ty::Slice(rhs_ty) if self.types_may_unify_inner(lhs_ty, rhs_ty, depth) =>
true,
_ => false,
}matches!(rhs.kind(), ty::Slice(rhs_ty) if self.types_may_unify_inner(lhs_ty, rhs_ty, depth))
410 }
411
412 ty::Dynamic(lhs_preds, ..) => {
413 #[allow(non_exhaustive_omitted_patterns)] match rhs.kind() {
ty::Dynamic(rhs_preds, ..) if
lhs_preds.principal_def_id() == rhs_preds.principal_def_id() => true,
_ => false,
}matches!(rhs.kind(), ty::Dynamic(rhs_preds, ..) if
417 lhs_preds.principal_def_id() == rhs_preds.principal_def_id()
418 )
419 }
420
421 ty::FnPtr(lhs_sig_tys, lhs_hdr) => match rhs.kind() {
422 ty::FnPtr(rhs_sig_tys, rhs_hdr) => {
423 let lhs_sig_tys = lhs_sig_tys.skip_binder().inputs_and_output;
424 let rhs_sig_tys = rhs_sig_tys.skip_binder().inputs_and_output;
425
426 lhs_hdr == rhs_hdr
427 && lhs_sig_tys.len() == rhs_sig_tys.len()
428 && iter::zip(lhs_sig_tys.iter(), rhs_sig_tys.iter())
429 .all(|(lhs, rhs)| self.types_may_unify_inner(lhs, rhs, depth))
430 }
431 _ => false,
432 },
433
434 ty::Bound(..) => true,
435
436 ty::FnDef(lhs_def_id, lhs_args) => match rhs.kind() {
437 ty::FnDef(rhs_def_id, rhs_args) => {
438 lhs_def_id == rhs_def_id
439 && self.args_may_unify_inner(
440 lhs_args.no_bound_vars().unwrap(),
441 rhs_args.no_bound_vars().unwrap(),
442 depth,
443 )
444 }
445 _ => false,
446 },
447
448 ty::Closure(lhs_def_id, lhs_args) => match rhs.kind() {
449 ty::Closure(rhs_def_id, rhs_args) => {
450 lhs_def_id == rhs_def_id && self.args_may_unify_inner(lhs_args, rhs_args, depth)
451 }
452 _ => false,
453 },
454
455 ty::CoroutineClosure(lhs_def_id, lhs_args) => match rhs.kind() {
456 ty::CoroutineClosure(rhs_def_id, rhs_args) => {
457 lhs_def_id == rhs_def_id && self.args_may_unify_inner(lhs_args, rhs_args, depth)
458 }
459 _ => false,
460 },
461
462 ty::Coroutine(lhs_def_id, lhs_args) => match rhs.kind() {
463 ty::Coroutine(rhs_def_id, rhs_args) => {
464 lhs_def_id == rhs_def_id && self.args_may_unify_inner(lhs_args, rhs_args, depth)
465 }
466 _ => false,
467 },
468
469 ty::CoroutineWitness(lhs_def_id, lhs_args) => match rhs.kind() {
470 ty::CoroutineWitness(rhs_def_id, rhs_args) => {
471 lhs_def_id == rhs_def_id && self.args_may_unify_inner(lhs_args, rhs_args, depth)
472 }
473 _ => false,
474 },
475
476 ty::Pat(lhs_ty, _) => {
477 #[allow(non_exhaustive_omitted_patterns)] match rhs.kind() {
ty::Pat(rhs_ty, _) if self.types_may_unify_inner(lhs_ty, rhs_ty, depth) =>
true,
_ => false,
}matches!(rhs.kind(), ty::Pat(rhs_ty, _) if self.types_may_unify_inner(lhs_ty, rhs_ty, depth))
479 }
480
481 ty::UnsafeBinder(lhs_ty) => match rhs.kind() {
482 ty::UnsafeBinder(rhs_ty) => {
483 self.types_may_unify_inner(lhs_ty.skip_binder(), rhs_ty.skip_binder(), depth)
484 }
485 _ => false,
486 },
487
488 ty::Error(..) => true,
489
490 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
492 }
493 }
494
495 fn consts_may_unify_inner(self, lhs: Const<I>, rhs: Const<I>) -> bool {
498 match rhs.kind() {
499 ty::ConstKind::Param(_) => {
500 if INSTANTIATE_RHS_WITH_INFER {
501 return true;
502 }
503 }
504
505 ty::ConstKind::Expr(_)
506 | ty::ConstKind::Alias(_, _)
507 | ty::ConstKind::Error(_)
508 | ty::ConstKind::Infer(_)
509 | ty::ConstKind::Bound(..) => {
510 return true;
511 }
512
513 ty::ConstKind::Value(..) | ty::ConstKind::Placeholder(_) => {}
514 };
515
516 match lhs.kind() {
517 ty::ConstKind::Value(lhs_val) => match rhs.kind() {
518 ty::ConstKind::Value(rhs_val) => lhs_val.valtree() == rhs_val.valtree(),
519 _ => false,
520 },
521
522 ty::ConstKind::Param(lhs) => {
523 INSTANTIATE_LHS_WITH_INFER
524 || match rhs.kind() {
525 ty::ConstKind::Param(rhs) => lhs == rhs,
526 _ => false,
527 }
528 }
529
530 ty::ConstKind::Placeholder(lhs) => {
532 #[allow(non_exhaustive_omitted_patterns)] match rhs.kind() {
ty::ConstKind::Placeholder(rhs) if lhs == rhs => true,
_ => false,
}matches!(rhs.kind(), ty::ConstKind::Placeholder(rhs) if lhs == rhs)
533 }
534
535 ty::ConstKind::Expr(_) | ty::ConstKind::Alias(_, _) | ty::ConstKind::Error(_) => true,
538
539 ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) => true,
540 }
541 }
542
543 fn var_and_ty_may_unify(self, var: ty::InferTy, ty: I::Ty) -> bool {
544 if !ty.is_known_rigid() {
545 return true;
546 }
547
548 match var {
549 ty::IntVar(_) => ty.is_integral(),
550 ty::FloatVar(_) => ty.is_floating_point(),
551 _ => true,
552 }
553 }
554}