Skip to content

Commit f3ce557

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

6 files changed

Lines changed: 27 additions & 37 deletions

File tree

‎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
usecrate::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
usecrate::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
usecrate::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
pubstructImpliedOutlivesBounds<'tcx>{
5252
pubty:Ty<'tcx>,
5353
}
54+
55+
#[derive(Copy,Clone,Debug,Hash,PartialEq,Eq,HashStable,TypeFoldable,TypeVisitable)]
56+
pubstructDropckOutlives<'tcx>{
57+
pubdropped_ty:Ty<'tcx>,
58+
}
5459
}
5560

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

84+
pubtypeCanonicalDropckOutlivesGoal<'tcx> =
85+
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::DropckOutlives<'tcx>>>;
86+
7987
#[derive(Clone,Debug,Default,HashStable,TypeFoldable,TypeVisitable)]
8088
pubstructDropckOutlivesResult<'tcx>{
8189
pubkinds: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
pubfncompute_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-
letParamEnvAnd{ param_env,value:for_ty} = goal;
95+
letParamEnvAnd{ param_env,value:DropckOutlives{ dropped_ty }} = goal;
9596

9697
letmut 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-
letmut ty_stack = vec![(for_ty,0)];
133+
letmut ty_stack = vec![(dropped_ty,0)];
133134

134135
// Set used to detect infinite recursion.
135136
letmut 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
usecrate::infer::canonical::{Canonical,CanonicalQueryResponse};
65
usecrate::traits::ObligationCtxt;
76
usecrate::traits::query::dropck_outlives::{
87
compute_dropck_outlives_inner, trivial_dropck_outlives,
98
};
10-
11-
#[derive(Copy,Clone,Debug,HashStable,TypeFoldable,TypeVisitable)]
12-
pubstructDropckOutlives<'tcx>{
13-
dropped_ty:Ty<'tcx>,
14-
}
15-
16-
impl<'tcx>DropckOutlives<'tcx>{
17-
pubfnnew(dropped_ty:Ty<'tcx>) -> Self{
18-
DropckOutlives{ dropped_ty }
19-
}
20-
}
9+
usecrate::traits::query::type_op::DropckOutlives;
2110

2211
impl<'tcx>super::QueryTypeOp<'tcx>forDropckOutlives<'tcx>{
2312
typeQueryResponse = 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-
letDropckOutlives{ dropped_ty } = value;
41-
param_env.and(dropped_ty)
42-
});
43-
4425
tcx.dropck_outlives(canonicalized)
4526
}
4627

4728
fnperform_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)fnprovide(p:&mutProviders){
@@ -19,7 +19,7 @@ pub(crate) fn provide(p: &mut Providers) {
1919

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

0 commit comments

Comments
 (0)