Skip to content

Commit d9893b3

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36160 - Aatch:normalize-closure-sig, r=eddyb
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 rust-lang#36139 r? @eddyb
2 parents c77af26 + e0279d7 commit d9893b3

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
@@ -1878,11 +1878,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
18781878
hir::DefaultReturn(..) => self.tcx().mk_nil(),
18791879
};
18801880

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

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)