diff options
| author | csmoe <csmoe@msn.com> | 2019-09-26 16:09:51 +0000 |
|---|---|---|
| committer | csmoe <csmoe@msn.com> | 2019-09-29 16:17:46 +0000 |
| commit | eab060f4da1eeb302953b76d35278679bfeb76b0 (patch) | |
| tree | 0f506f1a321c983b64da97f91dcc658272466a2f | |
| parent | 8ab82c147af31c1346c6e78c95722ce8bf27501b (diff) | |
| download | rust-eab060f4da1eeb302953b76d35278679bfeb76b0.tar.gz rust-eab060f4da1eeb302953b76d35278679bfeb76b0.zip | |
clean ClosureSubsts in rustc::ty
| -rw-r--r-- | src/librustc/ty/context.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ty/flags.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/instance.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ty/print/obsolete.rs | 11 | ||||
| -rw-r--r-- | src/librustc/ty/relate.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/subst.rs | 20 | ||||
| -rw-r--r-- | src/librustc/ty/util.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/walk.rs | 2 |
8 files changed, 26 insertions, 21 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 6c5d9a6dfdf..6baf59a2577 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -29,7 +29,7 @@ use crate::traits; use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals}; use crate::ty::{self, DefIdTree, Ty, TypeAndMut}; use crate::ty::{TyS, TyKind, List}; -use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const}; +use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const}; use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate}; use crate::ty::RegionKind; use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid}; @@ -2482,7 +2482,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>) + pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty(Closure(closure_id, closure_substs)) } diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index 6e43aa6a25d..b513ef5a966 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -106,7 +106,7 @@ impl FlagComputation { &ty::Closure(_, ref substs) => { self.add_flags(TypeFlags::HAS_TY_CLOSURE); self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES); - self.add_substs(&substs.substs); + self.add_substs(substs); } &ty::Bound(debruijn, _) => { diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 741830f205c..c0cd1fd0614 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -321,7 +321,7 @@ impl<'tcx> Instance<'tcx> { let actual_kind = substs.closure_kind(def_id, tcx); match needs_fn_once_adapter_shim(actual_kind, requested_kind) { - Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs), + Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs.substs), _ => Instance::new(def_id, substs.substs) } } @@ -335,7 +335,7 @@ impl<'tcx> Instance<'tcx> { pub fn fn_once_adapter_instance( tcx: TyCtxt<'tcx>, closure_did: DefId, - substs: ty::ClosureSubsts<'tcx>, + substs: ty::SubstsRef<'tcx>, ) -> Instance<'tcx> { debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, diff --git a/src/librustc/ty/print/obsolete.rs b/src/librustc/ty/print/obsolete.rs index d7d43b8203f..6f97006c71e 100644 --- a/src/librustc/ty/print/obsolete.rs +++ b/src/librustc/ty/print/obsolete.rs @@ -8,7 +8,7 @@ use rustc::hir::def_id::DefId; use rustc::mir::interpret::ConstValue; use rustc::ty::subst::SubstsRef; -use rustc::ty::{self, ClosureSubsts, Const, GeneratorSubsts, Instance, Ty, TyCtxt}; +use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt}; use rustc::{bug, hir}; use std::fmt::Write; use std::iter; @@ -154,8 +154,13 @@ impl DefPathBasedNames<'tcx> { self.push_type_name(sig.output(), output, debug); } } - ty::Generator(def_id, GeneratorSubsts { ref substs }, _) - | ty::Closure(def_id, ClosureSubsts { ref substs }) => { + ty::Generator(def_id, GeneratorSubsts { ref substs }, _) => { + self.push_def_path(def_id, output); + let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id)); + let substs = substs.truncate_to(self.tcx, generics); + self.push_generic_params(substs, iter::empty(), output, debug); + } + ty::Closure(def_id, substs) => { self.push_def_path(def_id, output); let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id)); let substs = substs.truncate_to(self.tcx, generics); diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 2af6963f712..5cd89d231f9 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -442,7 +442,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>( // the (anonymous) type of the same closure expression. So // all of their regions should be equated. let substs = relation.relate(&a_substs, &b_substs)?; - Ok(tcx.mk_closure(a_id, substs)) + Ok(tcx.mk_closure(a_id, &substs)) } (&ty::RawPtr(ref a_mt), &ty::RawPtr(ref b_mt)) => diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index e17a715e957..6e00c6b29ec 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -384,22 +384,22 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { /// Divides the closure substs into their respective /// components. Single source of truth with respect to the /// ordering. - fn split(self, def_id: DefId, tcx: TyCtxt<'_>) -> SplitClosureSubsts<'tcx> { + fn split(&self, def_id: DefId, tcx: TyCtxt<'_>) -> SplitClosureSubsts<'_> { let generics = tcx.generics_of(def_id); let parent_len = generics.parent_count; SplitClosureSubsts { - closure_kind_ty: self.substs.type_at(parent_len), - closure_sig_ty: self.substs.type_at(parent_len + 1), - upvar_kinds: &self.substs[parent_len + 2..], + closure_kind_ty: self.type_at(parent_len), + closure_sig_ty: self.type_at(parent_len + 1), + upvar_kinds: &self[parent_len + 2..], } } #[inline] pub fn upvar_tys( - &self, + &'a self, def_id: DefId, tcx: TyCtxt<'_>, - ) -> impl Iterator<Item = Ty<'tcx>> + 'tcx { + ) -> impl Iterator<Item = Ty<'a>> + 'a { let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx); upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { @@ -413,7 +413,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { /// Returns the closure kind for this closure; may return a type /// variable during inference. To get the closure kind during /// inference, use `infcx.closure_kind(def_id, substs)`. - pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { + pub fn closure_kind_ty(&'a self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'a> { self.split(def_id, tcx).closure_kind_ty } @@ -421,7 +421,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { /// closure; may contain type variables during inference. To get /// the closure signature during inference, use /// `infcx.fn_sig(def_id)`. - pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { + pub fn closure_sig_ty(&'a self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'a> { self.split(def_id, tcx).closure_sig_ty } @@ -430,7 +430,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { /// there are no type variables. /// /// If you have an inference context, use `infcx.closure_kind()`. - pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind { + pub fn closure_kind(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind { self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap() } @@ -439,7 +439,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { /// there are no type variables. /// /// If you have an inference context, use `infcx.closure_sig()`. - pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> { + pub fn closure_sig(&'a self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'a> { let ty = self.closure_sig_ty(def_id, tcx); match ty.kind { ty::FnPtr(sig) => sig, diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index c4d8e452441..05f0d164cc1 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -642,7 +642,7 @@ impl<'tcx> TyCtxt<'tcx> { /// wrapped in a binder. pub fn closure_env_ty(self, closure_def_id: DefId, - closure_substs: ty::ClosureSubsts<'tcx>) + closure_substs: SubstsRef<'tcx>) -> Option<ty::Binder<Ty<'tcx>>> { let closure_ty = self.mk_closure(closure_def_id, closure_substs); diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs index 12f0d80cd0e..1895ab83674 100644 --- a/src/librustc/ty/walk.rs +++ b/src/librustc/ty/walk.rs @@ -111,7 +111,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { stack.extend(substs.types().rev()); } ty::Closure(_, ref substs) => { - stack.extend(substs.substs.types().rev()); + stack.extend(substs.types().rev()); } ty::Generator(_, ref substs, _) => { stack.extend(substs.substs.types().rev()); |
