Skip to content

Commit 1088006

Browse files
committed
librustc: Implement unit-like struct constants. r=brson
1 parent 8fa306a commit 1088006

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
410410

411411
C_named_struct(llty, ~[ lldiscrim, C_null(llstructtys[1]) ])
412412
}
413+
Some(ast::def_class(_)) => {
414+
let ety = ty::expr_ty(cx.tcx, e);
415+
let llty = type_of::type_of(cx, ety);
416+
C_null(llty)
417+
}
413418
_ => {
414419
cx.sess.span_bug(e.span,
415420
~"expected a const, fn, or variant def")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Foo;
2+
3+
const X: Foo = Foo;
4+
5+
fn main() {
6+
match X {
7+
Foo => {}
8+
}
9+
}
10+

0 commit comments

Comments
 (0)