@@ -1704,6 +1704,61 @@ pub fn trans_enum_variant(ccx: &CrateContext,
17041704 llfndecl) ;
17051705}
17061706
1707+ pub fn trans_enum_variant_constructor<' a>( mut bcx: & ' a Block <' a>,
1708+ ctor_ty: ty:: t,
1709+ disr: ty:: Disr ,
1710+ args: callee:: CallArgs ,
1711+ dest: expr:: Dest ) -> Result <' a> {
1712+
1713+ let ccx = bcx. fcx. ccx;
1714+ let tcx = & ccx. tcx;
1715+
1716+ let result_ty = match ty:: get( ctor_ty) . sty {
1717+ ty:: ty_bare_fn( ref bft) => bft. sig. output,
1718+ _ => ccx. sess( ) . bug(
1719+ format!( "trans_enum_variant_constructor: \
1720+ unexpected ctor return type {}",
1721+ ctor_ty. repr( tcx) ) . as_slice( ) )
1722+ } ;
1723+
1724+ // Get location to store the result. If the user does not care about
1725+ // the result, just make a stack slot
1726+ let llresult = match dest {
1727+ expr:: SaveIn ( d) => d,
1728+ expr:: Ignore => {
1729+ if !type_is_zero_size( ccx, result_ty) {
1730+ alloc_ty( bcx, result_ty, "constructor_result" )
1731+ } else {
1732+ C_undef ( type_of:: type_of( ccx, result_ty) )
1733+ }
1734+ }
1735+ } ;
1736+
1737+ if !type_is_zero_size( ccx, result_ty) {
1738+ let repr = adt:: represent_type( ccx, result_ty) ;
1739+ adt:: trans_start_init( bcx, & * repr, llresult, disr) ;
1740+
1741+ match args {
1742+ callee:: ArgExprs ( exprs) => {
1743+ for ( i, expr) in exprs. iter( ) . enumerate( ) {
1744+ let lldestptr = adt:: trans_field_ptr( bcx, & * repr, llresult, disr, i) ;
1745+ bcx = expr:: trans_into( bcx, * expr, expr:: SaveIn ( lldestptr) ) ;
1746+ }
1747+ }
1748+ _ => ccx. sess( ) . bug( "expected expr as arguments for variant/struct tuple constructor" )
1749+ }
1750+ }
1751+
1752+ // If the caller doesn't care about the result
1753+ // drop the temporary we made
1754+ let bcx = match dest {
1755+ expr:: SaveIn ( _) => bcx,
1756+ expr:: Ignore => glue:: drop_ty( bcx, llresult, result_ty)
1757+ } ;
1758+
1759+ Result :: new( bcx, llresult)
1760+ }
1761+
17071762pub fn trans_tuple_struct( ccx: & CrateContext ,
17081763 _fields: & [ ast:: StructField ] ,
17091764 ctor_id: ast:: NodeId ,
0 commit comments