diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c4a3fe8fa62..cd2bb32bbf8 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -92,7 +92,7 @@ pub struct LoweringContext<'a> { trait_impls: BTreeMap>, trait_default_impl: BTreeMap, - is_generator: hir::IsGenerator, + is_generator: bool, catch_scopes: Vec, loop_scopes: Vec, @@ -146,7 +146,7 @@ pub fn lower_crate(sess: &Session, current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)], item_local_id_counters: NodeMap(), node_id_to_hir_id: IndexVec::new(), - is_generator: hir::IsGenerator::No, + is_generator: false, }.lower_crate(krate) } @@ -371,7 +371,7 @@ impl<'a> LoweringContext<'a> { arguments: decl.map_or(hir_vec![], |decl| { decl.inputs.iter().map(|x| self.lower_arg(x)).collect() }), - is_generator: self.is_generator == hir::IsGenerator::Yes, + is_generator: self.is_generator, value, }; let id = body.id(); @@ -432,7 +432,7 @@ impl<'a> LoweringContext<'a> { fn lower_body(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId where F: FnOnce(&mut LoweringContext) -> hir::Expr { - let prev = mem::replace(&mut self.is_generator, hir::IsGenerator::No); + let prev = mem::replace(&mut self.is_generator, false); let result = f(self); let r = self.record_body(result, decl); self.is_generator = prev; @@ -1940,13 +1940,13 @@ impl<'a> LoweringContext<'a> { ExprKind::Closure(capture_clause, ref decl, ref body, fn_decl_span) => { self.with_new_scopes(|this| { this.with_parent_def(e.id, |this| { - let mut gen = hir::IsGenerator::No; + let mut is_generator = false; let body_id = this.lower_body(Some(decl), |this| { let e = this.lower_expr(body); - gen = this.is_generator; + is_generator = this.is_generator; e }); - if gen == hir::IsGenerator::Yes && !decl.inputs.is_empty() { + if is_generator && !decl.inputs.is_empty() { span_err!(this.sess, fn_decl_span, E0625, "generators cannot have explicit arguments"); this.sess.abort_if_errors(); @@ -1955,7 +1955,7 @@ impl<'a> LoweringContext<'a> { this.lower_fn_decl(decl), body_id, fn_decl_span, - gen) + is_generator) }) }) } @@ -2092,7 +2092,7 @@ impl<'a> LoweringContext<'a> { } ExprKind::Yield(ref opt_expr) => { - self.is_generator = hir::IsGenerator::Yes; + self.is_generator = true; let expr = opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| { self.expr(e.span, hir::ExprTup(hir_vec![]), ThinVec::new()) }); diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 8fb7ca643a7..d1cc6b5d3e4 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1013,8 +1013,9 @@ pub enum Expr_ { /// /// 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, IsGenerator), + /// This may also be a generator literal, indicated by the final boolean, + /// in that case there is an GeneratorClause. + ExprClosure(CaptureClause, P, BodyId, Span, bool), /// A block (`{ ... }`) ExprBlock(P), @@ -1190,12 +1191,6 @@ pub struct Destination { pub target_id: ScopeTarget, } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum IsGenerator { - Yes, - No, -} - #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum CaptureClause { CaptureByValue, diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 04e8cbeb7ff..140c9c6ae9a 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -688,11 +688,6 @@ impl<'a, 'gcx, 'tcx> HashStable> for hir::M } } -impl_stable_hash_for!(enum hir::IsGenerator { - Yes, - No -}); - impl_stable_hash_for!(enum hir::CaptureClause { CaptureByValue, CaptureByRef diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 9c018026092..903d70add6f 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -560,7 +560,7 @@ macro_rules! make_mir_visitor { AggregateKind::Generator(ref $($mutability)* def_id, ref $($mutability)* closure_substs) => { self.visit_def_id(def_id, location); - self.visit_closure_substs(closure_substs); + self.visit_closure_substs(closure_substs, location); } } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 338c46a4c93..9b3585fff58 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -428,7 +428,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } } - hir::ExprClosure(.., gen) => { + hir::ExprClosure(.., is_generator) => { let closure_ty = cx.tables().expr_ty(expr); let (def_id, substs) = match closure_ty.sty { ty::TyClosure(def_id, substs) | @@ -447,7 +447,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, closure_id: def_id, substs: substs, upvars: upvars, - generator: gen == hir::IsGenerator::Yes, + generator: is_generator, } } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index ffaf6afb6e8..70325ee3a93 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -75,11 +75,11 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> { fn visit_expr(&mut self, expr: &'gcx hir::Expr) { match expr.node { - hir::ExprClosure(cc, _, body_id, _, gen) => { + hir::ExprClosure(cc, _, body_id, _, is_generator) => { let body = self.fcx.tcx.hir.body(body_id); self.visit_body(body); self.fcx.analyze_closure(expr.id, expr.span, body, cc, - gen == hir::IsGenerator::Yes); + is_generator); } _ => { } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 05f5c4070d3..d1ba9fd0918 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1155,8 +1155,8 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, NodeField(field) => icx.to_ty(&field.ty), - NodeExpr(&hir::Expr { node: hir::ExprClosure(.., gen), .. }) => { - if gen == hir::IsGenerator::Yes { + NodeExpr(&hir::Expr { node: hir::ExprClosure(.., is_generator), .. }) => { + if is_generator { return tcx.typeck_tables_of(def_id).node_id_to_type(node_id); }