Skip to content

Commit 3f32898

Browse files
committedOct 4, 2013
auto merge of #9711 : sanxiyn/rust/ambiguous-default-method, r=alexcrichton
Fix #8808.
2 parents 4bae639 + fbd5639 commit 3f32898

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

‎src/librustc/middle/typeck/check/method.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,13 @@ impl<'self> LookupContext<'self> {
12881288
fn report_candidate(&self, idx: uint, origin: &method_origin) {
12891289
match *origin {
12901290
method_static(impl_did) => {
1291-
self.report_static_candidate(idx, impl_did)
1291+
// If it is an instantiated default method, use the original
1292+
// default method for error reporting.
1293+
let did = match provided_source(self.tcx(), impl_did) {
1294+
None => impl_did,
1295+
Some(did) => did
1296+
};
1297+
self.report_static_candidate(idx, did)
12921298
}
12931299
method_param(ref mp) => {
12941300
self.report_param_candidate(idx, (*mp).trait_id)
@@ -1302,7 +1308,8 @@ impl<'self> LookupContext<'self> {
13021308
fn report_static_candidate(&self, idx: uint, did: DefId) {
13031309
let span = if did.crate == ast::LOCAL_CRATE {
13041310
match self.tcx().items.find(&did.node) {
1305-
Some(&ast_map::node_method(m, _, _)) => m.span,
1311+
Some(&ast_map::node_method(m, _, _))
1312+
| Some(&ast_map::node_trait_method(@ast::provided(m), _, _)) => m.span,
13061313
_ => fail2!("report_static_candidate: bad item {:?}", did)
13071314
}
13081315
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo { fn method(&self) {} } //~ NOTE `Foo::method`
12+
trait Bar { fn method(&self) {} } //~ NOTE `Bar::method`
13+
14+
impl Foo for uint {}
15+
impl Bar for uint {}
16+
17+
fn main() {
18+
1u.method(); //~ ERROR multiple applicable methods in scope
19+
}

0 commit comments

Comments
 (0)
Please sign in to comment.