From 249b356fb3dba0998dbaef34980c9dd1c1e42f48 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Thu, 3 Oct 2013 03:59:58 -0400 Subject: [PATCH] make unit structs immediate struct Foo; fn foo() -> Foo { Foo } Before: ; Function Attrs: nounwind readnone uwtable define void @_ZN3foo18he8ca29755dedebbaf4v0.0E(%struct.Foo* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture) #0 { "function top level": ret void } After: ; Function Attrs: nounwind readnone uwtable define %struct.Foo @_ZN3foo18he8ca29755dedebbaf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 { "function top level": ret %struct.Foo undef } --- src/librustc/middle/trans/common.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index bbed6324543..b1b7441f243 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -75,6 +75,9 @@ pub fn type_is_immediate(ccx: &mut CrateContext, ty: ty::t) -> bool { } match ty::get(ty).sty { // FIXME: #9651: small `ty_struct` should also be immediate + ty::ty_struct(def_id, ref substs) => { + ty::struct_fields(tcx, def_id, substs).is_empty() + } ty::ty_enum(*) | ty::ty_tup(*) => { let llty = sizing_type_of(ccx, ty); llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type)