]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_trait_selection/src/traits/query/type_op/outlives.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / compiler / rustc_trait_selection / src / traits / query / type_op / outlives.rs
CommitLineData
e74abb32 1use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
dfeec247 2use crate::traits::query::dropck_outlives::{trivial_dropck_outlives, DropckOutlivesResult};
9fa01778 3use crate::traits::query::Fallible;
ba9703b0 4use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
8faf50e0 5
064997fb 6#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable, Lift)]
8faf50e0
XL
7pub struct DropckOutlives<'tcx> {
8 dropped_ty: Ty<'tcx>,
9}
10
11impl<'tcx> DropckOutlives<'tcx> {
12 pub fn new(dropped_ty: Ty<'tcx>) -> Self {
13 DropckOutlives { dropped_ty }
14 }
15}
16
a2a8927a 17impl<'tcx> super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
0bf4aa26 18 type QueryResponse = DropckOutlivesResult<'tcx>;
8faf50e0
XL
19
20 fn try_fast_path(
dc9dc135 21 tcx: TyCtxt<'tcx>,
8faf50e0 22 key: &ParamEnvAnd<'tcx, Self>,
0bf4aa26 23 ) -> Option<Self::QueryResponse> {
60c5eb7d 24 if trivial_dropck_outlives(tcx, key.value.dropped_ty) {
8faf50e0
XL
25 Some(DropckOutlivesResult::default())
26 } else {
27 None
28 }
29 }
30
31 fn perform_query(
dc9dc135
XL
32 tcx: TyCtxt<'tcx>,
33 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
34 ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
8faf50e0
XL
35 // Subtle: note that we are not invoking
36 // `infcx.at(...).dropck_outlives(...)` here, but rather the
37 // underlying `dropck_outlives` query. This same underlying
38 // query is also used by the
39 // `infcx.at(...).dropck_outlives(...)` fn. Avoiding the
40 // wrapper means we don't need an infcx in this code, which is
41 // good because the interface doesn't give us one (so that we
42 // know we are not registering any subregion relations or
43 // other things).
44
45 // FIXME convert to the type expected by the `dropck_outlives`
46 // query. This should eventually be fixed by changing the
47 // *underlying query*.
a1dfa0c6
XL
48 let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
49 let DropckOutlives { dropped_ty } = value;
50 param_env.and(dropped_ty)
51 });
8faf50e0
XL
52
53 tcx.dropck_outlives(canonicalized)
54 }
8faf50e0 55}