]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs
New upstream version 1.71.1+dfsg1
[rustc.git] / compiler / rustc_trait_selection / src / traits / query / type_op / normalize.rs
CommitLineData
9c376795 1use crate::infer::canonical::{Canonical, CanonicalQueryResponse};
49aad941
FG
2use crate::traits::ObligationCtxt;
3use rustc_middle::traits::query::NoSolution;
4use rustc_middle::traits::ObligationCause;
ba9703b0 5use rustc_middle::ty::fold::TypeFoldable;
9ffffee4 6use rustc_middle::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt};
dfeec247 7use std::fmt;
8faf50e0 8
ba9703b0 9pub use rustc_middle::traits::query::type_op::Normalize;
8faf50e0 10
dc9dc135 11impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
8faf50e0 12where
dc9dc135 13 T: Normalizable<'tcx> + 'tcx,
8faf50e0 14{
0bf4aa26 15 type QueryResponse = T;
8faf50e0 16
dc9dc135 17 fn try_fast_path(_tcx: TyCtxt<'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<T> {
dfeec247 18 if !key.value.value.has_projections() { Some(key.value.value) } else { None }
8faf50e0
XL
19 }
20
21 fn perform_query(
dc9dc135 22 tcx: TyCtxt<'tcx>,
9c376795 23 canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Self>>,
49aad941 24 ) -> Result<CanonicalQueryResponse<'tcx, Self::QueryResponse>, NoSolution> {
8faf50e0
XL
25 T::type_op_method(tcx, canonicalized)
26 }
49aad941
FG
27
28 fn perform_locally_in_new_solver(
29 ocx: &ObligationCtxt<'_, 'tcx>,
30 key: ParamEnvAnd<'tcx, Self>,
31 ) -> Result<Self::QueryResponse, NoSolution> {
32 // FIXME(-Ztrait-solver=next): shouldn't be using old normalizer
33 Ok(ocx.normalize(&ObligationCause::dummy(), key.param_env, key.value.value))
34 }
8faf50e0
XL
35}
36
9ffffee4 37pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<TyCtxt<'tcx>> + Lift<'tcx> + Copy {
8faf50e0 38 fn type_op_method(
dc9dc135 39 tcx: TyCtxt<'tcx>,
9c376795 40 canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
49aad941 41 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution>;
8faf50e0
XL
42}
43
a2a8927a 44impl<'tcx> Normalizable<'tcx> for Ty<'tcx> {
8faf50e0 45 fn type_op_method(
dc9dc135 46 tcx: TyCtxt<'tcx>,
9c376795 47 canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
49aad941 48 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
8faf50e0
XL
49 tcx.type_op_normalize_ty(canonicalized)
50 }
8faf50e0
XL
51}
52
a2a8927a 53impl<'tcx> Normalizable<'tcx> for ty::Predicate<'tcx> {
8faf50e0 54 fn type_op_method(
dc9dc135 55 tcx: TyCtxt<'tcx>,
9c376795 56 canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
49aad941 57 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
8faf50e0
XL
58 tcx.type_op_normalize_predicate(canonicalized)
59 }
8faf50e0
XL
60}
61
a2a8927a 62impl<'tcx> Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
8faf50e0 63 fn type_op_method(
dc9dc135 64 tcx: TyCtxt<'tcx>,
9c376795 65 canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
49aad941 66 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
8faf50e0
XL
67 tcx.type_op_normalize_poly_fn_sig(canonicalized)
68 }
8faf50e0
XL
69}
70
a2a8927a 71impl<'tcx> Normalizable<'tcx> for ty::FnSig<'tcx> {
8faf50e0 72 fn type_op_method(
dc9dc135 73 tcx: TyCtxt<'tcx>,
9c376795 74 canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
49aad941 75 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
8faf50e0
XL
76 tcx.type_op_normalize_fn_sig(canonicalized)
77 }
8faf50e0 78}