DropckOutlives
to rustc_middle
This commit is contained in:
parent
9334d85e69
commit
f3ce557fcd
6 changed files with 27 additions and 37 deletions
|
@ -1,4 +1,5 @@
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_infer::traits::query::type_op::DropckOutlives;
|
||||
use rustc_middle::traits::query::{DropckConstraint, DropckOutlivesResult};
|
||||
use rustc_middle::ty::{self, EarlyBinder, ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
|
@ -88,10 +89,10 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||
|
||||
pub fn compute_dropck_outlives_inner<'tcx>(
|
||||
ocx: &ObligationCtxt<'_, 'tcx>,
|
||||
goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
|
||||
goal: ParamEnvAnd<'tcx, DropckOutlives<'tcx>>,
|
||||
) -> Result<DropckOutlivesResult<'tcx>, NoSolution> {
|
||||
let tcx = ocx.infcx.tcx;
|
||||
let ParamEnvAnd { param_env, value: for_ty } = goal;
|
||||
let ParamEnvAnd { param_env, value: DropckOutlives { dropped_ty } } = goal;
|
||||
|
||||
let mut result = DropckOutlivesResult { kinds: vec![], overflows: vec![] };
|
||||
|
||||
|
@ -99,7 +100,7 @@ pub fn compute_dropck_outlives_inner<'tcx>(
|
|||
// something from the stack and invoke
|
||||
// `dtorck_constraint_for_ty_inner`. This may produce new types that
|
||||
// have to be pushed on the stack. This continues until we have explored
|
||||
// all the reachable types from the type `for_ty`.
|
||||
// all the reachable types from the type `dropped_ty`.
|
||||
//
|
||||
// Example: Imagine that we have the following code:
|
||||
//
|
||||
|
@ -129,7 +130,7 @@ pub fn compute_dropck_outlives_inner<'tcx>(
|
|||
// lead to us trying to push `A` a second time -- to prevent
|
||||
// infinite recursion, we notice that `A` was already pushed
|
||||
// once and stop.
|
||||
let mut ty_stack = vec![(for_ty, 0)];
|
||||
let mut ty_stack = vec![(dropped_ty, 0)];
|
||||
|
||||
// Set used to detect infinite recursion.
|
||||
let mut ty_set = FxHashSet::default();
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||
use rustc_middle::traits::query::{DropckOutlivesResult, NoSolution};
|
||||
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
|
||||
|
||||
use crate::infer::canonical::{Canonical, CanonicalQueryResponse};
|
||||
use crate::traits::ObligationCtxt;
|
||||
use crate::traits::query::dropck_outlives::{
|
||||
compute_dropck_outlives_inner, trivial_dropck_outlives,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct DropckOutlives<'tcx> {
|
||||
dropped_ty: Ty<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> DropckOutlives<'tcx> {
|
||||
pub fn new(dropped_ty: Ty<'tcx>) -> Self {
|
||||
DropckOutlives { dropped_ty }
|
||||
}
|
||||
}
|
||||
use crate::traits::query::type_op::DropckOutlives;
|
||||
|
||||
impl<'tcx> super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
|
||||
type QueryResponse = DropckOutlivesResult<'tcx>;
|
||||
|
@ -33,14 +22,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
|
|||
tcx: TyCtxt<'tcx>,
|
||||
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Self>>,
|
||||
) -> Result<CanonicalQueryResponse<'tcx, Self::QueryResponse>, NoSolution> {
|
||||
// FIXME convert to the type expected by the `dropck_outlives`
|
||||
// query. This should eventually be fixed by changing the
|
||||
// *underlying query*.
|
||||
let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
|
||||
let DropckOutlives { dropped_ty } = value;
|
||||
param_env.and(dropped_ty)
|
||||
});
|
||||
|
||||
tcx.dropck_outlives(canonicalized)
|
||||
}
|
||||
|
||||
|
@ -48,6 +29,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
|
|||
ocx: &ObligationCtxt<'_, 'tcx>,
|
||||
key: ParamEnvAnd<'tcx, Self>,
|
||||
) -> Result<Self::QueryResponse, NoSolution> {
|
||||
compute_dropck_outlives_inner(ocx, key.param_env.and(key.value.dropped_ty))
|
||||
compute_dropck_outlives_inner(ocx, key.param_env.and(key.value))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue