Skip to content

Commit 1882ef2

Browse files
committed
---
yaml --- r: 138923 b: refs/heads/try2 c: 122e4a2 h: refs/heads/master i: 138921: c8debb7 138919: b12f278 v: v3
1 parent ed70f23 commit 1882ef2

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c929ddde1650b4cde91efd435d7807dd313c2e9b
8+
refs/heads/try2: 122e4a28b83ca0d3b3aef9b39eed414da54c4523
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/consts.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
182182
}
183183
Some(@ty::AutoDerefRef(ref adj)) => {
184184
let mut ty = ety;
185+
let mut maybe_ptr = None;
185186
for adj.autoderefs.times {
186187
let (dv, dt) = const_deref(cx, llconst, ty, false);
188+
maybe_ptr = Some(llconst);
187189
llconst = dv;
188190
ty = dt;
189191
}
@@ -193,17 +195,21 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
193195
Some(ref autoref) => {
194196
fail_unless!(autoref.region == ty::re_static);
195197
fail_unless!(autoref.mutbl != ast::m_mutbl);
198+
// Don't copy data to do a deref+ref.
199+
let llptr = match maybe_ptr {
200+
Some(ptr) => ptr,
201+
None => const_addr_of(cx, llconst)
202+
};
196203
match autoref.kind {
197204
ty::AutoPtr => {
198-
llconst = const_addr_of(cx, llconst);
205+
llconst = llptr;
199206
}
200207
ty::AutoBorrowVec => {
201-
let base = const_addr_of(cx, llconst);
202208
let size = machine::llsize_of(cx,
203209
val_ty(llconst));
204210
fail_unless!(abi::slice_elt_base == 0);
205211
fail_unless!(abi::slice_elt_len == 1);
206-
llconst = C_struct(~[base, size]);
212+
llconst = C_struct(~[llptr, size]);
207213
}
208214
_ => {
209215
cx.sess.span_bug(e.span,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 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+
type Big = [u64 * 8];
12+
struct Pair { a: int, b: &'self Big }
13+
const x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
14+
const y: &'static Pair<'static> = &Pair {a: 15, b: x};
15+
16+
pub fn main() {
17+
fail_unless!(ptr::addr_of(x) == ptr::addr_of(y.b));
18+
}

0 commit comments

Comments
 (0)