diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 944d04ee402..41ddedcb526 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -2738,6 +2738,25 @@ impl methods for lookup { self.tcx().sess.span_err( self.expr.span, "multiple applicable methods in scope"); + + // I would like to print out how each impl was imported, + // but I cannot for the life of me figure out how to + // annotate resolve to preserve this information. + for results.eachi { |i, result| + let (_, _, did) = result; + let span = if did.crate == ast::local_crate { + alt check self.tcx().items.get(did.node) { + ast_map::node_method(m, _, _) { m.span } + } + } else { + self.expr.span + }; + self.tcx().sess.span_note( + span, + #fmt["candidate #%u is %s", + (i+1u), + ty::item_path_str(self.tcx(), did)]); + } } let (self_substs, n_tps, did) = results[0]; diff --git a/src/test/auxiliary/ambig_impl_2_lib.rs b/src/test/auxiliary/ambig_impl_2_lib.rs new file mode 100644 index 00000000000..2ea30d4e078 --- /dev/null +++ b/src/test/auxiliary/ambig_impl_2_lib.rs @@ -0,0 +1 @@ +impl methods1 for uint { fn me() -> uint { self } } diff --git a/src/test/compile-fail/ambig_impl_1.rs b/src/test/compile-fail/ambig_impl_1.rs new file mode 100644 index 00000000000..434cdf31002 --- /dev/null +++ b/src/test/compile-fail/ambig_impl_1.rs @@ -0,0 +1,3 @@ +impl methods1 for uint { fn me() -> uint { self } } //! NOTE candidate #1 is methods1::me +impl methods2 for uint { fn me() -> uint { self } } //! NOTE candidate #2 is methods2::me +fn main() { 1u.me(); } //! ERROR multiple applicable methods in scope diff --git a/src/test/compile-fail/ambig_impl_2_exe.rs b/src/test/compile-fail/ambig_impl_2_exe.rs new file mode 100644 index 00000000000..49c1fdc2f1d --- /dev/null +++ b/src/test/compile-fail/ambig_impl_2_exe.rs @@ -0,0 +1,7 @@ +// xfail-fast aux-build +// aux-build:ambig_impl_2_lib.rs +use ambig_impl_2_lib; +import ambig_impl_2_lib::methods1; +impl methods2 for uint { fn me() -> uint { self } } //! NOTE candidate #2 is methods2::me +fn main() { 1u.me(); } //! ERROR multiple applicable methods in scope +//!^ NOTE candidate #1 is ambig_impl_2_lib::methods1::me