]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / compiler / rustc_trait_selection / src / traits / query / type_op / implied_outlives_bounds.rs
CommitLineData
e74abb32 1use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
9fa01778 2use crate::traits::query::Fallible;
c295e0f8 3use rustc_infer::traits::query::OutlivesBound;
923072b8 4use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt};
b7449926 5
064997fb 6#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable, Lift)]
b7449926
XL
7pub struct ImpliedOutlivesBounds<'tcx> {
8 pub ty: Ty<'tcx>,
9}
10
dc9dc135 11impl<'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}