@@ -1986,7 +1986,7 @@ pub fn trans_struct_dtor(ccx: @crate_ctxt,
1986
1986
}
1987
1987
1988
1988
pub fn trans_enum_def( ccx: @crate_ctxt, enum_definition: ast:: enum_def,
1989
- id: ast:: node_id, degen: bool ,
1989
+ id: ast:: node_id, tps : ~ [ ast :: ty_param ] , degen: bool ,
1990
1990
path: @ast_map:: path, vi: @~[ ty:: VariantInfo ] ,
1991
1991
i: & mut uint) {
1992
1992
for vec:: each( enum_definition. variants) |variant| {
@@ -2003,13 +2003,14 @@ pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
2003
2003
// Nothing to do.
2004
2004
}
2005
2005
ast:: struct_variant_kind( struct_def) => {
2006
- trans_struct_def ( ccx, struct_def, path,
2006
+ trans_struct_def ( ccx, struct_def, /*bad*/ copy tps , path,
2007
2007
variant. node . id ) ;
2008
2008
}
2009
2009
ast:: enum_variant_kind( ref enum_definition) => {
2010
2010
trans_enum_def ( ccx,
2011
2011
* enum_definition,
2012
2012
id,
2013
+ /*bad*/ copy tps,
2013
2014
degen,
2014
2015
path,
2015
2016
vi,
@@ -2061,11 +2062,11 @@ pub fn trans_item(ccx: @crate_ctxt, item: ast::item) {
2061
2062
trans_mod ( ccx, m) ;
2062
2063
}
2063
2064
ast:: item_enum( ref enum_definition, ref tps) => {
2064
- if tps. is_empty ( ) {
2065
+ if tps. len ( ) == 0 u {
2065
2066
let degen = ( * enum_definition) . variants . len ( ) == 1 u;
2066
2067
let vi = ty:: enum_variants ( ccx. tcx , local_def ( item. id ) ) ;
2067
2068
let mut i = 0 ;
2068
- trans_enum_def ( ccx, ( * enum_definition) , item. id ,
2069
+ trans_enum_def ( ccx, ( * enum_definition) , item. id , /*bad*/ copy * tps ,
2069
2070
degen, path, vi, & mut i) ;
2070
2071
}
2071
2072
}
@@ -2079,33 +2080,35 @@ pub fn trans_item(ccx: @crate_ctxt, item: ast::item) {
2079
2080
foreign:: trans_foreign_mod ( ccx, foreign_mod, abi) ;
2080
2081
}
2081
2082
ast:: item_struct( struct_def, tps) => {
2082
- if tps. is_empty ( ) {
2083
- trans_struct_def ( ccx, struct_def, path, item. id ) ;
2084
- }
2083
+ trans_struct_def ( ccx, struct_def, tps, path, item. id ) ;
2085
2084
}
2086
2085
_ => { /* fall through */ }
2087
2086
}
2088
2087
}
2089
2088
2090
2089
pub fn trans_struct_def ( ccx : @crate_ctxt , struct_def : @ast:: struct_def ,
2091
- path : @ast_map:: path ,
2090
+ tps : ~ [ ast :: ty_param ] , path : @ast_map:: path ,
2092
2091
id : ast:: node_id ) {
2093
- // Translate the destructor.
2094
- do option:: iter ( & struct_def. dtor ) |dtor| {
2095
- trans_struct_dtor ( ccx, /*bad*/ copy * path, dtor. node . body ,
2096
- dtor. node . id , None , None , local_def ( id) ) ;
2097
- } ;
2092
+ // If there are type parameters, the destructor and constructor will be
2093
+ // monomorphized, so we don't translate them here.
2094
+ if tps. len ( ) == 0 u {
2095
+ // Translate the destructor.
2096
+ do option:: iter ( & struct_def. dtor ) |dtor| {
2097
+ trans_struct_dtor ( ccx, /*bad*/ copy * path, dtor. node . body ,
2098
+ dtor. node . id , None , None , local_def ( id) ) ;
2099
+ } ;
2098
2100
2099
- // If this is a tuple-like struct, translate the constructor.
2100
- match struct_def. ctor_id {
2101
- // We only need to translate a constructor if there are fields;
2102
- // otherwise this is a unit-like struct.
2103
- Some ( ctor_id) if struct_def. fields . len ( ) > 0 => {
2104
- let llfndecl = get_item_val ( ccx, ctor_id) ;
2105
- trans_tuple_struct ( ccx, /*bad*/ copy struct_def. fields ,
2106
- ctor_id, None , llfndecl) ;
2101
+ // If this is a tuple-like struct, translate the constructor.
2102
+ match struct_def. ctor_id {
2103
+ // We only need to translate a constructor if there are fields;
2104
+ // otherwise this is a unit-like struct.
2105
+ Some ( ctor_id) if struct_def. fields . len ( ) > 0 => {
2106
+ let llfndecl = get_item_val ( ccx, ctor_id) ;
2107
+ trans_tuple_struct ( ccx, /*bad*/ copy struct_def. fields ,
2108
+ ctor_id, None , llfndecl) ;
2109
+ }
2110
+ Some ( _) | None => { }
2107
2111
}
2108
- Some ( _) | None => { }
2109
2112
}
2110
2113
}
2111
2114
0 commit comments