librustc: Implement unit-like struct constants. r=brson
This commit is contained in:
parent
8fa306a0ad
commit
1088006ed9
@ -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")
|
||||
|
10
src/test/run-pass/const-unit-struct.rs
Normal file
10
src/test/run-pass/const-unit-struct.rs
Normal file
@ -0,0 +1,10 @@
|
||||
struct Foo;
|
||||
|
||||
const X: Foo = Foo;
|
||||
|
||||
fn main() {
|
||||
match X {
|
||||
Foo => {}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user