Skip to content

Commit 276463f

Browse files
committed
Fix another generics bug with default methods. Closes #7295.
1 parent c6515ee commit 276463f

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,8 @@ impl<'self> LookupContext<'self> {
300300
ty_self(self_did) => {
301301
// Call is of the form "self.foo()" and appears in one
302302
// of a trait's default method implementations.
303-
let substs = substs {
304-
self_r: None,
305-
self_ty: None,
306-
tps: ~[]
307-
};
308303
self.push_inherent_candidates_from_self(
309-
self_ty, self_did, &substs);
304+
self_ty, self_did);
310305
}
311306
ty_enum(did, _) | ty_struct(did, _) => {
312307
if self.check_traits == CheckTraitsAndInherentMethods {
@@ -462,12 +457,12 @@ impl<'self> LookupContext<'self> {
462457

463458
pub fn push_inherent_candidates_from_self(&self,
464459
self_ty: ty::t,
465-
did: def_id,
466-
substs: &ty::substs) {
460+
did: def_id) {
467461
struct MethodInfo {
468462
method_ty: @ty::Method,
469463
trait_def_id: ast::def_id,
470-
index: uint
464+
index: uint,
465+
trait_ref: @ty::TraitRef
471466
}
472467

473468
let tcx = self.tcx();
@@ -479,7 +474,8 @@ impl<'self> LookupContext<'self> {
479474
method_info = Some(MethodInfo {
480475
method_ty: methods[i],
481476
index: i,
482-
trait_def_id: did
477+
trait_def_id: did,
478+
trait_ref: ty::lookup_trait_def(tcx, did).trait_ref
483479
});
484480
}
485481
None => ()
@@ -494,7 +490,8 @@ impl<'self> LookupContext<'self> {
494490
method_info = Some(MethodInfo {
495491
method_ty: supertrait_methods[i],
496492
index: i,
497-
trait_def_id: trait_ref.def_id
493+
trait_def_id: trait_ref.def_id,
494+
trait_ref: *trait_ref
498495
});
499496
break;
500497
}
@@ -505,16 +502,14 @@ impl<'self> LookupContext<'self> {
505502
match method_info {
506503
Some(ref info) => {
507504
// We've found a method -- return it
508-
let rcvr_substs = substs {self_ty: Some(self_ty),
509-
..copy *substs };
510505
let origin = if did == info.trait_def_id {
511506
method_self(info.trait_def_id, info.index)
512507
} else {
513508
method_super(info.trait_def_id, info.index)
514509
};
515510
self.inherent_candidates.push(Candidate {
516511
rcvr_ty: self_ty,
517-
rcvr_substs: rcvr_substs,
512+
rcvr_substs: copy info.trait_ref.substs,
518513
method_ty: info.method_ty,
519514
origin: origin
520515
});

src/test/run-pass/bug-7295.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#[allow(default_methods)];
12+
pub trait Foo<T> {
13+
pub fn func1<U>(&self, t: U);
14+
15+
pub fn func2<U>(&self, t: U) {
16+
self.func1(t);
17+
}
18+
}
19+
20+
pub fn main() {
21+
22+
}

0 commit comments

Comments
 (0)