about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-03 20:21:31 -0700
committerbors <bors@rust-lang.org>2013-10-03 20:21:31 -0700
commit3f32898a7b78888b73c59db6def2dfea8a7b1931 (patch)
treeceda3b8606350110ec725c3edea4e38489534acf /src
parent4bae639d86bd4c63040874dd5c305983832162c0 (diff)
parentfbd56396bc35aa65cf0a449d5073086aad2e61b9 (diff)
downloadrust-3f32898a7b78888b73c59db6def2dfea8a7b1931.tar.gz
rust-3f32898a7b78888b73c59db6def2dfea8a7b1931.zip
auto merge of #9711 : sanxiyn/rust/ambiguous-default-method, r=alexcrichton
Fix #8808.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/typeck/check/method.rs11
-rw-r--r--src/test/compile-fail/ambig-default-method.rs19
2 files changed, 28 insertions, 2 deletions
diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs
index 8bfef838c9c..e0df9bf1cfc 100644
--- a/src/librustc/middle/typeck/check/method.rs
+++ b/src/librustc/middle/typeck/check/method.rs
@@ -1288,7 +1288,13 @@ impl<'self> LookupContext<'self> {
     fn report_candidate(&self, idx: uint, origin: &method_origin) {
         match *origin {
             method_static(impl_did) => {
-                self.report_static_candidate(idx, impl_did)
+                // If it is an instantiated default method, use the original
+                // default method for error reporting.
+                let did = match provided_source(self.tcx(), impl_did) {
+                    None => impl_did,
+                    Some(did) => did
+                };
+                self.report_static_candidate(idx, did)
             }
             method_param(ref mp) => {
                 self.report_param_candidate(idx, (*mp).trait_id)
@@ -1302,7 +1308,8 @@ impl<'self> LookupContext<'self> {
     fn report_static_candidate(&self, idx: uint, did: DefId) {
         let span = if did.crate == ast::LOCAL_CRATE {
             match self.tcx().items.find(&did.node) {
-              Some(&ast_map::node_method(m, _, _)) => m.span,
+              Some(&ast_map::node_method(m, _, _))
+              | Some(&ast_map::node_trait_method(@ast::provided(m), _, _)) => m.span,
               _ => fail2!("report_static_candidate: bad item {:?}", did)
             }
         } else {
diff --git a/src/test/compile-fail/ambig-default-method.rs b/src/test/compile-fail/ambig-default-method.rs
new file mode 100644
index 00000000000..56ab6d7da3f
--- /dev/null
+++ b/src/test/compile-fail/ambig-default-method.rs
@@ -0,0 +1,19 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo { fn method(&self) {} } //~ NOTE `Foo::method`
+trait Bar { fn method(&self) {} } //~ NOTE `Bar::method`
+
+impl Foo for uint {}
+impl Bar for uint {}
+
+fn main() {
+    1u.method(); //~ ERROR multiple applicable methods in scope
+}