Skip to content

Commit 56e7587

Browse files
committed
convert dropck_outlives type-op to use the query
1 parent 4d399f3 commit 56e7587

File tree

3 files changed

+78
-37
lines changed

3 files changed

+78
-37
lines changed

src/librustc/traits/query/dropck_outlives.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use infer::at::At;
1212
use infer::InferOk;
1313
use std::iter::FromIterator;
14+
use syntax::codemap::Span;
1415
use ty::subst::Kind;
1516
use ty::{self, Ty, TyCtxt};
1617

@@ -60,22 +61,9 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
6061
&orig_values,
6162
result,
6263
) {
63-
Ok(InferOk {
64-
value: DropckOutlivesResult { kinds, overflows },
65-
obligations,
66-
}) => {
67-
for overflow_ty in overflows.into_iter().take(1) {
68-
let mut err = struct_span_err!(
69-
tcx.sess,
70-
span,
71-
E0320,
72-
"overflow while adding drop-check rules for {}",
73-
self.infcx.resolve_type_vars_if_possible(&ty),
74-
);
75-
err.note(&format!("overflowed on {}", overflow_ty));
76-
err.emit();
77-
}
78-
64+
Ok(InferOk { value, obligations }) => {
65+
let ty = self.infcx.resolve_type_vars_if_possible(&ty);
66+
let kinds = value.into_kinds_reporting_overflows(tcx, span, ty);
7967
return InferOk {
8068
value: kinds,
8169
obligations,
@@ -102,12 +90,44 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
10290
}
10391
}
10492

105-
#[derive(Clone, Debug)]
93+
#[derive(Clone, Debug, Default)]
10694
pub struct DropckOutlivesResult<'tcx> {
10795
pub kinds: Vec<Kind<'tcx>>,
10896
pub overflows: Vec<Ty<'tcx>>,
10997
}
11098

99+
impl<'tcx> DropckOutlivesResult<'tcx> {
100+
pub fn report_overflows(
101+
&self,
102+
tcx: TyCtxt<'_, '_, 'tcx>,
103+
span: Span,
104+
ty: Ty<'tcx>,
105+
) {
106+
for overflow_ty in self.overflows.iter().take(1) {
107+
let mut err = struct_span_err!(
108+
tcx.sess,
109+
span,
110+
E0320,
111+
"overflow while adding drop-check rules for {}",
112+
ty,
113+
);
114+
err.note(&format!("overflowed on {}", overflow_ty));
115+
err.emit();
116+
}
117+
}
118+
119+
pub fn into_kinds_reporting_overflows(
120+
self,
121+
tcx: TyCtxt<'_, '_, 'tcx>,
122+
span: Span,
123+
ty: Ty<'tcx>,
124+
) -> Vec<Kind<'tcx>> {
125+
self.report_overflows(tcx, span, ty);
126+
let DropckOutlivesResult { kinds, overflows: _ } = self;
127+
kinds
128+
}
129+
}
130+
111131
/// A set of constraints that need to be satisfied in order for
112132
/// a type to be valid for destruction.
113133
#[derive(Clone, Debug)]

src/librustc/traits/query/type_op/outlives.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use infer::{InferCtxt, InferOk};
11+
use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
1212
use traits::query::dropck_outlives::trivial_dropck_outlives;
13+
use traits::query::dropck_outlives::DropckOutlivesResult;
1314
use traits::query::Fallible;
14-
use traits::ObligationCause;
15-
use ty::subst::Kind;
16-
use ty::{ParamEnv, Ty, TyCtxt};
15+
use ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt};
1716

1817
#[derive(Debug)]
1918
pub struct DropckOutlives<'tcx> {
@@ -30,23 +29,39 @@ impl<'tcx> DropckOutlives<'tcx> {
3029
}
3130
}
3231

33-
impl<'gcx, 'tcx> super::TypeOp<'gcx, 'tcx> for DropckOutlives<'tcx> {
34-
type Output = Vec<Kind<'tcx>>;
32+
impl super::QueryTypeOp<'gcx, 'tcx> for DropckOutlives<'tcx>
33+
where
34+
'gcx: 'tcx,
35+
{
36+
type QueryKey = ParamEnvAnd<'tcx, Ty<'tcx>>;
37+
type QueryResult = DropckOutlivesResult<'tcx>;
3538

36-
fn trivial_noop(self, tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::Output, Self> {
39+
fn trivial_noop(self, tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self> {
3740
if trivial_dropck_outlives(tcx, self.dropped_ty) {
38-
Ok(vec![])
41+
Ok(DropckOutlivesResult::default())
3942
} else {
4043
Err(self)
4144
}
4245
}
4346

44-
fn perform(
45-
self,
46-
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
47-
) -> Fallible<InferOk<'tcx, Vec<Kind<'tcx>>>> {
48-
Ok(infcx
49-
.at(&ObligationCause::dummy(), self.param_env)
50-
.dropck_outlives(self.dropped_ty))
47+
fn param_env(&self) -> ParamEnv<'tcx> {
48+
self.param_env
49+
}
50+
51+
fn into_query_key(self) -> Self::QueryKey {
52+
self.param_env.and(self.dropped_ty)
53+
}
54+
55+
fn perform_query(
56+
tcx: TyCtxt<'_, 'gcx, 'tcx>,
57+
canonicalized: Canonicalized<'gcx, Self::QueryKey>,
58+
) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>> {
59+
tcx.dropck_outlives(canonicalized)
60+
}
61+
62+
fn upcast_result(
63+
lifted_query_result: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
64+
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>> {
65+
lifted_query_result
5166
}
5267
}

src/librustc_mir/borrow_check/nll/type_check/liveness.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use borrow_check::nll::type_check::AtLocation;
1313
use dataflow::move_paths::{HasMoveData, MoveData};
1414
use dataflow::MaybeInitializedPlaces;
1515
use dataflow::{FlowAtLocation, FlowsAtLocation};
16+
use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
1617
use rustc::infer::canonical::QueryRegionConstraint;
1718
use rustc::mir::Local;
1819
use rustc::mir::{BasicBlock, Location, Mir};
1920
use rustc::traits::query::type_op::outlives::DropckOutlives;
2021
use rustc::traits::query::type_op::TypeOp;
21-
use rustc::ty::subst::Kind;
2222
use rustc::ty::{Ty, TypeFoldable};
2323
use rustc_data_structures::fx::FxHashMap;
2424
use std::rc::Rc;
@@ -71,7 +71,7 @@ where
7171
}
7272

7373
struct DropData<'tcx> {
74-
dropped_kinds: Vec<Kind<'tcx>>,
74+
dropck_result: DropckOutlivesResult<'tcx>,
7575
region_constraint_data: Option<Rc<Vec<QueryRegionConstraint<'tcx>>>>,
7676
}
7777

@@ -202,10 +202,16 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo
202202
self.cx.push_region_constraints(location.at_self(), data);
203203
}
204204

205+
drop_data.dropck_result.report_overflows(
206+
self.cx.infcx.tcx,
207+
self.mir.source_info(location).span,
208+
dropped_ty,
209+
);
210+
205211
// All things in the `outlives` array may be touched by
206212
// the destructor and must be live at this point.
207213
let cause = Cause::DropVar(dropped_local, location);
208-
for &kind in &drop_data.dropped_kinds {
214+
for &kind in &drop_data.dropck_result.kinds {
209215
Self::push_type_live_constraint(&mut self.cx, kind, location, cause);
210216
}
211217
}
@@ -217,12 +223,12 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo
217223
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
218224

219225
let param_env = cx.param_env;
220-
let (dropped_kinds, region_constraint_data) = DropckOutlives::new(param_env, dropped_ty)
226+
let (dropck_result, region_constraint_data) = DropckOutlives::new(param_env, dropped_ty)
221227
.fully_perform(cx.infcx)
222228
.unwrap();
223229

224230
DropData {
225-
dropped_kinds,
231+
dropck_result,
226232
region_constraint_data,
227233
}
228234
}

0 commit comments

Comments
 (0)