Skip to content

Commit 8b511a8

Browse files
committed
---
yaml --- r: 30387 b: refs/heads/incoming c: c6b5154 h: refs/heads/master i: 30385: b3c15e1 30383: 3b4198a v: v3
1 parent d8524f1 commit 8b511a8

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: cd3cc6d17b68ef18199a54372963b00ba8a0a84f
9+
refs/heads/incoming: c6b51547c14780a0473a5bcae90c8d4b0530b7c8
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/rustc/middle/ty.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export serialize_region_variance, deserialize_region_variance;
190190
export opt_region_variance;
191191
export serialize_opt_region_variance, deserialize_opt_region_variance;
192192
export determine_inherited_purity;
193+
export provided_trait_methods;
193194

194195
// Data types
195196

@@ -3069,6 +3070,24 @@ fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) {
30693070
cx.trait_method_cache.insert(ast_util::local_def(id), ms);
30703071
}
30713072

3073+
fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@ast::method] {
3074+
if is_local(id) {
3075+
match cx.items.find(id.node) {
3076+
Some(ast_map::node_item(@{node: item_trait(_, _, ms),_}, _)) =>
3077+
match ast_util::split_trait_methods(ms) {
3078+
(_, p) => p
3079+
},
3080+
_ => cx.sess.bug(#fmt("provided_trait_methods: %? is not a trait",
3081+
id))
3082+
}
3083+
}
3084+
else {
3085+
// FIXME #2794: default methods for traits don't work cross-crate
3086+
~[]
3087+
}
3088+
}
3089+
3090+
30723091
fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
30733092
match cx.trait_method_cache.find(id) {
30743093
// Local traits are supposed to have been added explicitly.

branches/incoming/src/rustc/middle/typeck/collect.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -343,33 +343,22 @@ fn check_methods_against_trait(ccx: @crate_ctxt,
343343
// implementation in the trait itself. If not, raise a
344344
// "missing method" error.
345345

346-
match tcx.items.get(did.node) {
347-
ast_map::node_item(
348-
@{node: ast::item_trait(_, _, trait_methods), _}, _) => {
349-
let (_, provided_methods) =
350-
split_trait_methods(trait_methods);
351-
352-
match vec::find(provided_methods, |provided_method|
353-
provided_method.ident == trait_m.ident) {
354-
Some(_) => {
355-
// If there's a provided method with the name we
356-
// want, then we're fine; nothing else to do.
357-
}
358-
None => {
359-
tcx.sess.span_err(
360-
a_trait_ty.path.span,
361-
fmt!("missing method `%s`",
362-
tcx.sess.str_of(trait_m.ident)));
363-
}
364-
}
346+
let provided_methods = ty::provided_trait_methods(tcx, did);
347+
match vec::find(provided_methods, |provided_method|
348+
provided_method.ident == trait_m.ident) {
349+
Some(_) => {
350+
// If there's a provided method with the name we
351+
// want, then we're fine; nothing else to do.
365352
}
366-
_ => {
367-
tcx.sess.bug(~"check_methods_against_trait(): trait_ref \
368-
didn't refer to a trait");
353+
None => {
354+
tcx.sess.span_err(
355+
a_trait_ty.path.span,
356+
fmt!("missing method `%s`",
357+
tcx.sess.str_of(trait_m.ident)));
369358
}
370359
}
371360
}
372-
} // alt
361+
} // match
373362
} // |trait_m|
374363
} // fn
375364

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum thing = uint;
2+
impl thing : cmp::Ord { //~ ERROR missing method `gt`
3+
pure fn lt(&&other: thing) -> bool { *self < *other }
4+
pure fn le(&&other: thing) -> bool { *self < *other }
5+
pure fn ge(&&other: thing) -> bool { *self < *other }
6+
}
7+
fn main() {}

0 commit comments

Comments
 (0)