Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

In ty::impl_traits, treat structs properly

Treat structs just like impls: use their associated list of
trait refs to get the list of traits that one of them implements.
I don't understand what was happening before, but it was wrong.

Closes #2936
  • Loading branch information...
commit a70e37b214407743ba9ac7e688e13d7a9d644ad5 1 parent a19dce6
@catamorphism catamorphism authored
Showing with 24 additions and 15 deletions.
  1. +4 −15 src/rustc/middle/ty.rs
  2. +20 −0 src/test/run-pass/issue-2936.rs
View
19 src/rustc/middle/ty.rs
@@ -2826,22 +2826,11 @@ fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] {
node_id_to_type(cx, trait_ref.ref_id)
}
}
- Some(ast_map::node_item(@{node: ast::item_class(*),
+ Some(ast_map::node_item(@{node: ast::item_class(sd,_),
_},_)) => {
- match cx.def_map.find(id.node) {
- Some(def_ty(trait_id)) => {
- // XXX: Doesn't work cross-crate.
- debug!("(impl_traits) found trait id %?", trait_id);
- ~[node_id_to_type(cx, trait_id.node)]
- }
- Some(x) => {
- cx.sess.bug(fmt!("impl_traits: trait ref is in trait map \
- but is bound to %?", x));
- }
- None => {
- ~[]
- }
- }
+ do vec::map(sd.traits) |trait_ref| {
+ node_id_to_type(cx, trait_ref.ref_id)
+ }
}
_ => ~[]
}
View
20 src/test/run-pass/issue-2936.rs
@@ -0,0 +1,20 @@
+trait bar<T> {
+ fn get_bar() -> T;
+}
+
+fn foo<T, U: bar<T>>(b: U) -> T {
+ b.get_bar()
+}
+
+struct cbar : bar<int> {
+ x: int;
+ new(x: int) { self.x = x; }
+ fn get_bar() -> int {
+ self.x
+ }
+}
+
+fn main() {
+ let x: int = foo::<int, cbar>(cbar(5));
+ assert x == 5;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.