Skip to content

Commit 931f59f

Browse files
committed
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.
1 parent 4e5666e commit 931f59f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -604,17 +604,21 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
604604
ty::FnMutUnboxedClosureKind => ast::Many,
605605
ty::FnOnceUnboxedClosureKind => ast::Once,
606606
};
607-
Ok(Rc::new(cmt_ {
608-
id: id,
609-
span: span,
610-
cat: cat_copied_upvar(CopiedUpvar {
611-
upvar_id: var_id,
612-
onceness: onceness,
613-
capturing_proc: fn_node_id,
614-
}),
615-
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
616-
ty: expr_ty
617-
}))
607+
if self.typer.capture_mode(fn_node_id) == ast::CaptureByRef {
608+
self.cat_upvar(id, span, var_id, fn_node_id)
609+
} else {
610+
Ok(Rc::new(cmt_ {
611+
id: id,
612+
span: span,
613+
cat: cat_copied_upvar(CopiedUpvar {
614+
upvar_id: var_id,
615+
onceness: onceness,
616+
capturing_proc: fn_node_id,
617+
}),
618+
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
619+
ty: expr_ty
620+
}))
621+
}
618622
}
619623
_ => {
620624
self.tcx().sess.span_bug(

0 commit comments

Comments
 (0)