Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 15f6540

Browse files
committedAug 29, 2017
resolve type vars with obligations in more places
This fixes a few cases of inference misses, some of them regressions caused by the impl selected for a method not being immediately evaluated.
1 parent de0e695 commit 15f6540

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
 

‎src/librustc_typeck/check/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28182818
formal_ret: Ty<'tcx>,
28192819
formal_args: &[Ty<'tcx>])
28202820
-> Vec<Ty<'tcx>> {
2821+
let formal_ret = self.resolve_type_vars_with_obligations(formal_ret);
28212822
let expected_args = expected_ret.only_has_type(self).and_then(|ret_ty| {
28222823
self.fudge_regions_if_ok(&RegionVariableOrigin::Coercion(call_span), || {
28232824
// Attempt to apply a subtyping relationship between the formal
@@ -3978,6 +3979,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39783979
}
39793980
hir::ExprTup(ref elts) => {
39803981
let flds = expected.only_has_type(self).and_then(|ty| {
3982+
let ty = self.resolve_type_vars_with_obligations(ty);
39813983
match ty.sty {
39823984
ty::TyTuple(ref flds, _) => Some(&flds[..]),
39833985
_ => None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2017 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+
pub struct ClientMap;
12+
pub struct ClientMap2;
13+
14+
pub trait Service {
15+
type Request;
16+
fn call(&self, _req: Self::Request);
17+
}
18+
19+
pub struct S<T>(T);
20+
21+
impl Service for ClientMap {
22+
type Request = S<Box<Fn(i32)>>;
23+
fn call(&self, _req: Self::Request) {}
24+
}
25+
26+
27+
impl Service for ClientMap2 {
28+
type Request = (Box<Fn(i32)>,);
29+
fn call(&self, _req: Self::Request) {}
30+
}
31+
32+
33+
fn main() {
34+
ClientMap.call(S { 0: Box::new(|_msgid| ()) });
35+
ClientMap.call(S(Box::new(|_msgid| ())));
36+
ClientMap2.call((Box::new(|_msgid| ()),));
37+
}

0 commit comments

Comments
 (0)