Remove IsGenerator
in favor of a boolean
No need to be mixed!
This commit is contained in:
parent
06ce77cb39
commit
9285a61413
@ -92,7 +92,7 @@ pub struct LoweringContext<'a> {
|
|||||||
trait_impls: BTreeMap<DefId, Vec<NodeId>>,
|
trait_impls: BTreeMap<DefId, Vec<NodeId>>,
|
||||||
trait_default_impl: BTreeMap<DefId, NodeId>,
|
trait_default_impl: BTreeMap<DefId, NodeId>,
|
||||||
|
|
||||||
is_generator: hir::IsGenerator,
|
is_generator: bool,
|
||||||
|
|
||||||
catch_scopes: Vec<NodeId>,
|
catch_scopes: Vec<NodeId>,
|
||||||
loop_scopes: Vec<NodeId>,
|
loop_scopes: Vec<NodeId>,
|
||||||
@ -146,7 +146,7 @@ pub fn lower_crate(sess: &Session,
|
|||||||
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
|
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
|
||||||
item_local_id_counters: NodeMap(),
|
item_local_id_counters: NodeMap(),
|
||||||
node_id_to_hir_id: IndexVec::new(),
|
node_id_to_hir_id: IndexVec::new(),
|
||||||
is_generator: hir::IsGenerator::No,
|
is_generator: false,
|
||||||
}.lower_crate(krate)
|
}.lower_crate(krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
arguments: decl.map_or(hir_vec![], |decl| {
|
arguments: decl.map_or(hir_vec![], |decl| {
|
||||||
decl.inputs.iter().map(|x| self.lower_arg(x)).collect()
|
decl.inputs.iter().map(|x| self.lower_arg(x)).collect()
|
||||||
}),
|
}),
|
||||||
is_generator: self.is_generator == hir::IsGenerator::Yes,
|
is_generator: self.is_generator,
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
let id = body.id();
|
let id = body.id();
|
||||||
@ -432,7 +432,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
fn lower_body<F>(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId
|
fn lower_body<F>(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId
|
||||||
where F: FnOnce(&mut LoweringContext) -> hir::Expr
|
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 result = f(self);
|
||||||
let r = self.record_body(result, decl);
|
let r = self.record_body(result, decl);
|
||||||
self.is_generator = prev;
|
self.is_generator = prev;
|
||||||
@ -1940,13 +1940,13 @@ impl<'a> LoweringContext<'a> {
|
|||||||
ExprKind::Closure(capture_clause, ref decl, ref body, fn_decl_span) => {
|
ExprKind::Closure(capture_clause, ref decl, ref body, fn_decl_span) => {
|
||||||
self.with_new_scopes(|this| {
|
self.with_new_scopes(|this| {
|
||||||
this.with_parent_def(e.id, |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 body_id = this.lower_body(Some(decl), |this| {
|
||||||
let e = this.lower_expr(body);
|
let e = this.lower_expr(body);
|
||||||
gen = this.is_generator;
|
is_generator = this.is_generator;
|
||||||
e
|
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,
|
span_err!(this.sess, fn_decl_span, E0625,
|
||||||
"generators cannot have explicit arguments");
|
"generators cannot have explicit arguments");
|
||||||
this.sess.abort_if_errors();
|
this.sess.abort_if_errors();
|
||||||
@ -1955,7 +1955,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
this.lower_fn_decl(decl),
|
this.lower_fn_decl(decl),
|
||||||
body_id,
|
body_id,
|
||||||
fn_decl_span,
|
fn_decl_span,
|
||||||
gen)
|
is_generator)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2092,7 +2092,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ExprKind::Yield(ref opt_expr) => {
|
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(|| {
|
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())
|
self.expr(e.span, hir::ExprTup(hir_vec![]), ThinVec::new())
|
||||||
});
|
});
|
||||||
|
@ -1013,8 +1013,9 @@ pub enum Expr_ {
|
|||||||
///
|
///
|
||||||
/// The final span is the span of the argument block `|...|`
|
/// The final span is the span of the argument block `|...|`
|
||||||
///
|
///
|
||||||
/// This may also be a generator literal, in that case there is an GeneratorClause.
|
/// This may also be a generator literal, indicated by the final boolean,
|
||||||
ExprClosure(CaptureClause, P<FnDecl>, BodyId, Span, IsGenerator),
|
/// in that case there is an GeneratorClause.
|
||||||
|
ExprClosure(CaptureClause, P<FnDecl>, BodyId, Span, bool),
|
||||||
/// A block (`{ ... }`)
|
/// A block (`{ ... }`)
|
||||||
ExprBlock(P<Block>),
|
ExprBlock(P<Block>),
|
||||||
|
|
||||||
@ -1190,12 +1191,6 @@ pub struct Destination {
|
|||||||
pub target_id: ScopeTarget,
|
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)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||||
pub enum CaptureClause {
|
pub enum CaptureClause {
|
||||||
CaptureByValue,
|
CaptureByValue,
|
||||||
|
@ -688,11 +688,6 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::M
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_stable_hash_for!(enum hir::IsGenerator {
|
|
||||||
Yes,
|
|
||||||
No
|
|
||||||
});
|
|
||||||
|
|
||||||
impl_stable_hash_for!(enum hir::CaptureClause {
|
impl_stable_hash_for!(enum hir::CaptureClause {
|
||||||
CaptureByValue,
|
CaptureByValue,
|
||||||
CaptureByRef
|
CaptureByRef
|
||||||
|
@ -560,7 +560,7 @@ macro_rules! make_mir_visitor {
|
|||||||
AggregateKind::Generator(ref $($mutability)* def_id,
|
AggregateKind::Generator(ref $($mutability)* def_id,
|
||||||
ref $($mutability)* closure_substs) => {
|
ref $($mutability)* closure_substs) => {
|
||||||
self.visit_def_id(def_id, location);
|
self.visit_def_id(def_id, location);
|
||||||
self.visit_closure_substs(closure_substs);
|
self.visit_closure_substs(closure_substs, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 closure_ty = cx.tables().expr_ty(expr);
|
||||||
let (def_id, substs) = match closure_ty.sty {
|
let (def_id, substs) = match closure_ty.sty {
|
||||||
ty::TyClosure(def_id, substs) |
|
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,
|
closure_id: def_id,
|
||||||
substs: substs,
|
substs: substs,
|
||||||
upvars: upvars,
|
upvars: upvars,
|
||||||
generator: gen == hir::IsGenerator::Yes,
|
generator: is_generator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +75,11 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> {
|
|||||||
|
|
||||||
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
|
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
|
||||||
match expr.node {
|
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);
|
let body = self.fcx.tcx.hir.body(body_id);
|
||||||
self.visit_body(body);
|
self.visit_body(body);
|
||||||
self.fcx.analyze_closure(expr.id, expr.span, body, cc,
|
self.fcx.analyze_closure(expr.id, expr.span, body, cc,
|
||||||
gen == hir::IsGenerator::Yes);
|
is_generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => { }
|
_ => { }
|
||||||
|
@ -1155,8 +1155,8 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
|
|
||||||
NodeField(field) => icx.to_ty(&field.ty),
|
NodeField(field) => icx.to_ty(&field.ty),
|
||||||
|
|
||||||
NodeExpr(&hir::Expr { node: hir::ExprClosure(.., gen), .. }) => {
|
NodeExpr(&hir::Expr { node: hir::ExprClosure(.., is_generator), .. }) => {
|
||||||
if gen == hir::IsGenerator::Yes {
|
if is_generator {
|
||||||
return tcx.typeck_tables_of(def_id).node_id_to_type(node_id);
|
return tcx.typeck_tables_of(def_id).node_id_to_type(node_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user