Skip to content

Commit 63eb4d9

Browse files
committed
move during_closure_kind_inference flag to mc
We used to put the flag on the `InferCtxt`.
1 parent 8ffc04b commit 63eb4d9

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

src/librustc/infer/mod.rs

-16
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
175175
// any obligations set during the current snapshot. In that case, the
176176
// snapshot can't be rolled back.
177177
pub obligations_in_snapshot: Cell<bool>,
178-
179-
// This is false except during closure kind inference. It is used
180-
// by the mem-categorization code to be able to have stricter
181-
// assertions (which are always true except during upvar
182-
// inference).
183-
during_closure_kind_inference: Cell<bool>,
184178
}
185179

186180
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -497,7 +491,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
497491
tainted_by_errors_flag: Cell::new(false),
498492
err_count_on_creation: self.sess.err_count(),
499493
obligations_in_snapshot: Cell::new(false),
500-
during_closure_kind_inference: Cell::new(false),
501494
}
502495
}
503496
}
@@ -539,7 +532,6 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
539532
tainted_by_errors_flag: Cell::new(false),
540533
err_count_on_creation: tcx.sess.err_count(),
541534
obligations_in_snapshot: Cell::new(false),
542-
during_closure_kind_inference: Cell::new(false),
543535
}))
544536
}
545537
}
@@ -1302,14 +1294,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13021294
.map(|method| resolve_ty(method.ty)))
13031295
}
13041296

1305-
pub fn set_during_closure_kind_inference(&self, value: bool) {
1306-
self.during_closure_kind_inference.set(value);
1307-
}
1308-
1309-
pub fn during_closure_kind_inference(&self) -> bool {
1310-
self.during_closure_kind_inference.get()
1311-
}
1312-
13131297
/// True if errors have been reported since this infcx was
13141298
/// created. This is sometimes used as a heuristic to skip
13151299
/// reporting errors that often occur as a result of earlier

src/librustc/middle/expr_use_visitor.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,19 @@ enum PassArgs {
271271

272272
impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
273273
pub fn new(delegate: &'a mut (Delegate<'tcx>+'a),
274-
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self
274+
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
275+
-> Self
276+
{
277+
ExprUseVisitor::with_options(delegate, infcx, mc::MemCategorizationOptions::default())
278+
}
279+
280+
pub fn with_options(delegate: &'a mut (Delegate<'tcx>+'a),
281+
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
282+
options: mc::MemCategorizationOptions)
283+
-> Self
275284
{
276285
ExprUseVisitor {
277-
mc: mc::MemCategorizationContext::new(infcx),
286+
mc: mc::MemCategorizationContext::with_options(infcx, options),
278287
delegate: delegate
279288
}
280289
}

src/librustc/middle/mem_categorization.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ impl ast_node for hir::Pat {
259259
#[derive(Copy, Clone)]
260260
pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
261261
pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
262+
options: MemCategorizationOptions,
263+
}
264+
265+
#[derive(Copy, Clone, Default)]
266+
pub struct MemCategorizationOptions {
267+
// If true, then when analyzing a closure upvar, if the closure
268+
// has a missing kind, we treat it like a Fn closure. When false,
269+
// we ICE if the closure has a missing kind. Should be false
270+
// except during closure kind inference. It is used by the
271+
// mem-categorization code to be able to have stricter assertions
272+
// (which are always true except during upvar inference).
273+
pub during_closure_kind_inference: bool,
262274
}
263275

264276
pub type McResult<T> = Result<T, ()>;
@@ -362,8 +374,15 @@ impl MutabilityCategory {
362374
impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
363375
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
364376
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
377+
MemCategorizationContext::with_options(infcx, MemCategorizationOptions::default())
378+
}
379+
380+
pub fn with_options(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
381+
options: MemCategorizationOptions)
382+
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
365383
MemCategorizationContext {
366384
infcx: infcx,
385+
options: options,
367386
}
368387
}
369388

@@ -586,7 +605,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
586605
self.cat_upvar(id, span, var_id, fn_node_id, kind)
587606
}
588607
None => {
589-
if !self.infcx.during_closure_kind_inference() {
608+
if !self.options.during_closure_kind_inference {
590609
span_bug!(
591610
span,
592611
"No closure kind for {:?}",

src/librustc_typeck/check/upvar.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,13 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
171171
debug!("analyze_closure(id={:?}, body.id={:?})", id, body.id);
172172

173173
{
174-
self.fcx.set_during_closure_kind_inference(true);
175-
let mut euv = euv::ExprUseVisitor::new(self, self.fcx);
174+
let mut euv =
175+
euv::ExprUseVisitor::with_options(self,
176+
self.fcx,
177+
mc::MemCategorizationOptions {
178+
during_closure_kind_inference: true
179+
});
176180
euv.walk_fn(decl, body);
177-
self.fcx.set_during_closure_kind_inference(false);
178181
}
179182

180183
// Now that we've analyzed the closure, we know how each

0 commit comments

Comments
 (0)