Skip to content

Commit

Permalink
Return adjustment target if adjust kind is never-to-any
Browse files Browse the repository at this point in the history
Without doing so, we'll run into a series of delayed bugs then find that
we have a `TyKind::Error` constructed yet fail to emit an error.

This partially reverts a change in
<rust-lang#121208> related to never type
adjustments in expr typecheck errors.
  • Loading branch information
jieyouxu committed Dec 14, 2024
1 parent 0b0744a commit d15315c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.try_structurally_resolve_type(expr.span, ty).is_never()
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
{
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
let reported = self.dcx().span_delayed_bug(
expr.span,
"expression with never type wound up being adjusted",
);
return Ty::new_error(self.tcx(), reported);

return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
target.to_owned()
} else {
Ty::new_error(self.tcx(), reported)
};
}

let adj_ty = self.next_ty_var(expr.span);
Expand Down

0 comments on commit d15315c

Please sign in to comment.