Skip to content

Commit

Permalink
Fold MethodOrigins to resolve inference variables they may contain.
Browse files Browse the repository at this point in the history
Fixes #17662.
  • Loading branch information
eddyb committed Sep 30, 2014
1 parent 823f108 commit 79d4540
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/librustc/middle/ty_fold.rs
Expand Up @@ -251,6 +251,33 @@ impl TypeFoldable for ty::AutoRef {
}
}

impl TypeFoldable for typeck::MethodOrigin {
fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::MethodOrigin {
match *self {
typeck::MethodStatic(def_id) => {
typeck::MethodStatic(def_id)
}
typeck::MethodStaticUnboxedClosure(def_id) => {
typeck::MethodStaticUnboxedClosure(def_id)
}
typeck::MethodTypeParam(ref param) => {
typeck::MethodTypeParam(typeck::MethodParam {
trait_ref: param.trait_ref.fold_with(folder),
method_num: param.method_num
})
}
typeck::MethodTraitObject(ref object) => {
typeck::MethodTraitObject(typeck::MethodObject {
trait_ref: object.trait_ref.fold_with(folder),
object_trait_id: object.object_trait_id,
method_num: object.method_num,
real_index: object.real_index
})
}
}
}
}

impl TypeFoldable for typeck::vtable_origin {
fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::vtable_origin {
match *self {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/writeback.rs
Expand Up @@ -323,7 +323,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
method_call,
method.repr(self.tcx()));
let new_method = MethodCallee {
origin: method.origin,
origin: self.resolve(&method.origin, reason),
ty: self.resolve(&method.ty, reason),
substs: self.resolve(&method.substs, reason),
};
Expand Down
22 changes: 22 additions & 0 deletions src/test/auxiliary/issue-17662.rs
@@ -0,0 +1,22 @@
// Copyright 2014 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.

#![crate_type = "lib"]

pub trait Foo<'a, T> {
fn foo(&self) -> T;
}

pub fn foo<'a, T>(x: &'a Foo<'a, T>) -> T {
let x: &'a Foo<T> = x;
// ^ the lifetime parameter of Foo is left to be infered.
x.foo()
// ^ encoding this method call in metadata triggers an ICE.
}
23 changes: 23 additions & 0 deletions src/test/run-pass/issue-17662.rs
@@ -0,0 +1,23 @@
// Copyright 2014 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.

// aux-build:issue-17662.rs

extern crate "issue-17662" as i;

struct Bar<'a>;

impl<'a> i::Foo<'a, uint> for Bar<'a> {
fn foo(&self) -> uint { 5u }
}

pub fn main() {
assert_eq!(i::foo(&Bar), 5);
}

14 comments on commit 79d4540

@nikomatsakis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@79d4540

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/method-origin-subst = 79d4540 into auto

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/method-origin-subst = 79d4540 merged ok, testing candidate = 7f1dbe81

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@79d4540

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/method-origin-subst = 79d4540 into auto

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/method-origin-subst = 79d4540 merged ok, testing candidate = ee55a446

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@79d4540

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/method-origin-subst = 79d4540 into auto

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/method-origin-subst = 79d4540 merged ok, testing candidate = b419e9e

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 79d4540 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b419e9e

Please sign in to comment.