From 1088006ed9a66f7bf7f4d4768b60b8bf165c160e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 30 Nov 2012 18:32:50 -0800 Subject: [PATCH] librustc: Implement unit-like struct constants. r=brson --- src/librustc/middle/trans/consts.rs | 5 +++++ src/test/run-pass/const-unit-struct.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/test/run-pass/const-unit-struct.rs diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index e2466c1c4c65..9291c4ba3ee7 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -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") diff --git a/src/test/run-pass/const-unit-struct.rs b/src/test/run-pass/const-unit-struct.rs new file mode 100644 index 000000000000..c0a0201ed74b --- /dev/null +++ b/src/test/run-pass/const-unit-struct.rs @@ -0,0 +1,10 @@ +struct Foo; + +const X: Foo = Foo; + +fn main() { + match X { + Foo => {} + } +} +