rustc_trait_selection/traits/query/type_op/
normalize.rs1use std::fmt;
2
3use rustc_middle::traits::query::NoSolution;
4pub use rustc_middle::traits::query::type_op::Normalize;
5use rustc_middle::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
6
7use crate::infer::InferCtxt;
8use crate::infer::canonical::{CanonicalQueryInput, CanonicalQueryResponse};
9
10impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<'tcx, T>
11where
12 T: Normalizable<'tcx> + 'tcx,
13{
14 type QueryResponse = T;
15
16 fn try_fast_path(infcx: &InferCtxt<'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<T> {
17 let value = key.value.value.skip_normalization();
18 if !value.has_aliases() { Some(infcx.deeply_resolve_ignoring_regions(value)) } else { None }
19 }
20
21 fn perform_query(
22 tcx: TyCtxt<'tcx>,
23 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Self>>,
24 ) -> Result<CanonicalQueryResponse<'tcx, Self::QueryResponse>, NoSolution> {
25 T::type_op_method(tcx, canonicalized)
26 }
27}
28
29pub trait Normalizable<'tcx>:
30 PartialEq + fmt::Debug + TypeFoldable<TyCtxt<'tcx>> + Lift<TyCtxt<'tcx>> + Copy
31{
32 fn type_op_method(
33 tcx: TyCtxt<'tcx>,
34 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize<'tcx, Self>>>,
35 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution>;
36}
37
38impl<'tcx> Normalizable<'tcx> for Ty<'tcx> {
39 fn type_op_method(
40 tcx: TyCtxt<'tcx>,
41 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize<'tcx, Self>>>,
42 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
43 tcx.type_op_normalize_ty(canonicalized)
44 }
45}
46
47impl<'tcx> Normalizable<'tcx> for ty::Clause<'tcx> {
48 fn type_op_method(
49 tcx: TyCtxt<'tcx>,
50 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize<'tcx, Self>>>,
51 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
52 tcx.type_op_normalize_clause(canonicalized)
53 }
54}
55
56impl<'tcx> Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
57 fn type_op_method(
58 tcx: TyCtxt<'tcx>,
59 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize<'tcx, Self>>>,
60 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
61 tcx.type_op_normalize_poly_fn_sig(canonicalized)
62 }
63}
64
65impl<'tcx> Normalizable<'tcx> for ty::FnSig<'tcx> {
66 fn type_op_method(
67 tcx: TyCtxt<'tcx>,
68 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize<'tcx, Self>>>,
69 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
70 tcx.type_op_normalize_fn_sig(canonicalized)
71 }
72}
73
74impl<'tcx> Normalizable<'tcx> for ty::PolyTypeOutlivesClause<'tcx> {
77 fn type_op_method(
78 _tcx: TyCtxt<'tcx>,
79 _canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize<'tcx, Self>>>,
80 ) -> Result<CanonicalQueryResponse<'tcx, Self>, NoSolution> {
81 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("we never normalize PolyTypeOutlivesClause")));
}unreachable!("we never normalize PolyTypeOutlivesClause")
82 }
83}