From 2afd04c009c53d221d244c82a54daeb4c5d656f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 10 Jul 2017 21:24:22 +0200 Subject: [PATCH] Add some comments --- src/librustc/hir/mod.rs | 2 ++ src/librustc/ty/sty.rs | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 40a745bcebfb..39e17434fa1e 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1023,6 +1023,8 @@ pub enum Expr_ { /// A closure (for example, `move |a, b, c| {a + b + c}`). /// /// The final span is the span of the argument block `|...|` + /// + /// This may also be a generator literal, in that case there is an GeneratorClause. ExprClosure(CaptureClause, P, BodyId, Span, Option), /// A block (`{ ... }`) ExprBlock(P), diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index bd5f6a8e2625..0f0bcdb78b8a 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -149,7 +149,8 @@ pub enum TypeVariants<'tcx> { /// `|a| a`. TyClosure(DefId, ClosureSubsts<'tcx>), - /// The anonymous type of a generator. Pairs with a TyClosure for closure generators. + /// The anonymous type of a generator. Used to represent the type of + /// `|a| yield a`. TyGenerator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>), /// The never type `!` @@ -279,6 +280,9 @@ impl<'a, 'gcx, 'acx, 'tcx> ClosureSubsts<'tcx> { } impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> { + /// This returns the types of the MIR locals which had to be stored across suspension points. + /// It is calculated in rustc_mir::transform::generator::StateTransform. + /// All the types here must be in the tuple in GeneratorInterior. pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> impl Iterator> + 'tcx { @@ -287,6 +291,8 @@ impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> { state.into_iter() } + /// This is the types of all the fields stored in a generator. + /// It includes the upvars, state types and the state discriminant which is u32. pub fn field_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> impl Iterator> + 'tcx {