Skip to content

Commit b1ec0a5

Browse files
committed
Default methods get through compilation, but not linkage (cc: #2794).
1 parent 0e0833e commit b1ec0a5

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/rustc/middle/trans/base.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -5217,12 +5217,13 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id,
52175217
}
52185218

52195219
fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5220+
debug!{"get_item_val(id=`%?`)", id};
52205221
let tcx = ccx.tcx;
52215222
match ccx.item_vals.find(id) {
52225223
some(v) => v,
52235224
none => {
52245225
let mut exprt = false;
5225-
let val = match check ccx.tcx.items.get(id) {
5226+
let val = match ccx.tcx.items.get(id) {
52265227
ast_map::node_item(i, pth) => {
52275228
let my_path = vec::append(*pth, ~[path_name(i.ident)]);
52285229
match check i.node {
@@ -5246,11 +5247,33 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
52465247
}
52475248
}
52485249
}
5250+
ast_map::node_trait_method(trait_method, _, pth) => {
5251+
debug!{"get_item_val(): processing a node_trait_method"};
5252+
match *trait_method {
5253+
ast::required(_) => {
5254+
ccx.sess.bug(~"unexpected variant: required trait method in \
5255+
get_item_val()");
5256+
}
5257+
ast::provided(m) => {
5258+
// FIXME (#2794): Default methods currently compiling but not
5259+
// linking successfully; not sure if this is correct. It's
5260+
// just copypasta from the node_method case.
5261+
exprt = true;
5262+
let mty = ty::node_id_to_type(ccx.tcx, id);
5263+
let pth =
5264+
vec::append(*pth, ~[path_name(@ccx.names(~"meth")),
5265+
path_name(m.ident)]);
5266+
let llfn = register_fn_full(ccx, m.span, pth, id, mty);
5267+
set_inline_hint_if_appr(m.attrs, llfn);
5268+
llfn
5269+
}
5270+
}
5271+
}
52495272
ast_map::node_method(m, impl_id, pth) => {
52505273
exprt = true;
52515274
let mty = ty::node_id_to_type(ccx.tcx, id);
52525275
let pth = vec::append(*pth, ~[path_name(@ccx.names(~"meth")),
5253-
path_name(m.ident)]);
5276+
path_name(m.ident)]);
52545277
let llfn = register_fn_full(ccx, m.span, pth, id, mty);
52555278
set_inline_hint_if_appr(m.attrs, llfn);
52565279
llfn
@@ -5310,6 +5333,9 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
53105333
set_inline_hint(llfn);
53115334
llfn
53125335
}
5336+
_ => {
5337+
ccx.sess.bug(~"get_item_val(): unexpected variant");
5338+
}
53135339
};
53145340
if !(exprt || ccx.reachable.contains_key(id)) {
53155341
lib::llvm::SetLinkage(val, lib::llvm::InternalLinkage);

0 commit comments

Comments
 (0)