]> git.proxmox.com Git - rustc.git/blob - src/librustc_trait_selection/traits/query/type_op/implied_outlives_bounds.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_trait_selection / traits / query / type_op / implied_outlives_bounds.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::outlives_bounds::OutlivesBound;
3 use crate::traits::query::Fallible;
4 use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
5
6 #[derive(Clone, Debug, HashStable, TypeFoldable, Lift)]
7 pub struct ImpliedOutlivesBounds<'tcx> {
8 pub ty: Ty<'tcx>,
9 }
10
11 impl<'tcx> ImpliedOutlivesBounds<'tcx> {
12 pub fn new(ty: Ty<'tcx>) -> Self {
13 ImpliedOutlivesBounds { ty }
14 }
15 }
16
17 impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
18 type QueryResponse = Vec<OutlivesBound<'tcx>>;
19
20 fn try_fast_path(
21 _tcx: TyCtxt<'tcx>,
22 _key: &ParamEnvAnd<'tcx, Self>,
23 ) -> Option<Self::QueryResponse> {
24 None
25 }
26
27 fn perform_query(
28 tcx: TyCtxt<'tcx>,
29 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
30 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
31 // FIXME this `unchecked_map` is only necessary because the
32 // query is defined as taking a `ParamEnvAnd<Ty>`; it should
33 // take a `ImpliedOutlivesBounds` instead
34 let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
35 let ImpliedOutlivesBounds { ty } = value;
36 param_env.and(ty)
37 });
38
39 tcx.implied_outlives_bounds(canonicalized)
40 }
41 }