From 931f59f214f68bf2a5656d605cb200f22d47cdf8 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Wed, 1 Oct 2014 23:52:19 -0700 Subject: [PATCH] Fix categorization of upvars of capture-by-reference unboxed closures In particular, this causes mutation of an upvar to correctly mark it as mutable during adjustment. This makes borrowck correctly flag conflicting borrows, etc. We still seem to generate incorrect code in trans which copies the upvar by value into the closure. This remains to be fixed. --- src/librustc/middle/mem_categorization.rs | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index bb44b1f55cb4..b62884c057a5 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -604,17 +604,21 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { ty::FnMutUnboxedClosureKind => ast::Many, ty::FnOnceUnboxedClosureKind => ast::Once, }; - Ok(Rc::new(cmt_ { - id: id, - span: span, - cat: cat_copied_upvar(CopiedUpvar { - upvar_id: var_id, - onceness: onceness, - capturing_proc: fn_node_id, - }), - mutbl: MutabilityCategory::from_local(self.tcx(), var_id), - ty: expr_ty - })) + if self.typer.capture_mode(fn_node_id) == ast::CaptureByRef { + self.cat_upvar(id, span, var_id, fn_node_id) + } else { + Ok(Rc::new(cmt_ { + id: id, + span: span, + cat: cat_copied_upvar(CopiedUpvar { + upvar_id: var_id, + onceness: onceness, + capturing_proc: fn_node_id, + }), + mutbl: MutabilityCategory::from_local(self.tcx(), var_id), + ty: expr_ty + })) + } } _ => { self.tcx().sess.span_bug(