use crate::mir::interpret::ConstValue;
use crate::middle::region;
use polonius_engine::Atom;
-use rustc_data_structures::indexed_vec::Idx;
+use rustc_index::vec::Idx;
use rustc_macros::HashStable;
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, GenericArg, GenericArgKind};
use crate::ty::{self, AdtDef, Discr, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable};
/// The anonymous type of a closure. Used to represent the type of
/// `|a| a`.
- Closure(DefId, ClosureSubsts<'tcx>),
+ Closure(DefId, SubstsRef<'tcx>),
/// The anonymous type of a generator. Used to represent the type of
/// `|a| yield a`.
- Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
+ Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
/// A type representin the types stored inside a generator.
/// This should only appear in GeneratorInteriors.
/// type parameters is similar, but the role of CK and CS are
/// different. CK represents the "yield type" and CS represents the
/// "return type" of the generator.
-#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
- Debug, RustcEncodable, RustcDecodable, HashStable)]
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug,
+ RustcEncodable, RustcDecodable, HashStable)]
pub struct ClosureSubsts<'tcx> {
/// Lifetime and type parameters from the enclosing function,
/// concatenated with the types of the upvars.
/// 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 kind_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> {
self.split(def_id, tcx).closure_kind_ty
}
/// 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 sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> {
self.split(def_id, tcx).closure_sig_ty
}
/// 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 kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind {
self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap()
}
/// 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> {
- let ty = self.closure_sig_ty(def_id, tcx);
+ pub fn sig(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
+ let ty = self.sig_ty(def_id, tcx);
match ty.kind {
ty::FnPtr(sig) => sig,
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty.kind),
#[derive(Debug, Copy, Clone)]
pub enum UpvarSubsts<'tcx> {
- Closure(ClosureSubsts<'tcx>),
+ Closure(SubstsRef<'tcx>),
Generator(GeneratorSubsts<'tcx>),
}
pub fn upvar_tys(
self,
def_id: DefId,
- tcx: TyCtxt<'_>,
+ tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let upvar_kinds = match self {
- UpvarSubsts::Closure(substs) => substs.split(def_id, tcx).upvar_kinds,
+ UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds,
UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds,
};
upvar_kinds.iter().map(|t| {
}
}
-newtype_index! {
+rustc_index::newtype_index! {
/// A [De Bruijn index][dbi] is a standard means of representing
/// regions (and perhaps later types) in a higher-ranked setting. In
/// particular, imagine a type like this:
pub index: u32,
}
-newtype_index! {
+rustc_index::newtype_index! {
pub struct RegionVid {
DEBUG_FORMAT = custom,
}
FreshFloatTy(u32),
}
-newtype_index! {
+rustc_index::newtype_index! {
pub struct BoundVar { .. }
}
pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
match self.kind {
TyKind::Adt(adt, _) => Some(adt.variant_range()),
- TyKind::Generator(def_id, substs, _) => Some(substs.variant_range(def_id, tcx)),
+ TyKind::Generator(def_id, substs, _) =>
+ Some(substs.assert_generator().variant_range(def_id, tcx)),
_ => None,
}
}
match self.kind {
TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)),
TyKind::Generator(def_id, substs, _) =>
- Some(substs.discriminant_for_variant(def_id, tcx, variant_index)),
+ Some(substs.as_generator().discriminant_for_variant(def_id, tcx, variant_index)),
_ => None,
}
}
Adt(_, substs) | Opaque(_, substs) => {
out.extend(substs.regions())
}
- Closure(_, ClosureSubsts { ref substs }) |
- Generator(_, GeneratorSubsts { ref substs }, _) => {
+ Closure(_, ref substs ) |
+ Generator(_, ref substs, _) => {
out.extend(substs.regions())
}
Projection(ref data) | UnnormalizedProjection(ref data) => {