Skip to content

Commit 7365d54

Browse files
committed
Subsume ClosureArgs.parent
1 parent 1e62827 commit 7365d54

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

engine/lib/import_thir.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ end) : EXPR = struct
10191019
TFloat
10201020
(match k with F16 -> F16 | F32 -> F32 | F64 -> F64 | F128 -> F128)
10211021
| Arrow signature
1022-
| Closure (_, { untupled_sig = signature; _ })
1022+
| Closure { untupled_sig = signature; _ }
10231023
| FnDef { fn_sig = signature; _ } ->
10241024
let ({ inputs; output; _ } : Thir.ty_fn_sig) = signature.value in
10251025
let inputs =

frontend/exporter/src/types/mir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ fn translate_terminator_kind_call<'tcx, S: BaseState<'tcx> + HasMir<'tcx> + HasO
373373
let sig = match hax_ty.kind() {
374374
TyKind::Arrow(sig) => sig,
375375
TyKind::FnDef { fn_sig, .. } => fn_sig,
376-
TyKind::Closure(_, args) => &args.untupled_sig,
376+
TyKind::Closure(args) => &args.untupled_sig,
377377
_ => supposely_unreachable_fatal!(
378378
s,
379379
"TerminatorKind_Call_expected_fn_type";
@@ -850,9 +850,9 @@ pub enum AggregateKind {
850850
#[custom_arm(rustc_middle::mir::AggregateKind::Closure(def_id, generics) => {
851851
let closure = generics.as_closure();
852852
let args = ClosureArgs::sfrom(s, *def_id, closure);
853-
AggregateKind::Closure(def_id.sinto(s), args)
853+
AggregateKind::Closure(args)
854854
})]
855-
Closure(DefId, ClosureArgs),
855+
Closure(ClosureArgs),
856856
#[custom_arm(FROM_TYPE::Coroutine(def_id, generics) => TO_TYPE::Coroutine(translate_item_ref(s, *def_id, generics)),)]
857857
Coroutine(ItemRef),
858858
#[custom_arm(FROM_TYPE::CoroutineClosure(def_id, generics) => TO_TYPE::CoroutineClosure(translate_item_ref(s, *def_id, generics)),)]

frontend/exporter/src/types/ty.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,10 @@ pub enum TyKind {
893893
#[custom_arm(
894894
ty::TyKind::Closure (def_id, generics) => {
895895
let closure = generics.as_closure();
896-
TyKind::Closure(
897-
def_id.sinto(s),
898-
ClosureArgs::sfrom(s, *def_id, closure),
899-
)
896+
TyKind::Closure(ClosureArgs::sfrom(s, *def_id, closure))
900897
},
901898
)]
902-
Closure(DefId, ClosureArgs),
899+
Closure(ClosureArgs),
903900

904901
#[custom_arm(FROM_TYPE::Adt(adt_def, generics) => TO_TYPE::Adt(translate_item_ref(s, adt_def.did(), generics)),)]
905902
Adt(ItemRef),
@@ -1352,11 +1349,10 @@ pub enum AliasRelationDirection {
13521349
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, JsonSchema)]
13531350
#[derive_group(Serializers)]
13541351
pub struct ClosureArgs {
1352+
pub item: ItemRef,
13551353
/// The base kind of this closure. The kinds are ordered by inclusion: any `Fn` works as an
13561354
/// `FnMut`, and any `FnMut` works as an `FnOnce`.
13571355
pub kind: ClosureKind,
1358-
/// Reference to the item which contains the closure.
1359-
pub parent: ItemRef,
13601356
/// The proper `fn(A, B, C) -> D` signature of the closure.
13611357
pub untupled_sig: PolyFnSig,
13621358
/// The signature of the closure as one input and one output, where the input arguments are
@@ -1379,13 +1375,15 @@ impl ClosureArgs {
13791375
{
13801376
let tcx = s.base().tcx;
13811377
let sig = from.sig();
1378+
let item = {
1379+
// The closure has no generics of its own: it inherits its parent generics and could
1380+
// have late-bound args but these are part of the signature.
1381+
let parent_args = tcx.mk_args(from.parent_args());
1382+
translate_item_ref(s, def_id, parent_args)
1383+
};
13821384
ClosureArgs {
1385+
item,
13831386
kind: from.kind().sinto(s),
1384-
parent: {
1385-
let parent_id = tcx.generics_of(def_id).parent.unwrap();
1386-
let parent_args = tcx.mk_args(from.parent_args());
1387-
translate_item_ref(s, parent_id, parent_args)
1388-
},
13891387
tupled_sig: sig.sinto(s),
13901388
untupled_sig: tcx
13911389
.signature_unclosure(sig, rustc_hir::Safety::Safe)

0 commit comments

Comments
 (0)