1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
3 use crate::traits::query::Fallible;
4 use crate::ty::fold::TypeFoldable;
5 use crate::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt};
7 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
8 pub struct Normalize<T> {
12 impl<'tcx, T> Normalize<T>
14 T: fmt::Debug + TypeFoldable<'tcx>,
16 pub fn new(value: T) -> Self {
21 impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
23 T: Normalizable<'tcx> + 'tcx,
25 type QueryResponse = T;
27 fn try_fast_path(_tcx: TyCtxt<'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<T> {
28 if !key.value.value.has_projections() {
37 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
38 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
39 T::type_op_method(tcx, canonicalized)
43 pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'tcx> + Copy {
46 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
47 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>>;
50 impl Normalizable<'tcx> for Ty<'tcx> {
53 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
54 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
55 tcx.type_op_normalize_ty(canonicalized)
59 impl Normalizable<'tcx> for ty::Predicate<'tcx> {
62 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
63 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
64 tcx.type_op_normalize_predicate(canonicalized)
68 impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
71 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
72 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
73 tcx.type_op_normalize_poly_fn_sig(canonicalized)
77 impl Normalizable<'tcx> for ty::FnSig<'tcx> {
80 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
81 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
82 tcx.type_op_normalize_fn_sig(canonicalized)
86 impl_stable_hash_for! {
87 impl<T> for struct Normalize<T> {