Skip to content

Commit eab060f

Browse files
committed
clean ClosureSubsts in rustc::ty
1 parent 8ab82c1 commit eab060f

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::traits;
2929
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
3030
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
3131
use crate::ty::{TyS, TyKind, List};
32-
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
32+
use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const};
3333
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
3434
use crate::ty::RegionKind;
3535
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
@@ -2482,7 +2482,7 @@ impl<'tcx> TyCtxt<'tcx> {
24822482
}
24832483

24842484
#[inline]
2485-
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
2485+
pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>)
24862486
-> Ty<'tcx> {
24872487
self.mk_ty(Closure(closure_id, closure_substs))
24882488
}

src/librustc/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl FlagComputation {
106106
&ty::Closure(_, ref substs) => {
107107
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
108108
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
109-
self.add_substs(&substs.substs);
109+
self.add_substs(substs);
110110
}
111111

112112
&ty::Bound(debruijn, _) => {

src/librustc/ty/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl<'tcx> Instance<'tcx> {
321321
let actual_kind = substs.closure_kind(def_id, tcx);
322322

323323
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
324-
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
324+
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs.substs),
325325
_ => Instance::new(def_id, substs.substs)
326326
}
327327
}
@@ -335,7 +335,7 @@ impl<'tcx> Instance<'tcx> {
335335
pub fn fn_once_adapter_instance(
336336
tcx: TyCtxt<'tcx>,
337337
closure_did: DefId,
338-
substs: ty::ClosureSubsts<'tcx>,
338+
substs: ty::SubstsRef<'tcx>,
339339
) -> Instance<'tcx> {
340340
debug!("fn_once_adapter_shim({:?}, {:?})",
341341
closure_did,

src/librustc/ty/print/obsolete.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use rustc::hir::def_id::DefId;
99
use rustc::mir::interpret::ConstValue;
1010
use rustc::ty::subst::SubstsRef;
11-
use rustc::ty::{self, ClosureSubsts, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
11+
use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
1212
use rustc::{bug, hir};
1313
use std::fmt::Write;
1414
use std::iter;
@@ -154,8 +154,13 @@ impl DefPathBasedNames<'tcx> {
154154
self.push_type_name(sig.output(), output, debug);
155155
}
156156
}
157-
ty::Generator(def_id, GeneratorSubsts { ref substs }, _)
158-
| ty::Closure(def_id, ClosureSubsts { ref substs }) => {
157+
ty::Generator(def_id, GeneratorSubsts { ref substs }, _) => {
158+
self.push_def_path(def_id, output);
159+
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));
160+
let substs = substs.truncate_to(self.tcx, generics);
161+
self.push_generic_params(substs, iter::empty(), output, debug);
162+
}
163+
ty::Closure(def_id, substs) => {
159164
self.push_def_path(def_id, output);
160165
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));
161166
let substs = substs.truncate_to(self.tcx, generics);

src/librustc/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
442442
// the (anonymous) type of the same closure expression. So
443443
// all of their regions should be equated.
444444
let substs = relation.relate(&a_substs, &b_substs)?;
445-
Ok(tcx.mk_closure(a_id, substs))
445+
Ok(tcx.mk_closure(a_id, &substs))
446446
}
447447

448448
(&ty::RawPtr(ref a_mt), &ty::RawPtr(ref b_mt)) =>

src/librustc/ty/subst.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,22 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
384384
/// Divides the closure substs into their respective
385385
/// components. Single source of truth with respect to the
386386
/// ordering.
387-
fn split(self, def_id: DefId, tcx: TyCtxt<'_>) -> SplitClosureSubsts<'tcx> {
387+
fn split(&self, def_id: DefId, tcx: TyCtxt<'_>) -> SplitClosureSubsts<'_> {
388388
let generics = tcx.generics_of(def_id);
389389
let parent_len = generics.parent_count;
390390
SplitClosureSubsts {
391-
closure_kind_ty: self.substs.type_at(parent_len),
392-
closure_sig_ty: self.substs.type_at(parent_len + 1),
393-
upvar_kinds: &self.substs[parent_len + 2..],
391+
closure_kind_ty: self.type_at(parent_len),
392+
closure_sig_ty: self.type_at(parent_len + 1),
393+
upvar_kinds: &self[parent_len + 2..],
394394
}
395395
}
396396

397397
#[inline]
398398
pub fn upvar_tys(
399-
&self,
399+
&'a self,
400400
def_id: DefId,
401401
tcx: TyCtxt<'_>,
402-
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
402+
) -> impl Iterator<Item = Ty<'a>> + 'a {
403403
let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
404404
upvar_kinds.iter().map(|t| {
405405
if let UnpackedKind::Type(ty) = t.unpack() {
@@ -413,15 +413,15 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
413413
/// Returns the closure kind for this closure; may return a type
414414
/// variable during inference. To get the closure kind during
415415
/// inference, use `infcx.closure_kind(def_id, substs)`.
416-
pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> {
416+
pub fn closure_kind_ty(&'a self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'a> {
417417
self.split(def_id, tcx).closure_kind_ty
418418
}
419419

420420
/// Returns the type representing the closure signature for this
421421
/// closure; may contain type variables during inference. To get
422422
/// the closure signature during inference, use
423423
/// `infcx.fn_sig(def_id)`.
424-
pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> {
424+
pub fn closure_sig_ty(&'a self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'a> {
425425
self.split(def_id, tcx).closure_sig_ty
426426
}
427427

@@ -430,7 +430,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
430430
/// there are no type variables.
431431
///
432432
/// If you have an inference context, use `infcx.closure_kind()`.
433-
pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind {
433+
pub fn closure_kind(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind {
434434
self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap()
435435
}
436436

@@ -439,7 +439,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
439439
/// there are no type variables.
440440
///
441441
/// If you have an inference context, use `infcx.closure_sig()`.
442-
pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
442+
pub fn closure_sig(&'a self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'a> {
443443
let ty = self.closure_sig_ty(def_id, tcx);
444444
match ty.kind {
445445
ty::FnPtr(sig) => sig,

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'tcx> TyCtxt<'tcx> {
642642
/// wrapped in a binder.
643643
pub fn closure_env_ty(self,
644644
closure_def_id: DefId,
645-
closure_substs: ty::ClosureSubsts<'tcx>)
645+
closure_substs: SubstsRef<'tcx>)
646646
-> Option<ty::Binder<Ty<'tcx>>>
647647
{
648648
let closure_ty = self.mk_closure(closure_def_id, closure_substs);

src/librustc/ty/walk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
111111
stack.extend(substs.types().rev());
112112
}
113113
ty::Closure(_, ref substs) => {
114-
stack.extend(substs.substs.types().rev());
114+
stack.extend(substs.types().rev());
115115
}
116116
ty::Generator(_, ref substs, _) => {
117117
stack.extend(substs.substs.types().rev());

0 commit comments

Comments
 (0)