Skip to content

Commit

Permalink
typeck/expr.rs: extract out check_expr_yield.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jun 15, 2019
1 parent 8da059b commit 8fd2d12
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/librustc_typeck/check/expr.rs
Expand Up @@ -144,16 +144,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_expr_index(base, idx, needs, expr)
}
ExprKind::Yield(ref value) => {
match self.yield_ty {
Some(ty) => {
self.check_expr_coercable_to_type(&value, ty);
}
None => {
struct_span_err!(self.tcx.sess, expr.span, E0627,
"yield statement outside of generator literal").emit();
}
}
tcx.mk_unit()
self.check_expr_yield(value, expr)
}
hir::ExprKind::Err => {
tcx.types.err
Expand Down Expand Up @@ -914,4 +905,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}

fn check_expr_yield(&self, value: &'tcx hir::Expr, expr: &'tcx hir::Expr) -> Ty<'tcx> {
match self.yield_ty {
Some(ty) => {
self.check_expr_coercable_to_type(&value, ty);
}
None => {
struct_span_err!(self.tcx.sess, expr.span, E0627,
"yield statement outside of generator literal").emit();
}
}
self.tcx.mk_unit()
}
}

0 comments on commit 8fd2d12

Please sign in to comment.