]> git.lizzy.rs Git - rust.git/commitdiff
replace GeneratorSubsts with SubstsRef
authorcsmoe <csmoe@msn.com>
Thu, 3 Oct 2019 13:02:06 +0000 (21:02 +0800)
committercsmoe <csmoe@msn.com>
Fri, 4 Oct 2019 12:47:43 +0000 (20:47 +0800)
src/librustc/ty/sty.rs
src/librustc/ty/subst.rs

index 3f09bf749edc8a6eb71b74c05c07b9bf488375c1..c1589b31de78a8bc76530b628522bf4caf1e9d5d 100644 (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.
index 537192b0a2e58dccf61c50aaa0a09a033b97ac46..de98c098ea5397b2213848df73f21ddab5d6c85a 100644 (file)
@@ -5,7 +5,7 @@
 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 @@ pub fn as_closure(&'a self) -> ClosureSubsts<'a> {
         }
     }
 
+    /// 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, _| {