Skip to content

Commit 6782868

Browse files
bogglegraydon
authored andcommitted
---
yaml --- r: 6560 b: refs/heads/master c: 68a82e4 h: refs/heads/master v: v3
1 parent 8d67489 commit 6782868

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3ee2eb656e36ff9bcf5d5c13fe311e423dba9dd4
2+
refs/heads/master: 68a82e44684a25314ded58349815bf6d1bc3c74a

trunk/src/comp/middle/check_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn check_expr(sess: session, e: @expr, &&is_const: bool, v: visit::vt<bool>) {
4343
"disallowed operator in constant expression");
4444
ret;
4545
}
46+
expr_cast(_, _) { }
4647
expr_lit(@{node: lit_str(_), _}) {
4748
sess.span_err(e.span,
4849
"string constants are not supported");

trunk/src/comp/middle/trans.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,6 +5184,16 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
51845184
// that does so later on?
51855185
fn trans_const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
51865186
alt e.node {
5187+
ast::expr_cast(e1, _) {
5188+
alt ccx_tcx(cx).cast_map.find(e.id) {
5189+
some(ty::triv_cast.) { trans_const_expr(cx, e1) }
5190+
_ {
5191+
cx.sess.span_err(e.span,
5192+
"non-trivial cast in constant expression");
5193+
fail;
5194+
}
5195+
}
5196+
}
51875197
ast::expr_lit(lit) { ret trans_crate_lit(cx, *lit); }
51885198
ast::expr_binary(b, e1, e2) {
51895199
let te1 = trans_const_expr(cx, e1);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std;
2+
3+
import std::ctypes::*;
4+
5+
// This will be more interesting once there is support
6+
// for consts that refer to other consts, i.e. math_f64::consts::pi as m_float
7+
#[cfg(target_arch="x86")]
8+
const foo: m_int = 0i32 as m_int;
9+
10+
#[cfg(target_arch="x86_64")]
11+
const foo: m_int = 0i64 as m_int;
12+
13+
fn main() {
14+
assert foo == 0 as m_int;
15+
}

0 commit comments

Comments
 (0)