Skip to content

Commit ef6b24d

Browse files
committed
rustc: fix the fact that trans_lvalue rooted twice
1 parent 14bf5c4 commit ef6b24d

File tree

3 files changed

+29
-55
lines changed

3 files changed

+29
-55
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ pub fn root_pats_as_necessary(bcx: block,
966966
967967
let datum = Datum {val: val, ty: node_id_type(bcx, pat_id),
968968
mode: ByRef, source: ZeroMem};
969-
bcx = datum.root(bcx, br.pats[col].span, root_info);
969+
bcx = datum.root(bcx, br.pats[col].span, key, root_info);
970970
// If we kept going, we'd only re-root the same value, so
971971
// return now.
972972
return bcx;

src/librustc/middle/trans/datum.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,17 @@ pub impl Datum {
517517
}
518518
}
519519

520-
fn root(&self, mut bcx: block, span: span, root_info: RootInfo) -> block {
520+
fn root(&self, mut bcx: block, span: span,
521+
root_key: root_map_key, root_info: RootInfo) -> block {
521522
/*!
522523
*
523524
* In some cases, borrowck will decide that an @T/@[]/@str
524525
* value must be rooted for the program to be safe. In that
525526
* case, we will call this function, which will stash a copy
526527
* away until we exit the scope `scope_id`. */
527528

528-
debug!("root(root_info=%?, self=%?)",
529-
root_info, self.to_str(bcx.ccx()));
529+
debug!("root(root_map_key=%?, root_info=%?, self=%?)",
530+
root_key, root_info, self.to_str(bcx.ccx()));
530531

531532
if bcx.sess().trace() {
532533
trans_trace(
@@ -674,7 +675,7 @@ pub impl Datum {
674675
let key = root_map_key { id: expr_id, derefs: derefs };
675676
let bcx = match ccx.maps.root_map.find(&key) {
676677
None => bcx,
677-
Some(&root_info) => self.root(bcx, span, root_info)
678+
Some(&root_info) => self.root(bcx, span, key, root_info)
678679
};
679680

680681
// Perform the write guard, if necessary.

src/librustc/middle/trans/expr.rs

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -821,57 +821,30 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
821821

822822
trace_span!(bcx, expr.span, @shorten(bcx.expr_to_str(expr)));
823823

824-
let unrooted_datum = unpack_datum!(bcx, unrooted(bcx, expr));
825-
826-
// If the lvalue must remain rooted, create a scratch datum, copy
827-
// the lvalue in there, and then arrange for it to be cleaned up
828-
// at the end of the scope with id `scope_id`:
829-
let root_key = root_map_key { id: expr.id, derefs: 0u };
830-
for bcx.ccx().maps.root_map.find(&root_key).each |&root_info| {
831-
bcx = unrooted_datum.root(bcx, expr.span, *root_info);
832-
}
833-
834-
return DatumBlock {bcx: bcx, datum: unrooted_datum};
835-
836-
fn unrooted(bcx: block, expr: @ast::expr) -> DatumBlock {
837-
/*!
838-
*
839-
* Translates `expr`. Note that this version generally
840-
* yields an unrooted, unmoved version. Rooting and possible
841-
* moves are dealt with above in trans_lvalue_unadjusted().
842-
*
843-
* One exception is if `expr` refers to a local variable,
844-
* in which case the source may already be FromMovedLvalue
845-
* if appropriate.
846-
*/
847-
848-
let mut bcx = bcx;
849-
850-
match expr.node {
851-
ast::expr_paren(e) => {
852-
return unrooted(bcx, e);
853-
}
854-
ast::expr_path(_) => {
855-
return trans_def_lvalue(bcx, expr, bcx.def(expr.id));
856-
}
857-
ast::expr_field(base, ident, _) => {
858-
return trans_rec_field(bcx, base, ident);
859-
}
860-
ast::expr_index(base, idx) => {
861-
return trans_index(bcx, expr, base, idx);
862-
}
863-
ast::expr_unary(ast::deref, base) => {
864-
let basedatum = unpack_datum!(bcx, trans_to_datum(bcx, base));
865-
return basedatum.deref(bcx, base, 0);
866-
}
867-
_ => {
868-
bcx.tcx().sess.span_bug(
869-
expr.span,
870-
fmt!("trans_lvalue reached fall-through case: %?",
871-
expr.node));
872-
}
824+
return match expr.node {
825+
ast::expr_paren(e) => {
826+
unrooted(bcx, e)
873827
}
874-
}
828+
ast::expr_path(_) => {
829+
trans_def_lvalue(bcx, expr, bcx.def(expr.id))
830+
}
831+
ast::expr_field(base, ident, _) => {
832+
trans_rec_field(bcx, base, ident)
833+
}
834+
ast::expr_index(base, idx) => {
835+
trans_index(bcx, expr, base, idx)
836+
}
837+
ast::expr_unary(ast::deref, base) => {
838+
let basedatum = unpack_datum!(bcx, trans_to_datum(bcx, base));
839+
basedatum.deref(bcx, base, 0)
840+
}
841+
_ => {
842+
bcx.tcx().sess.span_bug(
843+
expr.span,
844+
fmt!("trans_lvalue reached fall-through case: %?",
845+
expr.node));
846+
}
847+
};
875848

876849
fn trans_rec_field(bcx: block,
877850
base: @ast::expr,

0 commit comments

Comments
 (0)