Skip to main content

rustc_type_ir/
fast_reject.rs

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/// See `simplify_type`.
15#[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    /// A trait object, all of whose components are markers
33    /// (e.g., `dyn Send + Sync`).
34    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/// Generic parameters are pretty much just bound variables, e.g.
47/// the type of `fn foo<'a, T>(x: &'a T) -> u32 { ... }` can be thought of as
48/// `for<'a, T> fn(&'a T) -> u32`.
49///
50/// Typecheck of `foo` has to succeed for all possible generic arguments, so
51/// during typeck, we have to treat its generic parameters as if they
52/// were placeholders.
53///
54/// But when calling `foo` we only have to provide a specific generic argument.
55/// In that case the generic parameters are instantiated with inference variables.
56/// As we use `simplify_type` before that instantiation happens, we just treat
57/// generic parameters as if they were inference variables in that case.
58#[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    /// Treat parameters as infer vars. This is the correct mode for caching
61    /// an impl's type for lookup.
62    InstantiateWithInfer,
63    /// Treat parameters as placeholders in the given environment. This is the
64    /// correct mode for *lookup*, as during candidate selection.
65    ///
66    /// This also treats projections with inference variables as infer vars
67    /// since they could be further normalized.
68    // FIXME(@lcnr): This treats aliases as rigid. This is only correct if the
69    // type has been structurally normalized. We should reflect this requirement
70    // in the variant name. It is currently incorrectly used in diagnostics.
71    AsRigid,
72}
73
74/// Tries to simplify a type by only returning the outermost injective¹ layer, if one exists.
75///
76/// **This function should only be used if you need to store or retrieve the type from some
77/// hashmap. If you want to quickly decide whether two types may unify, use the [DeepRejectCtxt]
78/// instead.**
79///
80/// The idea is to get something simple that we can use to quickly decide if two types could unify,
81/// for example during method lookup. If this function returns `Some(x)` it can only unify with
82/// types for which this method returns either `Some(x)` as well or `None`.
83///
84/// A special case here are parameters and projections, which are only injective
85/// if they are treated as placeholders.
86///
87/// For example when storing impls based on their simplified self type, we treat
88/// generic parameters as if they were inference variables. We must not simplify them here,
89/// as they can unify with any other type.
90///
91/// With projections we have to be even more careful, as treating them as placeholders
92/// is only correct if they are fully normalized.
93///
94/// ¹ meaning that if the outermost layers are different, then the whole types are also different.
95pub 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            // When treating `ty::Param` as a placeholder, projections also
137            // don't unify with anything else as long as they are fully normalized.
138            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/// Given generic arguments, could they be unified after
167/// replacing parameters with inference variables or placeholders.
168/// This behavior is toggled using the const generics.
169///
170/// We use this to quickly reject impl/wc candidates without needing
171/// to instantiate generic arguments/having to enter a probe.
172///
173/// We also use this function during coherence. For coherence the
174/// impls only have to overlap for some value, so we treat parameters
175/// on both sides like inference variables.
176#[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    /// Treat parameters in both the lhs and the rhs as rigid.
187    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    /// Treat parameters in both the lhs and the rhs as infer vars.
194    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    /// Treat parameters in the lhs as rigid, and in rhs as infer vars.
201    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    // Quite arbitrary. Large enough to only affect a very tiny amount of impls/crates
210    // and small enough to prevent hangs.
211    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        // No need to decrement the depth here as this function is only
236        // recursively reachable via `types_may_unify_inner` which already
237        // increments the depth for us.
238        let may_unify = |(obl, imp): (I::GenericArg, I::GenericArg)| {
239            match obl.kind() {
240                // We don't fast reject based on regions.
241                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        // Specialize the common `(1, 1)` case to avoid iterator machinery.
258        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            // Start by checking whether the `rhs` type may unify with
272            // pretty much everything. Just return `true` in that case.
273            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            // These types only unify with inference variables or their own
282            // variant.
283            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            // FIXME(scrabsha)
309            ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
310        };
311
312        // The type system needs to support exponentially large types
313        // as long as they are self-similar. While most other folders
314        // use caching to handle them, this folder exists purely as a
315        // perf optimization and is incredibly hot. In pretty much all
316        // uses checking the cache is slower than simply recursing, so
317        // we instead just add an arbitrary depth cutoff.
318        //
319        // We only decrement the depth here as the match on `rhs`
320        // does not recurse.
321        let Some(depth) = depth.checked_sub(1) else {
322            return true;
323        };
324
325        // For purely rigid types, use structural equivalence.
326        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            // Depending on the value of const generics, we either treat generic parameters
342            // like placeholders or like inference variables.
343            ty::Param(lhs) => {
344                INSTANTIATE_LHS_WITH_INFER
345                    || match rhs.kind() {
346                        ty::Param(rhs) => lhs == rhs,
347                        _ => false,
348                    }
349            }
350
351            // Placeholder types don't unify with anything on their own.
352            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            // Since we ensure that the rhs is not non-rigid alias,
359            // lhs rigid alias can only unify with it if it's a rigid alias of the same kind.
360            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            // As we're walking the whole type, it may encounter projections
371            // inside of binders and what not, so we're just going to assume that
372            // non-rigid alias can unify with anything.
373            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                // Ideally we would walk the existential predicates here or at least
414                // compare their length. But considering that the relevant `Relate` impl
415                // actually sorts and deduplicates these, that doesn't work.
416                #[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                // FIXME(pattern_types): take pattern into account
478                #[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            // FIXME(scrabsha)
491            ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
492        }
493    }
494
495    // Unlike `types_may_unify_inner`, this does not take a depth as
496    // we never recurse from this function.
497    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            // Placeholder consts don't unify with anything on their own
531            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            // As we don't necessarily eagerly evaluate constants,
536            // they might unify with any value.
537            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}