Skip to content

Commit 1bf0649

Browse files
committed
auto merge of #18893 : bkoropoff/rust/issue-18883, r=alexcrichton
This was a simple case of substitutions being applied inconsistently. I haven't investigated why type parameters are actually showing up in the closure type here, but trans needs to handle them correctly in any case.
2 parents 4963afd + 0135858 commit 1bf0649

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/librustc/middle/trans/callee.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ pub fn trans_unboxing_shim(bcx: Block,
253253
llshimmedfn: ValueRef,
254254
fty: &ty::BareFnTy,
255255
method_id: ast::DefId,
256-
substs: subst::Substs)
256+
substs: &subst::Substs)
257257
-> ValueRef {
258258
let _icx = push_ctxt("trans_unboxing_shim");
259259
let ccx = bcx.ccx();
260260
let tcx = bcx.tcx();
261261

262+
let fty = fty.subst(tcx, substs);
263+
262264
// Transform the self type to `Box<self_type>`.
263265
let self_type = fty.sig.inputs[0];
264266
let boxed_self_type = ty::mk_uniq(tcx, self_type);
@@ -279,8 +281,7 @@ pub fn trans_unboxing_shim(bcx: Block,
279281
abi: fty.abi,
280282
sig: boxed_function_type,
281283
};
282-
let boxed_function_type =
283-
ty::mk_bare_fn(tcx, boxed_function_type).subst(tcx, &substs);
284+
let boxed_function_type = ty::mk_bare_fn(tcx, boxed_function_type);
284285
let function_type = match fty.abi {
285286
synabi::RustCall => {
286287
// We're passing through to a RustCall ABI function, but
@@ -301,10 +302,10 @@ pub fn trans_unboxing_shim(bcx: Block,
301302
abi: synabi::Rust,
302303
sig: fake_ty,
303304
};
304-
ty::mk_bare_fn(tcx, fake_ty).subst(tcx, &substs)
305+
ty::mk_bare_fn(tcx, fake_ty)
305306
}
306307
_ => {
307-
ty::mk_bare_fn(tcx, (*fty).clone()).subst(tcx, &substs)
308+
ty::mk_bare_fn(tcx, fty)
308309
}
309310
};
310311

src/librustc/middle/trans/meth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ pub fn get_vtable(bcx: Block,
624624
llfn,
625625
&closure_type,
626626
closure_def_id,
627-
substs);
627+
&substs);
628628
}
629629
}
630630

@@ -723,7 +723,7 @@ fn emit_vtable_methods(bcx: Block,
723723
fn_ref,
724724
&m.fty,
725725
m_id,
726-
substs.clone());
726+
&substs);
727727
}
728728
Some(fn_ref).into_iter()
729729
}

src/test/run-pass/issue-18883.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 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+
// Test that we don't ICE due to encountering unsubstituted type
12+
// parameters when untupling FnOnce parameters during translation of
13+
// an unboxing shim.
14+
15+
#![feature(unboxed_closures)]
16+
17+
fn main() {
18+
let _: Box<FnOnce<(),()>> = box move |&mut:| {};
19+
}

0 commit comments

Comments
 (0)