]> git.lizzy.rs Git - rust.git/blob - src/librustc/traits/query/type_op/outlives.rs
Retire BraceStructLiftImpl.
[rust.git] / src / librustc / traits / query / type_op / outlives.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::dropck_outlives::{DropckOutlivesResult, trivial_dropck_outlives};
3 use crate::traits::query::Fallible;
4 use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
5
6 #[derive(Copy, Clone, Debug, TypeFoldable, Lift)]
7 pub struct DropckOutlives<'tcx> {
8     dropped_ty: Ty<'tcx>,
9 }
10
11 impl<'tcx> DropckOutlives<'tcx> {
12     pub fn new(dropped_ty: Ty<'tcx>) -> Self {
13         DropckOutlives { dropped_ty }
14     }
15 }
16
17 impl super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
18     type QueryResponse = DropckOutlivesResult<'tcx>;
19
20     fn try_fast_path(
21         tcx: TyCtxt<'tcx>,
22         key: &ParamEnvAnd<'tcx, Self>,
23     ) -> Option<Self::QueryResponse> {
24         if trivial_dropck_outlives(tcx, key.value.dropped_ty) {
25             Some(DropckOutlivesResult::default())
26         } else {
27             None
28         }
29     }
30
31     fn perform_query(
32         tcx: TyCtxt<'tcx>,
33         canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
34     ) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
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*.
48         let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
49             let DropckOutlives { dropped_ty } = value;
50             param_env.and(dropped_ty)
51         });
52
53         tcx.dropck_outlives(canonicalized)
54     }
55 }
56
57 impl_stable_hash_for! {
58     struct DropckOutlives<'tcx> { dropped_ty }
59 }