1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
12 use traits::query::dropck_outlives::trivial_dropck_outlives;
13 use traits::query::dropck_outlives::DropckOutlivesResult;
14 use traits::query::Fallible;
15 use ty::{ParamEnvAnd, Ty, TyCtxt};
17 #[derive(Copy, Clone, Debug)]
18 pub struct DropckOutlives<'tcx> {
22 impl<'tcx> DropckOutlives<'tcx> {
23 pub fn new(dropped_ty: Ty<'tcx>) -> Self {
24 DropckOutlives { dropped_ty }
28 impl super::QueryTypeOp<'gcx, 'tcx> for DropckOutlives<'tcx>
32 type QueryResult = DropckOutlivesResult<'tcx>;
35 tcx: TyCtxt<'_, 'gcx, 'tcx>,
36 key: &ParamEnvAnd<'tcx, Self>,
37 ) -> Option<Self::QueryResult> {
38 if trivial_dropck_outlives(tcx, key.value.dropped_ty) {
39 Some(DropckOutlivesResult::default())
46 tcx: TyCtxt<'_, 'gcx, 'tcx>,
47 canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
48 ) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>> {
49 // Subtle: note that we are not invoking
50 // `infcx.at(...).dropck_outlives(...)` here, but rather the
51 // underlying `dropck_outlives` query. This same underlying
52 // query is also used by the
53 // `infcx.at(...).dropck_outlives(...)` fn. Avoiding the
54 // wrapper means we don't need an infcx in this code, which is
55 // good because the interface doesn't give us one (so that we
56 // know we are not registering any subregion relations or
59 // FIXME convert to the type expected by the `dropck_outlives`
60 // query. This should eventually be fixed by changing the
61 // *underlying query*.
67 value: DropckOutlives { dropped_ty },
70 let canonicalized = Canonical {
72 value: param_env.and(dropped_ty),
75 tcx.dropck_outlives(canonicalized)
78 fn shrink_to_tcx_lifetime(
79 lifted_query_result: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
80 ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>> {
85 BraceStructTypeFoldableImpl! {
86 impl<'tcx> TypeFoldable<'tcx> for DropckOutlives<'tcx> {
91 BraceStructLiftImpl! {
92 impl<'a, 'tcx> Lift<'tcx> for DropckOutlives<'a> {
93 type Lifted = DropckOutlives<'tcx>;
98 impl_stable_hash_for! {
99 struct DropckOutlives<'tcx> { dropped_ty }