Skip to content

Commit f3ce557

Browse files
committed
DropckOutlives to rustc_middle
1 parent 9334d85 commit f3ce557

File tree

6 files changed

+27
-37
lines changed

6 files changed

+27
-37
lines changed

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1111
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
1212
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
1313
use rustc_span::DUMMY_SP;
14-
use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
15-
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
14+
use rustc_trait_selection::traits::query::type_op::{DropckOutlives, TypeOp, TypeOpOutput};
1615
use tracing::debug;
1716

1817
use crate::location::RichLocation;
@@ -632,7 +631,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
632631

633632
match typeck
634633
.param_env
635-
.and(DropckOutlives::new(dropped_ty))
634+
.and(DropckOutlives { dropped_ty })
636635
.fully_perform(typeck.infcx, DUMMY_SP)
637636
{
638637
Ok(TypeOpOutput { output, constraints, .. }) => {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ use crate::query::plumbing::{
6565
CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
6666
};
6767
use crate::traits::query::{
68-
CanonicalAliasGoal, CanonicalImpliedOutlivesBoundsGoal, CanonicalPredicateGoal,
69-
CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpNormalizeGoal,
70-
CanonicalTypeOpProvePredicateGoal, DropckConstraint, DropckOutlivesResult,
71-
MethodAutoderefStepsResult, NoSolution, NormalizationResult, OutlivesBound,
68+
CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
69+
CanonicalPredicateGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
70+
CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, DropckConstraint,
71+
DropckOutlivesResult, MethodAutoderefStepsResult, NoSolution, NormalizationResult,
72+
OutlivesBound,
7273
};
7374
use crate::traits::{
7475
CodegenObligationError, DynCompatibilityViolation, EvaluationResult, ImplSource,
@@ -2069,12 +2070,12 @@ rustc_queries! {
20692070
/// Do not call this query directly:
20702071
/// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
20712072
query dropck_outlives(
2072-
goal: CanonicalTyGoal<'tcx>
2073+
goal: CanonicalDropckOutlivesGoal<'tcx>
20732074
) -> Result<
20742075
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
20752076
NoSolution,
20762077
> {
2077-
desc { "computing dropck types for `{}`", goal.value.value }
2078+
desc { "computing dropck types for `{}`", goal.value.value.dropped_ty }
20782079
}
20792080

20802081
/// Do not call this query directly: invoke `infcx.predicate_may_hold()` or

compiler/rustc_middle/src/traits/query.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ pub mod type_op {
5151
pub struct ImpliedOutlivesBounds<'tcx> {
5252
pub ty: Ty<'tcx>,
5353
}
54+
55+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
56+
pub struct DropckOutlives<'tcx> {
57+
pub dropped_ty: Ty<'tcx>,
58+
}
5459
}
5560

5661
pub type CanonicalAliasGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>;
@@ -76,6 +81,9 @@ pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
7681
pub type CanonicalImpliedOutlivesBoundsGoal<'tcx> =
7782
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::ImpliedOutlivesBounds<'tcx>>>;
7883

84+
pub type CanonicalDropckOutlivesGoal<'tcx> =
85+
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::DropckOutlives<'tcx>>>;
86+
7987
#[derive(Clone, Debug, Default, HashStable, TypeFoldable, TypeVisitable)]
8088
pub struct DropckOutlivesResult<'tcx> {
8189
pub kinds: Vec<GenericArg<'tcx>>,

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_data_structures::fx::FxHashSet;
2+
use rustc_infer::traits::query::type_op::DropckOutlives;
23
use rustc_middle::traits::query::{DropckConstraint, DropckOutlivesResult};
34
use rustc_middle::ty::{self, EarlyBinder, ParamEnvAnd, Ty, TyCtxt};
45
use rustc_span::{DUMMY_SP, Span};
@@ -88,18 +89,18 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
8889

8990
pub fn compute_dropck_outlives_inner<'tcx>(
9091
ocx: &ObligationCtxt<'_, 'tcx>,
91-
goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
92+
goal: ParamEnvAnd<'tcx, DropckOutlives<'tcx>>,
9293
) -> Result<DropckOutlivesResult<'tcx>, NoSolution> {
9394
let tcx = ocx.infcx.tcx;
94-
let ParamEnvAnd { param_env, value: for_ty } = goal;
95+
let ParamEnvAnd { param_env, value: DropckOutlives { dropped_ty } } = goal;
9596

9697
let mut result = DropckOutlivesResult { kinds: vec![], overflows: vec![] };
9798

9899
// A stack of types left to process. Each round, we pop
99100
// something from the stack and invoke
100101
// `dtorck_constraint_for_ty_inner`. This may produce new types that
101102
// have to be pushed on the stack. This continues until we have explored
102-
// all the reachable types from the type `for_ty`.
103+
// all the reachable types from the type `dropped_ty`.
103104
//
104105
// Example: Imagine that we have the following code:
105106
//
@@ -129,7 +130,7 @@ pub fn compute_dropck_outlives_inner<'tcx>(
129130
// lead to us trying to push `A` a second time -- to prevent
130131
// infinite recursion, we notice that `A` was already pushed
131132
// once and stop.
132-
let mut ty_stack = vec![(for_ty, 0)];
133+
let mut ty_stack = vec![(dropped_ty, 0)];
133134

134135
// Set used to detect infinite recursion.
135136
let mut ty_set = FxHashSet::default();
Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
21
use rustc_middle::traits::query::{DropckOutlivesResult, NoSolution};
3-
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
2+
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
43

54
use crate::infer::canonical::{Canonical, CanonicalQueryResponse};
65
use crate::traits::ObligationCtxt;
76
use crate::traits::query::dropck_outlives::{
87
compute_dropck_outlives_inner, trivial_dropck_outlives,
98
};
10-
11-
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
12-
pub struct DropckOutlives<'tcx> {
13-
dropped_ty: Ty<'tcx>,
14-
}
15-
16-
impl<'tcx> DropckOutlives<'tcx> {
17-
pub fn new(dropped_ty: Ty<'tcx>) -> Self {
18-
DropckOutlives { dropped_ty }
19-
}
20-
}
9+
use crate::traits::query::type_op::DropckOutlives;
2110

2211
impl<'tcx> super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
2312
type QueryResponse = DropckOutlivesResult<'tcx>;
@@ -33,21 +22,13 @@ impl<'tcx> super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
3322
tcx: TyCtxt<'tcx>,
3423
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Self>>,
3524
) -> Result<CanonicalQueryResponse<'tcx, Self::QueryResponse>, NoSolution> {
36-
// FIXME convert to the type expected by the `dropck_outlives`
37-
// query. This should eventually be fixed by changing the
38-
// *underlying query*.
39-
let canonicalized = canonicalized.unchecked_map(|ParamEnvAnd { param_env, value }| {
40-
let DropckOutlives { dropped_ty } = value;
41-
param_env.and(dropped_ty)
42-
});
43-
4425
tcx.dropck_outlives(canonicalized)
4526
}
4627

4728
fn perform_locally_with_next_solver(
4829
ocx: &ObligationCtxt<'_, 'tcx>,
4930
key: ParamEnvAnd<'tcx, Self>,
5031
) -> Result<Self::QueryResponse, NoSolution> {
51-
compute_dropck_outlives_inner(ocx, key.param_env.and(key.value.dropped_ty))
32+
compute_dropck_outlives_inner(ocx, key.param_env.and(key.value))
5233
}
5334
}

compiler/rustc_traits/src/dropck_outlives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_trait_selection::infer::InferCtxtBuilderExt;
1010
use rustc_trait_selection::traits::query::dropck_outlives::{
1111
compute_dropck_outlives_inner, dtorck_constraint_for_ty_inner,
1212
};
13-
use rustc_trait_selection::traits::query::{CanonicalTyGoal, NoSolution};
13+
use rustc_trait_selection::traits::query::{CanonicalDropckOutlivesGoal, NoSolution};
1414
use tracing::debug;
1515

1616
pub(crate) fn provide(p: &mut Providers) {
@@ -19,7 +19,7 @@ pub(crate) fn provide(p: &mut Providers) {
1919

2020
fn dropck_outlives<'tcx>(
2121
tcx: TyCtxt<'tcx>,
22-
canonical_goal: CanonicalTyGoal<'tcx>,
22+
canonical_goal: CanonicalDropckOutlivesGoal<'tcx>,
2323
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>, NoSolution> {
2424
debug!("dropck_outlives(goal={:#?})", canonical_goal);
2525

0 commit comments

Comments
 (0)