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.
This commit is contained in:
parent
4e5666eace
commit
931f59f214
1 changed files with 15 additions and 11 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue