Skip to content

Commit c18a1f3

Browse files
committed
---
yaml --- r: 22985 b: refs/heads/master c: 488ece0 h: refs/heads/master i: 22983: 977f6e9 v: v3
1 parent 999670b commit c18a1f3

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e02b1b1ec8696715c08fc970b67d9eaa6c91b15e
2+
refs/heads/master: 488ece05b59b68a7d25c1fc59388438a78bb0b52
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/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)

trunk/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");

trunk/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
}

trunk/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) }

trunk/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)