]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs
Rollup merge of #105684 - GuillaumeGomez:improve-rustdoc-var-name, r=notriddle
[rust.git] / compiler / rustc_trait_selection / src / traits / query / type_op / implied_outlives_bounds.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::Fallible;
3 use rustc_infer::traits::query::OutlivesBound;
4 use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt};
5
6 #[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable, Lift)]
7 pub struct ImpliedOutlivesBounds<'tcx> {
8     pub ty: Ty<'tcx>,
9 }
10
11 impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
12     type QueryResponse = Vec<OutlivesBound<'tcx>>;
13
14     fn try_fast_path(
15         _tcx: TyCtxt<'tcx>,
16         key: &ParamEnvAnd<'tcx, Self>,
17     ) -> Option<Self::QueryResponse> {
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         }
26     }
27
28     fn perform_query(
29         tcx: TyCtxt<'tcx>,
30         canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
31     ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
32         // FIXME this `unchecked_map` is only necessary because the
33         // query is defined as taking a `ParamEnvAnd<Ty>`; it should
34         // take an `ImpliedOutlivesBounds` instead
35         let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
36             let ImpliedOutlivesBounds { ty } = value;
37             param_env.and(ty)
38         });
39
40         tcx.implied_outlives_bounds(canonicalized)
41     }
42 }