]>
Commit | Line | Data |
---|---|---|
9c376795 | 1 | use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; |
49aad941 FG |
2 | use crate::traits::ObligationCtxt; |
3 | use rustc_middle::traits::query::NoSolution; | |
4 | use rustc_middle::traits::ObligationCause; | |
ba9703b0 | 5 | use rustc_middle::ty::fold::TypeFoldable; |
9ffffee4 | 6 | use rustc_middle::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt}; |
dfeec247 | 7 | use std::fmt; |
8faf50e0 | 8 | |
ba9703b0 | 9 | pub use rustc_middle::traits::query::type_op::Normalize; |
8faf50e0 | 10 | |
dc9dc135 | 11 | impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T> |
8faf50e0 | 12 | where |
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 | 37 | pub 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 | 44 | impl<'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 | 53 | impl<'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 | 62 | impl<'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 | 71 | impl<'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 | } |