Skip to content

Commit fb05f57

Browse files
committed
Compile default methods; un-xfail default methods test (cc: #2794).
1 parent 8271b3f commit fb05f57

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,6 +5023,9 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
50235023
ast::item_class(struct_def, tps) => {
50245024
trans_struct_def(ccx, struct_def, tps, path, item.ident, item.id);
50255025
}
5026+
ast::item_trait(tps, _, trait_methods) => {
5027+
trans_trait(ccx, tps, trait_methods, path, item.ident);
5028+
}
50265029
_ => {/* fall through */ }
50275030
}
50285031
}
@@ -5051,6 +5054,14 @@ fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
50515054
impl::trans_impl(ccx, *path, ident, ms, tps);
50525055
}
50535056

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+
50545065
// Translate a module. Doing this amounts to translating the items in the
50555066
// module; there ends up being no artifact (aside from linkage names) of
50565067
// 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 {
52755286
get_item_val()");
52765287
}
52775288
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.
52815289
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)
52895291
}
52905292
}
52915293
}
5292-
ast_map::node_method(m, impl_id, pth) => {
5294+
ast_map::node_method(m, _, pth) => {
52935295
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)
53005297
}
53015298
ast_map::node_foreign_item(ni, _, pth) => {
53025299
exprt = true;
@@ -5336,7 +5333,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
53365333
assert args.len() != 0u;
53375334
let pth = vec::append(*pth,
53385335
~[path_name(enm.ident),
5339-
path_name(v.node.name)]);
5336+
path_name(v.node.name)]);
53405337
llfn = match check enm.node {
53415338
ast::item_enum(_, _) => {
53425339
register_fn(ccx, v.span, pth, id)
@@ -5366,6 +5363,16 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
53665363
}
53675364
}
53685365

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+
53695376
// The constant translation pass.
53705377
fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
53715378
let _icx = ccx.insn_ctxt(~"trans_constant");

src/test/run-pass/traits-default-method-trivial.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//xfail-test
2-
31
trait Cat {
42
fn meow() -> bool;
53
fn scratch() -> bool;

0 commit comments

Comments
 (0)