]>
Commit | Line | Data |
---|---|---|
e74abb32 | 1 | use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse}; |
9fa01778 | 2 | use crate::traits::query::Fallible; |
c295e0f8 | 3 | use rustc_infer::traits::query::OutlivesBound; |
923072b8 | 4 | use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt}; |
b7449926 | 5 | |
064997fb | 6 | #[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable, Lift)] |
b7449926 XL |
7 | pub struct ImpliedOutlivesBounds<'tcx> { |
8 | pub ty: Ty<'tcx>, | |
9 | } | |
10 | ||
dc9dc135 | 11 | impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> { |
0bf4aa26 | 12 | type QueryResponse = Vec<OutlivesBound<'tcx>>; |
b7449926 XL |
13 | |
14 | fn try_fast_path( | |
dc9dc135 | 15 | _tcx: TyCtxt<'tcx>, |
923072b8 | 16 | key: &ParamEnvAnd<'tcx, Self>, |
0bf4aa26 | 17 | ) -> Option<Self::QueryResponse> { |
923072b8 FG |
18 | // Don't go into the query for things that can't possibly have lifetimes. |
19 | match key.value.ty.kind() { | |
20 | ty::Tuple(elems) if elems.is_empty() => Some(vec![]), | |
21 | ty::Never | ty::Str | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => { | |
22 | Some(vec![]) | |
23 | } | |
24 | _ => None, | |
25 | } | |
b7449926 XL |
26 | } |
27 | ||
28 | fn perform_query( | |
dc9dc135 XL |
29 | tcx: TyCtxt<'tcx>, |
30 | canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>, | |
31 | ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> { | |
a1dfa0c6 XL |
32 | // FIXME this `unchecked_map` is only necessary because the |
33 | // query is defined as taking a `ParamEnvAnd<Ty>`; it should | |
94222f64 | 34 | // take an `ImpliedOutlivesBounds` instead |
a1dfa0c6 XL |
35 | let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| { |
36 | let ImpliedOutlivesBounds { ty } = value; | |
37 | param_env.and(ty) | |
38 | }); | |
b7449926 XL |
39 | |
40 | tcx.implied_outlives_bounds(canonicalized) | |
41 | } | |
b7449926 | 42 | } |