librustc: Implement unit-like struct constants. r=brson

This commit is contained in:
Patrick Walton 2012-11-30 18:32:50 -08:00
parent 8fa306a0ad
commit 1088006ed9
2 changed files with 15 additions and 0 deletions

View File

@ -410,6 +410,11 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
C_named_struct(llty, ~[ lldiscrim, C_null(llstructtys[1]) ])
}
Some(ast::def_class(_)) => {
let ety = ty::expr_ty(cx.tcx, e);
let llty = type_of::type_of(cx, ety);
C_null(llty)
}
_ => {
cx.sess.span_bug(e.span,
~"expected a const, fn, or variant def")

View File

@ -0,0 +1,10 @@
struct Foo;
const X: Foo = Foo;
fn main() {
match X {
Foo => {}
}
}