Skip to content

Commit e953773

Browse files
committed
rollup merge of rust-lang#18250 : dotdash/fix_aliasing
2 parents a6883d4 + 70fe20a commit e953773

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
940940
controlflow::trans_loop(bcx, expr.id, &**body)
941941
}
942942
ast::ExprAssign(ref dst, ref src) => {
943+
let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
943944
let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &**dst, "assign"));
944945

945946
if ty::type_needs_drop(bcx.tcx(), dst_datum.ty) {
@@ -960,7 +961,6 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
960961
// We could avoid this intermediary with some analysis
961962
// to determine whether `dst` may possibly own `src`.
962963
debuginfo::set_source_location(bcx.fcx, expr.id, expr.span);
963-
let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
964964
let src_datum = unpack_datum!(
965965
bcx, src_datum.to_rvalue_datum(bcx, "ExprAssign"));
966966
bcx = glue::drop_ty(bcx,
@@ -969,7 +969,7 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
969969
Some(NodeInfo { id: expr.id, span: expr.span }));
970970
src_datum.store_to(bcx, dst_datum.val)
971971
} else {
972-
trans_into(bcx, &**src, SaveIn(dst_datum.to_llref()))
972+
src_datum.store_to(bcx, dst_datum.val)
973973
}
974974
}
975975
ast::ExprAssignOp(op, ref dst, ref src) => {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct Foo {
12+
f1: int,
13+
_f2: int,
14+
}
15+
16+
#[inline(never)]
17+
pub fn foo(f: &mut Foo) -> Foo {
18+
let ret = *f;
19+
f.f1 = 0;
20+
ret
21+
}
22+
23+
pub fn main() {
24+
let mut f = Foo {
25+
f1: 8,
26+
_f2: 9,
27+
};
28+
f = foo(&mut f);
29+
assert_eq!(f.f1, 8);
30+
}

0 commit comments

Comments
 (0)