Skip to content

Commit 893b6f6

Browse files
authored
Rollup merge of #119239 - compiler-errors:yield-coercion, r=davidtwco
Remove unnecessary arm in `check_expr_yield` We always set up the `resume_yield_tys` for async blocks and fns, so this arm was unreachable.
2 parents 093bd08 + 85d2b6e commit 893b6f6

File tree

2 files changed

+1
-16
lines changed

2 files changed

+1
-16
lines changed

Diff for: compiler/rustc_hir/src/hir.rs

-6
Original file line numberDiff line numberDiff line change
@@ -2110,12 +2110,6 @@ pub enum YieldSource {
21102110
Yield,
21112111
}
21122112

2113-
impl YieldSource {
2114-
pub fn is_await(&self) -> bool {
2115-
matches!(self, YieldSource::Await { .. })
2116-
}
2117-
}
2118-
21192113
impl fmt::Display for YieldSource {
21202114
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21212115
f.write_str(match self {

Diff for: compiler/rustc_hir_typeck/src/expr.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
349349
ExprKind::Index(base, idx, brackets_span) => {
350350
self.check_expr_index(base, idx, expr, brackets_span)
351351
}
352-
ExprKind::Yield(value, ref src) => self.check_expr_yield(value, expr, src),
352+
ExprKind::Yield(value, _) => self.check_expr_yield(value, expr),
353353
hir::ExprKind::Err(guar) => Ty::new_error(tcx, guar),
354354
}
355355
}
@@ -3162,22 +3162,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31623162
&self,
31633163
value: &'tcx hir::Expr<'tcx>,
31643164
expr: &'tcx hir::Expr<'tcx>,
3165-
src: &'tcx hir::YieldSource,
31663165
) -> Ty<'tcx> {
31673166
match self.resume_yield_tys {
31683167
Some((resume_ty, yield_ty)) => {
31693168
self.check_expr_coercible_to_type(value, yield_ty, None);
31703169

31713170
resume_ty
31723171
}
3173-
// Given that this `yield` expression was generated as a result of lowering a `.await`,
3174-
// we know that the yield type must be `()`; however, the context won't contain this
3175-
// information. Hence, we check the source of the yield expression here and check its
3176-
// value's type against `()` (this check should always hold).
3177-
None if src.is_await() => {
3178-
self.check_expr_coercible_to_type(value, Ty::new_unit(self.tcx), None);
3179-
Ty::new_unit(self.tcx)
3180-
}
31813172
_ => {
31823173
self.dcx().emit_err(YieldExprOutsideOfCoroutine { span: expr.span });
31833174
// Avoid expressions without types during writeback (#78653).

0 commit comments

Comments
 (0)