Skip to content

Commit 1f8e1d8

Browse files
committed
remove ClosureSubsts with SubstsRef
1 parent eab060f commit 1f8e1d8

File tree

20 files changed

+37
-29
lines changed

20 files changed

+37
-29
lines changed

src/librustc/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
896896
}
897897
}));
898898

899-
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
899+
self.tcx.mk_closure(def_id, substs)
900900
}
901901

902902
ty::Generator(def_id, substs, movability) => {

src/librustc/middle/mem_categorization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
745745
// During upvar inference we may not know the
746746
// closure kind, just use the LATTICE_BOTTOM value.
747747
Some(infcx) =>
748-
infcx.closure_kind(closure_def_id, ty::ClosureSubsts::from_ref(closure_substs))
748+
infcx.closure_kind(closure_def_id,
749+
ty::ClosureSubsts::from_ref(closure_substs))
749750
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
750751

751752
None =>

src/librustc/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'tcx> Rvalue<'tcx> {
218218
tcx.type_of(def.did).subst(tcx, substs)
219219
}
220220
AggregateKind::Closure(did, substs) => {
221-
tcx.mk_closure(did, substs)
221+
tcx.mk_closure(did, &substs.substs)
222222
}
223223
AggregateKind::Generator(did, substs, movability) => {
224224
tcx.mk_generator(did, substs, movability)

src/librustc/traits/select.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
20512051
"assemble_unboxed_candidates: kind={:?} obligation={:?}",
20522052
kind, obligation
20532053
);
2054-
match self.infcx.closure_kind(closure_def_id, closure_substs) {
2054+
match self.infcx.closure_kind(closure_def_id,
2055+
ty::ClosureSubsts::from_ref(closure_substs)) {
20552056
Some(closure_kind) => {
20562057
debug!(
20572058
"assemble_unboxed_candidates: closure_kind = {:?}",
@@ -3375,7 +3376,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33753376
obligations.push(Obligation::new(
33763377
obligation.cause.clone(),
33773378
obligation.param_env,
3378-
ty::Predicate::ClosureKind(closure_def_id, ty::ClosureSubsts::from_ref(substs.clone()), kind),
3379+
ty::Predicate::ClosureKind(closure_def_id,
3380+
ty::ClosureSubsts::from_ref(substs.clone()), kind),
33793381
));
33803382
}
33813383

@@ -3876,7 +3878,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
38763878
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",
38773879
obligation, closure_def_id, substs,
38783880
);
3879-
let closure_type = self.infcx.closure_sig(closure_def_id, substs);
3881+
let closure_type = self.infcx.closure_sig(closure_def_id,
3882+
ty::ClosureSubsts::from_ref(substs));
38803883

38813884
debug!(
38823885
"closure_trait_ref_unnormalized: closure_type = {:?}",

src/librustc/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
402402
) -> impl Iterator<Item = Ty<'a>> + 'a {
403403
let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
404404
upvar_kinds.iter().map(|t| {
405-
if let UnpackedKind::Type(ty) = t.unpack() {
405+
if let GenericArgKind::Type(ty) = t.unpack() {
406406
ty
407407
} else {
408408
bug!("upvar should be type")

src/librustc_codegen_ssa/mir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
615615
};
616616

617617
let (def_id, upvar_substs) = match closure_layout.ty.kind {
618-
ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)),
618+
ty::Closure(def_id, substs) => (def_id,
619+
UpvarSubsts::Closure(rustc::ty::ClosureSubsts::from_ref(substs))),
619620
ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
620621
_ => bug!("upvar debuginfo with non-closure arg0 type `{}`", closure_layout.ty)
621622
};

src/librustc_codegen_ssa/mir/rvalue.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
201201
match operand.layout.ty.kind {
202202
ty::Closure(def_id, substs) => {
203203
let instance = Instance::resolve_closure(
204-
bx.cx().tcx(), def_id, substs, ty::ClosureKind::FnOnce);
204+
bx.cx().tcx(), def_id,
205+
rustc::ty::ClosureSubsts::from_ref(substs),
206+
ty::ClosureKind::FnOnce);
205207
OperandValue::Immediate(bx.cx().get_fn(instance))
206208
}
207209
_ => {

src/librustc_codegen_utils/symbol_names/legacy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
224224
ty::Opaque(def_id, substs) |
225225
ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
226226
ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
227-
ty::Closure(def_id, ty::ClosureSubsts { substs }) |
227+
ty::Closure(def_id, substs) |
228228
ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
229229
self.print_def_path(def_id, substs)
230230
}

src/librustc_codegen_utils/symbol_names/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
414414
ty::Opaque(def_id, substs) |
415415
ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
416416
ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
417-
ty::Closure(def_id, ty::ClosureSubsts { substs }) |
417+
ty::Closure(def_id, substs) |
418418
ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
419419
self = self.print_def_path(def_id, substs)?;
420420
}

src/librustc_mir/borrow_check/nll/universal_regions.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
509509
.replace_free_regions_with_nll_infer_vars(FR, &defining_ty);
510510

511511
match defining_ty.kind {
512-
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs),
512+
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id,
513+
rustc::ty::ClosureSubsts::from_ref(substs)),
513514
ty::Generator(def_id, substs, movability) => {
514515
DefiningTy::Generator(def_id, substs, movability)
515516
}
@@ -584,7 +585,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
584585
assert_eq!(self.mir_def_id, def_id);
585586
let closure_sig = substs.closure_sig_ty(def_id, tcx).fn_sig(tcx);
586587
let inputs_and_output = closure_sig.inputs_and_output();
587-
let closure_ty = tcx.closure_env_ty(def_id, substs).unwrap();
588+
let closure_ty = tcx.closure_env_ty(def_id, substs.substs).unwrap();
588589
ty::Binder::fuse(
589590
closure_ty,
590591
inputs_and_output,

src/librustc_mir/hair/cx/expr.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ fn make_mirror_unadjusted<'a, 'tcx>(
506506
hir::ExprKind::Closure(..) => {
507507
let closure_ty = cx.tables().expr_ty(expr);
508508
let (def_id, substs, movability) = match closure_ty.kind {
509-
ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs), None),
509+
ty::Closure(def_id, substs) => (def_id,
510+
UpvarSubsts::Closure(rustc::ty::ClosureSubsts::from_ref(substs)), None),
510511
ty::Generator(def_id, substs, movability) => {
511512
(def_id, UpvarSubsts::Generator(substs), Some(movability))
512513
}
@@ -1002,7 +1003,8 @@ fn convert_var(
10021003
let region = cx.tcx.mk_region(region);
10031004

10041005
let self_expr = if let ty::Closure(_, closure_substs) = closure_ty.kind {
1005-
match cx.infcx.closure_kind(closure_def_id, closure_substs).unwrap() {
1006+
match cx.infcx.closure_kind(closure_def_id,
1007+
rustc::ty::ClosureSubsts::from_ref(closure_substs)).unwrap() {
10061008
ty::ClosureKind::Fn => {
10071009
let ref_closure_ty = cx.tcx.mk_ref(region,
10081010
ty::TypeAndMut {
@@ -1011,7 +1013,7 @@ fn convert_var(
10111013
});
10121014
Expr {
10131015
ty: closure_ty,
1014-
temp_lifetime: temp_lifetime,
1016+
temp_lifetime,
10151017
span: expr.span,
10161018
kind: ExprKind::Deref {
10171019
arg: Expr {

src/librustc_mir/interpret/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7575
let instance = ty::Instance::resolve_closure(
7676
*self.tcx,
7777
def_id,
78-
substs,
78+
rustc::ty::ClosureSubsts::from_ref(substs),
7979
ty::ClosureKind::FnOnce,
8080
);
8181
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));

src/librustc_mir/interpret/intrinsics/type_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
6767
| ty::Opaque(def_id, substs)
6868
| ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs })
6969
| ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs })
70-
| ty::Closure(def_id, ty::ClosureSubsts { substs })
70+
| ty::Closure(def_id, substs)
7171
| ty::Generator(def_id, ty::GeneratorSubsts { substs }, _)
7272
=> self.print_def_path(def_id, substs),
7373
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

src/librustc_mir/monomorphize/collector.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
581581
match source_ty.kind {
582582
ty::Closure(def_id, substs) => {
583583
let instance = Instance::resolve_closure(
584-
self.tcx, def_id, substs, ty::ClosureKind::FnOnce);
584+
self.tcx, def_id,
585+
rustc::ty::ClosureSubsts::from_ref(substs), ty::ClosureKind::FnOnce);
585586
if should_monomorphize_locally(self.tcx, &instance) {
586587
self.output.push(create_fn_mono_item(instance));
587588
}

src/librustc_traits/generic_types.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ crate fn fn_def(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
6969
}
7070

7171
crate fn closure(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
72-
tcx.mk_closure(def_id, ty::ClosureSubsts {
73-
substs: InternalSubsts::bound_vars_for_item(tcx, def_id),
74-
})
72+
tcx.mk_closure(def_id, InternalSubsts::bound_vars_for_item(tcx, def_id))
7573
}
7674

7775
crate fn generator(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {

src/librustc_typeck/check/callee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
103103
// Check whether this is a call to a closure where we
104104
// haven't yet decided on whether the closure is fn vs
105105
// fnmut vs fnonce. If so, we have to defer further processing.
106+
let substs = rustc::ty::ClosureSubsts::from_ref(substs);
106107
if self.closure_kind(def_id, substs).is_none() {
107108
let closure_ty = self.closure_sig(def_id, substs);
108109
let fn_sig = self

src/librustc_typeck/check/closure.rs

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
132132
return self.tcx.mk_generator(expr_def_id, substs, movability);
133133
}
134134

135-
let substs = ty::ClosureSubsts { substs };
136135
let closure_type = self.tcx.mk_closure(expr_def_id, substs);
137136

138137
debug!(

src/librustc_typeck/check/coercion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
237237
// Non-capturing closures are coercible to
238238
// function pointers or unsafe function pointers.
239239
// It cannot convert closures that require unsafe.
240-
self.coerce_closure_to_fn(a, def_id_a, substs_a, b)
240+
self.coerce_closure_to_fn(a, def_id_a,
241+
rustc::ty::ClosureSubsts::from_ref(substs_a), b)
241242
}
242243
_ => {
243244
// Otherwise, just use unification rules.

src/librustc_typeck/check/upvar.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9696
// Extract the type of the closure.
9797
let ty = self.node_ty(closure_hir_id);
9898
let (closure_def_id, substs) = match ty.kind {
99-
ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)),
99+
ty::Closure(def_id, substs) => (def_id,
100+
UpvarSubsts::Closure(rustc::ty::ClosureSubsts::from_ref(substs))),
100101
ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
101102
ty::Error => {
102103
// #51714: skip analysis when we have already encountered type errors

src/librustc_typeck/collect.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1362,10 +1362,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
13621362
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
13631363
}
13641364

1365-
let substs = ty::ClosureSubsts {
1366-
substs: InternalSubsts::identity_for_item(tcx, def_id),
1367-
};
1368-
1365+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
13691366
tcx.mk_closure(def_id, substs)
13701367
}
13711368

0 commit comments

Comments
 (0)