mirror of
https://github.com/rust-lang/rust
synced 2024-11-02 11:53:40 +00:00
collector: apply param substs to closures cast to fn items
Fixes #42718.
This commit is contained in:
parent
ff9f2d2ae9
commit
09219d6a49
2 changed files with 11 additions and 0 deletions
|
@ -493,6 +493,8 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {
|
|||
}
|
||||
mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => {
|
||||
let source_ty = operand.ty(self.mir, self.scx.tcx());
|
||||
let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs,
|
||||
&source_ty);
|
||||
match source_ty.sty {
|
||||
ty::TyClosure(def_id, substs) => {
|
||||
let instance = monomorphize::resolve_closure(
|
||||
|
@ -543,6 +545,8 @@ fn visit_terminator_kind(&mut self,
|
|||
block: mir::BasicBlock,
|
||||
kind: &mir::TerminatorKind<'tcx>,
|
||||
location: Location) {
|
||||
debug!("visiting terminator {:?} @ {:?}", kind, location);
|
||||
|
||||
let tcx = self.scx.tcx();
|
||||
match *kind {
|
||||
mir::TerminatorKind::Call { ref func, .. } => {
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::mem;
|
||||
|
||||
const FOO: fn(u8) -> u8 = |v: u8| { v };
|
||||
|
||||
const BAR: [fn(&mut u32); 5] = [
|
||||
|
@ -21,6 +23,10 @@ fn func_specific() -> (fn() -> u32) {
|
|||
|| return 42
|
||||
}
|
||||
|
||||
fn generic<T>(_: T) -> fn() -> usize {
|
||||
|| mem::size_of::<T>()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Items
|
||||
assert_eq!(func_specific()(), 42);
|
||||
|
@ -34,4 +40,5 @@ fn main() {
|
|||
assert_eq!({ BAR[2](&mut a); a }, 3);
|
||||
assert_eq!({ BAR[3](&mut a); a }, 6);
|
||||
assert_eq!({ BAR[4](&mut a); a }, 10);
|
||||
assert_eq!(generic(0i8)(), 1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue