Skip to content

Commit d8287f0

Browse files
committed
rustc: Translate default methods on traits for each impl in which they're used instead of once.
This is a step on the way to default methods.
1 parent 937f8f4 commit d8287f0

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use session::session;
2121
use syntax::attr;
2222
use back::{link, abi, upcall};
2323
use syntax::{ast, ast_util, codemap, ast_map};
24-
use ast_util::{local_def, path_to_ident};
24+
use ast_util::{def_id_of_def, local_def, path_to_ident};
2525
use syntax::visit;
2626
use syntax::codemap::span;
2727
use syntax::print::pprust::{expr_to_str, stmt_to_str, path_to_str};
@@ -1847,8 +1847,33 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
18471847
}
18481848
}
18491849
}
1850-
ast::item_impl(tps, _, _, ms) => {
1850+
ast::item_impl(tps, trait_refs, _, ms) => {
18511851
meth::trans_impl(ccx, *path, item.ident, ms, tps);
1852+
1853+
// Translate any methods that have provided implementations.
1854+
for trait_refs.each |trait_ref_ptr| {
1855+
let trait_def = ccx.tcx.def_map.get(trait_ref_ptr.ref_id);
1856+
1857+
// XXX: Cross-crate default methods.
1858+
match ccx.tcx.items.get(def_id_of_def(trait_def).node) {
1859+
ast_map::node_item(trait_item, _) => {
1860+
match trait_item.node {
1861+
ast::item_trait(tps, _, trait_methods) => {
1862+
trans_trait(ccx, tps, trait_methods, path,
1863+
item.ident);
1864+
}
1865+
_ => {
1866+
ccx.tcx.sess.impossible_case(item.span,
1867+
~"trait item not a \
1868+
trait");
1869+
}
1870+
}
1871+
}
1872+
_ => {
1873+
ccx.tcx.sess.impossible_case(item.span, ~"no trait item");
1874+
}
1875+
}
1876+
}
18521877
}
18531878
ast::item_mod(m) => {
18541879
trans_mod(ccx, m);
@@ -1873,9 +1898,6 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
18731898
ast::item_class(struct_def, tps) => {
18741899
trans_struct_def(ccx, struct_def, tps, path, item.ident, item.id);
18751900
}
1876-
ast::item_trait(tps, _, trait_methods) => {
1877-
trans_trait(ccx, tps, trait_methods, path, item.ident);
1878-
}
18791901
_ => {/* fall through */ }
18801902
}
18811903
}

0 commit comments

Comments
 (0)