Skip to content

Commit 5e26808

Browse files
committed
Get rid of terrible way for iterating over provided methods.
1 parent d161e63 commit 5e26808

File tree

4 files changed

+14
-46
lines changed

4 files changed

+14
-46
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ use syntax::ast;
2424
use syntax::ast_map;
2525
use syntax::diagnostic::expect;
2626

27-
pub struct ProvidedTraitMethodInfo {
28-
ty: ty::Method,
29-
def_id: ast::def_id
30-
}
31-
3227
pub struct StaticMethodInfo {
3328
ident: ast::ident,
3429
def_id: ast::def_id,
@@ -134,7 +129,7 @@ pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,
134129

135130
pub fn get_provided_trait_methods(tcx: ty::ctxt,
136131
def: ast::def_id)
137-
-> ~[ProvidedTraitMethodInfo] {
132+
-> ~[@ty::Method] {
138133
let cstore = tcx.cstore;
139134
let cdata = cstore::get_crate_data(cstore, def.crate);
140135
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)

src/librustc/metadata/decoder.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::prelude::*;
1414

1515
use metadata::cstore::crate_metadata;
1616
use metadata::common::*;
17-
use metadata::csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
17+
use metadata::csearch::StaticMethodInfo;
1818
use metadata::csearch;
1919
use metadata::cstore;
2020
use metadata::decoder;
@@ -752,7 +752,7 @@ pub fn get_trait_method_def_ids(cdata: cmd,
752752

753753
pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
754754
id: ast::node_id, tcx: ty::ctxt) ->
755-
~[ProvidedTraitMethodInfo] {
755+
~[@ty::Method] {
756756
let data = cdata.data;
757757
let item = lookup_item(id, data);
758758
let mut result = ~[];
@@ -763,13 +763,8 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
763763

764764
if item_method_sort(mth) != 'p' { loop; }
765765

766-
let ty_method = get_method(intr, cdata, did.node, tcx);
767-
let provided_trait_method_info = ProvidedTraitMethodInfo {
768-
ty: ty_method,
769-
def_id: did
770-
};
771-
772-
vec::push(&mut result, provided_trait_method_info);
766+
vec::push(&mut result,
767+
@get_method(intr, cdata, did.node, tcx));
773768
}
774769

775770
return result;

src/librustc/middle/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,21 +3649,21 @@ pub fn def_has_ty_params(def: ast::def) -> bool {
36493649
}
36503650
}
36513651

3652-
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
3652+
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@Method] {
36533653
if is_local(id) {
36543654
match cx.items.find(&id.node) {
36553655
Some(&ast_map::node_item(@ast::item {
36563656
node: item_trait(_, _, ref ms),
36573657
_
36583658
}, _)) =>
36593659
match ast_util::split_trait_methods(*ms) {
3660-
(_, p) => p.map(|method| method.ident)
3660+
(_, p) => p.map(|m| method(cx, ast_util::local_def(m.id)))
36613661
},
36623662
_ => cx.sess.bug(fmt!("provided_trait_methods: %? is not a trait",
36633663
id))
36643664
}
36653665
} else {
3666-
csearch::get_provided_trait_methods(cx, id).map(|ifo| ifo.ty.ident)
3666+
csearch::get_provided_trait_methods(cx, id)
36673667
}
36683668
}
36693669

src/librustc/middle/typeck/coherence.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ impl CoherenceChecker {
333333

334334
let impl_poly_type = ty::lookup_item_type(tcx, impl_id);
335335

336-
for self.each_provided_trait_method(trait_ref.def_id) |trait_method| {
336+
let provided = ty::provided_trait_methods(tcx, trait_ref.def_id);
337+
for provided.iter().advance |trait_method| {
337338
// Synthesize an ID.
338339
let new_id = parse::next_node_id(tcx.sess.parse_sess);
339340
let new_did = local_def(new_id);
@@ -347,7 +348,7 @@ impl CoherenceChecker {
347348
impl_id,
348349
trait_ref,
349350
new_did,
350-
trait_method);
351+
*trait_method);
351352

352353
debug!("new_method_ty=%s", new_method_ty.repr(tcx));
353354

@@ -526,29 +527,6 @@ impl CoherenceChecker {
526527
}
527528
}
528529

529-
pub fn each_provided_trait_method(&self,
530-
trait_did: ast::def_id,
531-
f: &fn(x: @ty::Method) -> bool)
532-
-> bool {
533-
// Make a list of all the names of the provided methods.
534-
// XXX: This is horrible.
535-
let mut provided_method_idents = HashSet::new();
536-
let tcx = self.crate_context.tcx;
537-
let r = ty::provided_trait_methods(tcx, trait_did);
538-
for r.iter().advance |ident| {
539-
provided_method_idents.insert(*ident);
540-
}
541-
542-
for ty::trait_methods(tcx, trait_did).iter().advance |&method| {
543-
if provided_method_idents.contains(&method.ident) {
544-
if !f(method) {
545-
return false;
546-
}
547-
}
548-
}
549-
return true;
550-
}
551-
552530
pub fn polytypes_unify(&self,
553531
polytype_a: ty_param_bounds_and_ty,
554532
polytype_b: ty_param_bounds_and_ty)
@@ -729,9 +707,9 @@ impl CoherenceChecker {
729707
}
730708
// Default methods
731709
let r = ty::provided_trait_methods(tcx, trait_did);
732-
for r.iter().advance |ident| {
733-
debug!("inserting provided method %s", ident.repr(tcx));
734-
provided_names.insert(*ident);
710+
for r.iter().advance |method| {
711+
debug!("inserting provided method %s", method.ident.repr(tcx));
712+
provided_names.insert(method.ident);
735713
}
736714

737715
let r = ty::trait_methods(tcx, trait_did);

0 commit comments

Comments
 (0)