@@ -259,6 +259,18 @@ impl ast_node for hir::Pat {
259259#[ derive( Copy , Clone ) ]
260260pub 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
264276pub type McResult < T > = Result < T , ( ) > ;
@@ -362,8 +374,15 @@ impl MutabilityCategory {
362374impl < ' 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 {:?}" ,
0 commit comments