@@ -5023,6 +5023,9 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
5023
5023
ast:: item_class( struct_def, tps) => {
5024
5024
trans_struct_def ( ccx, struct_def, tps, path, item. ident , item. id ) ;
5025
5025
}
5026
+ ast:: item_trait( tps, _, trait_methods) => {
5027
+ trans_trait ( ccx, tps, trait_methods, path, item. ident ) ;
5028
+ }
5026
5029
_ => { /* fall through */ }
5027
5030
}
5028
5031
}
@@ -5051,6 +5054,14 @@ fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
5051
5054
impl :: trans_impl ( ccx , * path , ident , ms , tps ) ;
5052
5055
}
5053
5056
5057
+ fn trans_trait ( ccx : @crate_ctxt , tps : ~[ ast:: ty_param ] ,
5058
+ trait_methods : ~[ ast:: trait_method ] ,
5059
+ path : @ast_map:: path , ident : ast:: ident ) {
5060
+ // Translate any methods that have provided implementations
5061
+ let ( _, provided_methods) = ast_util:: split_trait_methods ( trait_methods) ;
5062
+ impl :: trans_impl ( ccx , * path , ident , provided_methods , tps ) ;
5063
+ }
5064
+
5054
5065
// Translate a module. Doing this amounts to translating the items in the
5055
5066
// module; there ends up being no artifact (aside from linkage names) of
5056
5067
// separate modules in the compiled program. That's because modules exist
@@ -5275,28 +5286,14 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5275
5286
get_item_val ( ) ") ;
5276
5287
}
5277
5288
ast:: provided( m) => {
5278
- // FIXME (#2794): Default methods currently compiling but not
5279
- // linking successfully; not sure if this is correct. It's
5280
- // just copypasta from the node_method case.
5281
5289
exprt = true ;
5282
- let mty = ty:: node_id_to_type ( ccx. tcx , id) ;
5283
- let pth =
5284
- vec:: append ( * pth, ~[ path_name ( @ccx. names ( ~"meth") ) ,
5285
- path_name ( m. ident ) ] ) ;
5286
- let llfn = register_fn_full ( ccx, m. span , pth, id, mty) ;
5287
- set_inline_hint_if_appr ( m. attrs , llfn) ;
5288
- llfn
5290
+ trans_method ( ccx, id, pth, m)
5289
5291
}
5290
5292
}
5291
5293
}
5292
- ast_map:: node_method( m, impl_id , pth) => {
5294
+ ast_map:: node_method( m, _ , pth) => {
5293
5295
exprt = true ;
5294
- let mty = ty:: node_id_to_type ( ccx. tcx , id) ;
5295
- let pth = vec:: append ( * pth, ~[ path_name ( @ccx. names ( ~"meth") ) ,
5296
- path_name ( m. ident ) ] ) ;
5297
- let llfn = register_fn_full ( ccx, m. span , pth, id, mty) ;
5298
- set_inline_hint_if_appr ( m. attrs , llfn) ;
5299
- llfn
5296
+ trans_method ( ccx, id, pth, m)
5300
5297
}
5301
5298
ast_map:: node_foreign_item( ni, _, pth) => {
5302
5299
exprt = true ;
@@ -5336,7 +5333,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5336
5333
assert args. len ( ) != 0 u;
5337
5334
let pth = vec:: append ( * pth,
5338
5335
~[ path_name ( enm. ident ) ,
5339
- path_name ( v. node . name ) ] ) ;
5336
+ path_name ( v. node . name ) ] ) ;
5340
5337
llfn = match check enm. node {
5341
5338
ast:: item_enum( _, _) => {
5342
5339
register_fn ( ccx, v. span , pth, id)
@@ -5366,6 +5363,16 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5366
5363
}
5367
5364
}
5368
5365
5366
+ fn trans_method ( ccx : @crate_ctxt , id : ast:: node_id , pth : @ast_map:: path ,
5367
+ m : @ast:: method ) -> ValueRef {
5368
+ let mty = ty:: node_id_to_type ( ccx. tcx , id) ;
5369
+ let pth = vec:: append ( * pth, ~[ path_name ( @ccx. names ( ~"meth") ) ,
5370
+ path_name ( m. ident ) ] ) ;
5371
+ let llfn = register_fn_full ( ccx, m. span , pth, id, mty) ;
5372
+ set_inline_hint_if_appr ( m. attrs , llfn) ;
5373
+ llfn
5374
+ }
5375
+
5369
5376
// The constant translation pass.
5370
5377
fn trans_constant ( ccx : @crate_ctxt , it : @ast:: item ) {
5371
5378
let _icx = ccx. insn_ctxt ( ~"trans_constant") ;
0 commit comments