Skip to content

Commit e0279d7

Browse files
committed
Normalize the function signature of closures
Previously we didn't normalize the function signatures used for closures. This didn't cause a problem in most cases, but caused an ICE in during MIR type checking. Fixes #36139
1 parent eac4146 commit e0279d7

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/librustc_typeck/astconv.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1877,11 +1877,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
18771877
hir::DefaultReturn(..) => self.tcx().mk_nil(),
18781878
};
18791879

1880+
let input_tys = self_ty.into_iter().chain(arg_tys).collect();
1881+
1882+
debug!("ty_of_method_or_bare_fn: input_tys={:?}", input_tys);
1883+
debug!("ty_of_method_or_bare_fn: output_ty={:?}", output_ty);
1884+
18801885
(self.tcx().mk_bare_fn(ty::BareFnTy {
18811886
unsafety: unsafety,
18821887
abi: abi,
18831888
sig: ty::Binder(ty::FnSig {
1884-
inputs: self_ty.into_iter().chain(arg_tys).collect(),
1889+
inputs: input_tys,
18851890
output: output_ty,
18861891
variadic: decl.variadic
18871892
}),

src/librustc_typeck/check/closure.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
7474

7575
let fn_sig = self.tcx.liberate_late_bound_regions(
7676
self.tcx.region_maps.call_site_extent(expr.id, body.id), &fn_ty.sig);
77+
let fn_sig =
78+
(**self).normalize_associated_types_in(body.span, body.id, &fn_sig);
7779

7880
check_fn(self, hir::Unsafety::Normal, expr.id, &fn_sig, decl, expr.id, &body);
7981

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2016 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+
// Previously the closure's argument would be inferred to
12+
// <S as ITrait<'a>>::Item, causing an error in MIR type
13+
// checking
14+
15+
trait ITrait<'a> {type Item;}
16+
17+
struct S {}
18+
19+
impl<'a> ITrait<'a> for S { type Item = &'a mut usize; }
20+
21+
fn m<T, I, F>(_: F)
22+
where I: for<'a> ITrait<'a>,
23+
F: for<'a> FnMut(<I as ITrait<'a>>::Item) { }
24+
25+
26+
fn main() {
27+
m::<usize,S,_>(|x| { *x += 1; });
28+
}

0 commit comments

Comments
 (0)