Skip to content

Commit

Permalink
resolve type vars with obligations in more places
Browse files Browse the repository at this point in the history
This fixes a few cases of inference misses, some of them regressions
caused by the impl selected for a method not being immediately evaluated.
  • Loading branch information
arielb1 committed Aug 29, 2017
1 parent de0e695 commit 15f6540
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
formal_ret: Ty<'tcx>,
formal_args: &[Ty<'tcx>])
-> Vec<Ty<'tcx>> {
let formal_ret = self.resolve_type_vars_with_obligations(formal_ret);
let expected_args = expected_ret.only_has_type(self).and_then(|ret_ty| {
self.fudge_regions_if_ok(&RegionVariableOrigin::Coercion(call_span), || {
// Attempt to apply a subtyping relationship between the formal
Expand Down Expand Up @@ -3978,6 +3979,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
hir::ExprTup(ref elts) => {
let flds = expected.only_has_type(self).and_then(|ty| {
let ty = self.resolve_type_vars_with_obligations(ty);
match ty.sty {
ty::TyTuple(ref flds, _) => Some(&flds[..]),
_ => None
Expand Down
37 changes: 37 additions & 0 deletions src/test/run-pass/method-argument-inference-associated-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2017 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.

pub struct ClientMap;
pub struct ClientMap2;

pub trait Service {
type Request;
fn call(&self, _req: Self::Request);
}

pub struct S<T>(T);

impl Service for ClientMap {
type Request = S<Box<Fn(i32)>>;
fn call(&self, _req: Self::Request) {}
}


impl Service for ClientMap2 {
type Request = (Box<Fn(i32)>,);
fn call(&self, _req: Self::Request) {}
}


fn main() {
ClientMap.call(S { 0: Box::new(|_msgid| ()) });
ClientMap.call(S(Box::new(|_msgid| ())));
ClientMap2.call((Box::new(|_msgid| ()),));
}

0 comments on commit 15f6540

Please sign in to comment.