Skip to content

Commit f112963

Browse files
committed
report ambig impl methods
1 parent f4cc5ff commit f112963

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/rustc/middle/typeck.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,6 +2738,25 @@ impl methods for lookup {
27382738
self.tcx().sess.span_err(
27392739
self.expr.span,
27402740
"multiple applicable methods in scope");
2741+
2742+
// I would like to print out how each impl was imported,
2743+
// but I cannot for the life of me figure out how to
2744+
// annotate resolve to preserve this information.
2745+
for results.eachi { |i, result|
2746+
let (_, _, did) = result;
2747+
let span = if did.crate == ast::local_crate {
2748+
alt check self.tcx().items.get(did.node) {
2749+
ast_map::node_method(m, _, _) { m.span }
2750+
}
2751+
} else {
2752+
self.expr.span
2753+
};
2754+
self.tcx().sess.span_note(
2755+
span,
2756+
#fmt["candidate #%u is %s",
2757+
(i+1u),
2758+
ty::item_path_str(self.tcx(), did)]);
2759+
}
27412760
}
27422761

27432762
let (self_substs, n_tps, did) = results[0];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
impl methods1 for uint { fn me() -> uint { self } }

src/test/compile-fail/ambig_impl_1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
impl methods1 for uint { fn me() -> uint { self } } //! NOTE candidate #1 is methods1::me
2+
impl methods2 for uint { fn me() -> uint { self } } //! NOTE candidate #2 is methods2::me
3+
fn main() { 1u.me(); } //! ERROR multiple applicable methods in scope
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// xfail-fast aux-build
2+
// aux-build:ambig_impl_2_lib.rs
3+
use ambig_impl_2_lib;
4+
import ambig_impl_2_lib::methods1;
5+
impl methods2 for uint { fn me() -> uint { self } } //! NOTE candidate #2 is methods2::me
6+
fn main() { 1u.me(); } //! ERROR multiple applicable methods in scope
7+
//!^ NOTE candidate #1 is ambig_impl_2_lib::methods1::me

0 commit comments

Comments
 (0)