Skip to content

Commit 79d4540

Browse files
committed
Fold MethodOrigins to resolve inference variables they may contain.
Fixes #17662.
1 parent 823f108 commit 79d4540

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

src/librustc/middle/ty_fold.rs

+27
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,33 @@ impl TypeFoldable for ty::AutoRef {
251251
}
252252
}
253253

254+
impl TypeFoldable for typeck::MethodOrigin {
255+
fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::MethodOrigin {
256+
match *self {
257+
typeck::MethodStatic(def_id) => {
258+
typeck::MethodStatic(def_id)
259+
}
260+
typeck::MethodStaticUnboxedClosure(def_id) => {
261+
typeck::MethodStaticUnboxedClosure(def_id)
262+
}
263+
typeck::MethodTypeParam(ref param) => {
264+
typeck::MethodTypeParam(typeck::MethodParam {
265+
trait_ref: param.trait_ref.fold_with(folder),
266+
method_num: param.method_num
267+
})
268+
}
269+
typeck::MethodTraitObject(ref object) => {
270+
typeck::MethodTraitObject(typeck::MethodObject {
271+
trait_ref: object.trait_ref.fold_with(folder),
272+
object_trait_id: object.object_trait_id,
273+
method_num: object.method_num,
274+
real_index: object.real_index
275+
})
276+
}
277+
}
278+
}
279+
}
280+
254281
impl TypeFoldable for typeck::vtable_origin {
255282
fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::vtable_origin {
256283
match *self {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
323323
method_call,
324324
method.repr(self.tcx()));
325325
let new_method = MethodCallee {
326-
origin: method.origin,
326+
origin: self.resolve(&method.origin, reason),
327327
ty: self.resolve(&method.ty, reason),
328328
substs: self.resolve(&method.substs, reason),
329329
};

src/test/auxiliary/issue-17662.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 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+
#![crate_type = "lib"]
12+
13+
pub trait Foo<'a, T> {
14+
fn foo(&self) -> T;
15+
}
16+
17+
pub fn foo<'a, T>(x: &'a Foo<'a, T>) -> T {
18+
let x: &'a Foo<T> = x;
19+
// ^ the lifetime parameter of Foo is left to be infered.
20+
x.foo()
21+
// ^ encoding this method call in metadata triggers an ICE.
22+
}

src/test/run-pass/issue-17662.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 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+
// aux-build:issue-17662.rs
12+
13+
extern crate "issue-17662" as i;
14+
15+
struct Bar<'a>;
16+
17+
impl<'a> i::Foo<'a, uint> for Bar<'a> {
18+
fn foo(&self) -> uint { 5u }
19+
}
20+
21+
pub fn main() {
22+
assert_eq!(i::foo(&Bar), 5);
23+
}

0 commit comments

Comments
 (0)