replace GeneratorSubsts with SubstsRef

This commit is contained in:
csmoe 2019-10-03 21:02:06 +08:00
parent 9e35a2811d
commit 2d87bace96
2 changed files with 10 additions and 2 deletions

View file

@ -163,7 +163,7 @@ pub enum TyKind<'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.

View file

@ -5,7 +5,7 @@ use crate::infer::canonical::Canonical;
use crate::ty::{self, Lift, List, Ty, TyCtxt, InferConst, ParamConst};
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use crate::mir::interpret::ConstValue;
use crate::ty::sty::ClosureSubsts;
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
use rustc_serialize::{self, Encodable, Encoder, Decodable, Decoder};
use syntax_pos::{Span, DUMMY_SP};
@ -194,6 +194,14 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
}
}
/// Interpret these substitutions as the substitutions of a generator type.
/// Closure substitutions have a particular structure controlled by the
/// compiler that encodes information like the signature and generator kind;
/// see `ty::GeneratorSubsts` struct for more comments.
pub fn as_generator(&'a self) -> GeneratorSubsts<'a> {
GeneratorSubsts { substs: self }
}
/// Creates a `InternalSubsts` that maps each generic parameter to itself.
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
Self::for_item(tcx, def_id, |param, _| {