Skip to content

Commit 1ee54a8

Browse files
committed
auto merge of #7725 : msullivan/rust/default-methods, r=pcwalton
r?
2 parents 96453eb + 3fa5203 commit 1ee54a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+185
-121
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ fn encode_info_for_method(ecx: &EncodeContext,
791791
if len > 0u || should_inline {
792792
(ecx.encode_inlined_item)(
793793
ecx, ebml_w, impl_path,
794-
ii_method(local_def(parent_id), m));
794+
ii_method(local_def(parent_id), false, m));
795795
} else {
796796
encode_symbol(ecx, ebml_w, m.id);
797797
}
@@ -1123,21 +1123,16 @@ fn encode_info_for_item(ecx: &EncodeContext,
11231123
}
11241124

11251125
provided(m) => {
1126-
// This is obviously a bogus assert but I don't think this
1127-
// ever worked before anyhow...near as I can tell, before
1128-
// we would emit two items.
1129-
if method_ty.explicit_self == sty_static {
1130-
tcx.sess.span_unimpl(
1131-
item.span,
1132-
fmt!("Method %s is both provided and static",
1133-
token::ident_to_str(&method_ty.ident)));
1126+
// If this is a static method, we've already encoded
1127+
// this.
1128+
if method_ty.explicit_self != sty_static {
1129+
encode_type_param_bounds(ebml_w, ecx,
1130+
&m.generics.ty_params);
11341131
}
1135-
encode_type_param_bounds(ebml_w, ecx,
1136-
&m.generics.ty_params);
11371132
encode_method_sort(ebml_w, 'p');
11381133
(ecx.encode_inlined_item)(
11391134
ecx, ebml_w, path,
1140-
ii_method(local_def(item.id), m));
1135+
ii_method(local_def(item.id), true, m));
11411136
}
11421137
}
11431138

src/librustc/middle/astencode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
319319
match *ii {
320320
//hack: we're not dropping items
321321
ast::ii_item(i) => ast::ii_item(fld.fold_item(i).get()),
322-
ast::ii_method(d, m) => ast::ii_method(d, fld.fold_method(m)),
322+
ast::ii_method(d, is_provided, m) =>
323+
ast::ii_method(d, is_provided, fld.fold_method(m)),
323324
ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i))
324325
}
325326
}
@@ -340,7 +341,8 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
340341

341342
match ii {
342343
ast::ii_item(i) => ast::ii_item(fld.fold_item(i).get()),
343-
ast::ii_method(d, m) => ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m)),
344+
ast::ii_method(d, is_provided, m) =>
345+
ast::ii_method(xcx.tr_def_id(d), is_provided, fld.fold_method(m)),
344346
ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)),
345347
}
346348
}

src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
244244
LintSpec {
245245
lint: default_methods,
246246
desc: "allow default methods",
247-
default: deny
247+
default: allow
248248
}),
249249

250250
("unused_unsafe",

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ impl cmt_ {
11851185
}
11861186
}
11871187

1188-
impl Repr for cmt {
1188+
impl Repr for cmt_ {
11891189
fn repr(&self, tcx: ty::ctxt) -> ~str {
11901190
fmt!("{%s id:%d m:%? ty:%s}",
11911191
self.cat.repr(tcx),

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
520520
let _icx = push_ctxt("trans_res_dtor");
521521
if !substs.is_empty() {
522522
let did = if did.crate != ast::local_crate {
523-
inline::maybe_instantiate_inline(ccx, did, true)
523+
inline::maybe_instantiate_inline(ccx, did)
524524
} else {
525525
did
526526
};

src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub fn trans_fn_ref_with_vtables(
250250
def_id: ast::def_id, // def id of fn
251251
ref_id: ast::node_id, // node id of use of fn; may be zero if N/A
252252
type_params: &[ty::t], // values for fn's ty params
253-
vtables: Option<typeck::vtable_res>)
253+
vtables: Option<typeck::vtable_res>) // vtables for the call
254254
-> FnData {
255255
//!
256256
//
@@ -361,8 +361,7 @@ pub fn trans_fn_ref_with_vtables(
361361
// def_id to the local id of the inlined copy.
362362
let def_id = {
363363
if def_id.crate != ast::local_crate {
364-
let may_translate = opt_impl_did.is_none();
365-
inline::maybe_instantiate_inline(ccx, def_id, may_translate)
364+
inline::maybe_instantiate_inline(ccx, def_id)
366365
} else {
367366
def_id
368367
}

src/librustc/middle/trans/common.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ impl Repr for param_substs {
154154
}
155155
}
156156

157-
impl Repr for @param_substs {
158-
fn repr(&self, tcx: ty::ctxt) -> ~str {
159-
param_substs_to_str(*self, tcx)
160-
}
161-
}
162-
163157
// Function context. Every LLVM function we create will have one of
164158
// these.
165159
pub struct fn_ctxt_ {

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn get_const_val(cx: @mut CrateContext, mut def_id: ast::def_id) -> ValueRef
159159
let contains_key = cx.const_values.contains_key(&def_id.node);
160160
if !ast_util::is_local(def_id) || !contains_key {
161161
if !ast_util::is_local(def_id) {
162-
def_id = inline::maybe_instantiate_inline(cx, def_id, true);
162+
def_id = inline::maybe_instantiate_inline(cx, def_id);
163163
}
164164
match cx.tcx.items.get_copy(&def_id.node) {
165165
ast_map::node_item(@ast::item {

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
956956
fn get_did(ccx: @mut CrateContext, did: ast::def_id)
957957
-> ast::def_id {
958958
if did.crate != ast::local_crate {
959-
inline::maybe_instantiate_inline(ccx, did, true)
959+
inline::maybe_instantiate_inline(ccx, did)
960960
} else {
961961
did
962962
}

src/librustc/middle/trans/inline.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ use syntax::ast;
2222
use syntax::ast_map::path_name;
2323
use syntax::ast_util::local_def;
2424

25-
// `translate` will be true if this function is allowed to translate the
26-
// item and false otherwise. Currently, this parameter is set to false when
27-
// translating default methods.
28-
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::def_id,
29-
translate: bool)
25+
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::def_id)
3026
-> ast::def_id {
3127
let _icx = push_ctxt("maybe_instantiate_inline");
3228
match ccx.external.find(&fn_id) {
@@ -59,7 +55,7 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::def_id,
5955
csearch::found(ast::ii_item(item)) => {
6056
ccx.external.insert(fn_id, Some(item.id));
6157
ccx.stats.n_inlines += 1;
62-
if translate { trans_item(ccx, item); }
58+
trans_item(ccx, item);
6359
local_def(item.id)
6460
}
6561
csearch::found(ast::ii_foreign(item)) => {
@@ -81,19 +77,19 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::def_id,
8177
_ => ccx.sess.bug("maybe_instantiate_inline: item has a \
8278
non-enum parent")
8379
}
84-
if translate { trans_item(ccx, item); }
80+
trans_item(ccx, item);
8581
local_def(my_id)
8682
}
8783
csearch::found_parent(_, _) => {
8884
ccx.sess.bug("maybe_get_item_ast returned a found_parent \
8985
with a non-item parent");
9086
}
91-
csearch::found(ast::ii_method(impl_did, mth)) => {
87+
csearch::found(ast::ii_method(impl_did, is_provided, mth)) => {
9288
ccx.stats.n_inlines += 1;
9389
ccx.external.insert(fn_id, Some(mth.id));
9490
// If this is a default method, we can't look up the
9591
// impl type. But we aren't going to translate anyways, so don't.
96-
if !translate { return local_def(mth.id); }
92+
if is_provided { return local_def(mth.id); }
9793

9894
let impl_tpt = ty::lookup_item_type(ccx.tcx, impl_did);
9995
let num_type_params =

0 commit comments

Comments
 (0)