Skip to content

Commit f700ee4

Browse files
Do not normalize closure signature when building FnOnce shim
1 parent 3066253 commit f700ee4

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ fn codegen_stmt<'tcx>(
682682
args,
683683
ty::ClosureKind::FnOnce,
684684
)
685-
.expect("failed to normalize and resolve closure during codegen")
686685
.polymorphize(fx.tcx);
687686
let func_ref = fx.get_function_ref(instance);
688687
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);

Diff for: compiler/rustc_codegen_ssa/src/mir/rvalue.rs

-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
435435
args,
436436
ty::ClosureKind::FnOnce,
437437
)
438-
.expect("failed to normalize and resolve closure during codegen")
439438
.polymorphize(bx.cx().tcx());
440439
OperandValue::Immediate(bx.cx().get_fn_addr(instance))
441440
}

Diff for: compiler/rustc_const_eval/src/interpret/cast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
117117
def_id,
118118
args,
119119
ty::ClosureKind::FnOnce,
120-
)
121-
.ok_or_else(|| err_inval!(TooGeneric))?;
120+
);
122121
let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
123122
self.write_pointer(fn_ptr, dest)?;
124123
}

Diff for: compiler/rustc_middle/src/ty/instance.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ impl<'tcx> Instance<'tcx> {
528528
def_id: DefId,
529529
args: ty::GenericArgsRef<'tcx>,
530530
requested_kind: ty::ClosureKind,
531-
) -> Option<Instance<'tcx>> {
531+
) -> Instance<'tcx> {
532532
let actual_kind = args.as_closure().kind();
533533

534534
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
535535
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
536-
_ => Some(Instance::new(def_id, args)),
536+
_ => Instance::new(def_id, args),
537537
}
538538
}
539539

@@ -548,7 +548,7 @@ impl<'tcx> Instance<'tcx> {
548548
tcx: TyCtxt<'tcx>,
549549
closure_did: DefId,
550550
args: ty::GenericArgsRef<'tcx>,
551-
) -> Option<Instance<'tcx>> {
551+
) -> Instance<'tcx> {
552552
let fn_once = tcx.require_lang_item(LangItem::FnOnce, None);
553553
let call_once = tcx
554554
.associated_items(fn_once)
@@ -562,14 +562,12 @@ impl<'tcx> Instance<'tcx> {
562562

563563
let self_ty = Ty::new_closure(tcx, closure_did, args);
564564

565-
let sig = args.as_closure().sig();
566-
let sig =
567-
tcx.try_normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig).ok()?;
568-
assert_eq!(sig.inputs().len(), 1);
569-
let args = tcx.mk_args_trait(self_ty, [sig.inputs()[0].into()]);
565+
let tupled_inputs_ty = args.as_closure().sig().map_bound(|sig| sig.inputs()[0]);
566+
let tupled_inputs_ty = tcx.instantiate_bound_regions_with_erased(tupled_inputs_ty);
567+
let args = tcx.mk_args_trait(self_ty, [tupled_inputs_ty.into()]);
570568

571-
debug!(?self_ty, ?sig);
572-
Some(Instance { def, args })
569+
debug!(?self_ty, args=?tupled_inputs_ty.tuple_fields());
570+
Instance { def, args }
573571
}
574572

575573
/// Depending on the kind of `InstanceDef`, the MIR body associated with an

Diff for: compiler/rustc_monomorphize/src/collector.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
783783
def_id,
784784
args,
785785
ty::ClosureKind::FnOnce,
786-
)
787-
.expect("failed to normalize and resolve closure during codegen");
786+
);
788787
if should_codegen_locally(self.tcx, &instance) {
789788
self.output.push(create_fn_mono_item(self.tcx, instance, span));
790789
}

Diff for: compiler/rustc_smir/src/rustc_smir/context.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
464464
let def_id = def.0.internal(&mut *tables, tcx);
465465
let args_ref = args.internal(&mut *tables, tcx);
466466
let closure_kind = kind.internal(&mut *tables, tcx);
467-
Instance::resolve_closure(tables.tcx, def_id, args_ref, closure_kind).stable(&mut *tables)
467+
Some(
468+
Instance::resolve_closure(tables.tcx, def_id, args_ref, closure_kind)
469+
.stable(&mut *tables),
470+
)
468471
}
469472

470473
fn eval_instance(&self, def: InstanceDef, const_ty: Ty) -> Result<Allocation, Error> {

Diff for: compiler/rustc_ty_utils/src/instance.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ fn resolve_associated_item<'tcx>(
322322
match *rcvr_args.type_at(0).kind() {
323323
ty::Closure(closure_def_id, args) => {
324324
let trait_closure_kind = tcx.fn_trait_kind_from_def_id(trait_id).unwrap();
325-
Instance::resolve_closure(tcx, closure_def_id, args, trait_closure_kind)
325+
Some(Instance::resolve_closure(
326+
tcx,
327+
closure_def_id,
328+
args,
329+
trait_closure_kind,
330+
))
326331
}
327332
ty::FnDef(..) | ty::FnPtr(..) => Some(Instance {
328333
def: ty::InstanceDef::FnPtrShim(trait_item_id, rcvr_args.type_at(0)),

0 commit comments

Comments
 (0)