Skip to content

Commit d15315c

Browse files
committed
Return adjustment target if adjust kind is never-to-any
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.
1 parent 0b0744a commit d15315c

File tree

1 file changed

+7
-2
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+7
-2
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7272
if self.try_structurally_resolve_type(expr.span, ty).is_never()
7373
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
7474
{
75-
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
75+
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
7676
let reported = self.dcx().span_delayed_bug(
7777
expr.span,
7878
"expression with never type wound up being adjusted",
7979
);
80-
return Ty::new_error(self.tcx(), reported);
80+
81+
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
82+
target.to_owned()
83+
} else {
84+
Ty::new_error(self.tcx(), reported)
85+
};
8186
}
8287

8388
let adj_ty = self.next_ty_var(expr.span);

0 commit comments

Comments
 (0)