Skip to content

Commit 09d7ad2

Browse files
committed
---
yaml --- r: 31647 b: refs/heads/dist-snap c: 488ece0 h: refs/heads/master i: 31645: fb94f68 31643: 03c5b56 31639: b272b72 31631: 1f425c1 31615: 91ec669 v: v3
1 parent 5042366 commit 09d7ad2

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: e02b1b1ec8696715c08fc970b67d9eaa6c91b15e
10+
refs/heads/dist-snap: 488ece05b59b68a7d25c1fc59388438a78bb0b52
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/rustc/middle/borrowck/preserve.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ impl private_methods for &preserve_ctxt {
7474
// when we borrow an rvalue, we can keep it rooted but only
7575
// up to the root_ub point
7676

77+
// When we're in a 'const &x = ...' context, self.root_ub is
78+
// zero and the rvalue is static, not bound to a scope.
79+
let scope_region = if self.root_ub == 0 {
80+
ty::re_static
81+
} else {
82+
ty::re_scope(self.root_ub)
83+
};
84+
7785
// FIXME(#2977)--need to update trans!
78-
self.compare_scope(cmt, ty::re_scope(self.root_ub))
86+
self.compare_scope(cmt, scope_region)
7987
}
8088
cat_stack_upvar(cmt) {
8189
self.preserve(cmt)

branches/dist-snap/src/rustc/middle/check_const.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@ fn check_expr(sess: session, def_map: resolve3::DefMap,
101101
}
102102
}
103103
}
104+
expr_addr_of(m_imm, _) |
104105
expr_tup(*) |
105106
expr_rec(*) { }
107+
expr_addr_of(*) {
108+
sess.span_err(
109+
e.span,
110+
~"borrowed pointers in constants may only refer to \
111+
immutable values");
112+
}
106113
_ {
107114
sess.span_err(e.span,
108115
~"constant contains unimplemented expression type");

branches/dist-snap/src/rustc/middle/trans/consts.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
130130
}
131131
}
132132
}
133+
ast::expr_addr_of(ast::m_imm, sub) {
134+
let cv = const_expr(cx, sub);
135+
let subty = ty::expr_ty(cx.tcx, sub),
136+
llty = type_of::type_of(cx, subty);
137+
let gv = do str::as_c_str("const") |name| {
138+
llvm::LLVMAddGlobal(cx.llmod, llty, name)
139+
};
140+
llvm::LLVMSetInitializer(gv, cv);
141+
llvm::LLVMSetGlobalConstant(gv, True);
142+
gv
143+
}
133144
ast::expr_tup(es) {
134145
C_struct(es.map(|e| const_expr(cx, e)))
135146
}

branches/dist-snap/src/rustc/middle/typeck/rscope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait region_scope {
88
enum empty_rscope { empty_rscope }
99
impl of region_scope for empty_rscope {
1010
fn anon_region() -> result<ty::region, ~str> {
11-
result::err(~"region types are not allowed here")
11+
result::ok(ty::re_static)
1212
}
1313
fn named_region(id: ast::ident) -> result<ty::region, ~str> {
1414
if *id == ~"static" { result::ok(ty::re_static) }

branches/dist-snap/src/test/run-pass/const-rec-and-tup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const x : (int,int) = (0xfeedf00dd,0xca11ab1e);
2-
const y : { x: (int, int),
1+
const x : (i32,i32) = (0xfeedf00dd,0xca11ab1e);
2+
const y : { x: (i64, i64),
33
y: { a: float,
44
b: float } } = { x: (0xf0f0f0f0_f0f0f0f0,
55
0xabababab_abababab),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
const x: &int = &10;
3+
4+
const y: &{a: int, b: &int} = &{a: 15, b: x};
5+
6+
fn main() {
7+
io::println(fmt!("x = %?", x));
8+
io::println(fmt!("y = {a: %?, b: %?}", y.a, *(y.b)));
9+
}

0 commit comments

Comments
 (0)