about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-12-14 02:52:29 +0800
committer许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-12-14 17:07:20 +0800
commitd15315cf9d2fbe3c2d348267567feacaddf89c50 (patch)
tree563189d3dc4feae1637e93627f0bc07871da5715
parent0b0744ae8093eeeb9cf9627320ca0d4649c9ffaf (diff)
downloadrust-d15315cf9d2fbe3c2d348267567feacaddf89c50.tar.gz
rust-d15315cf9d2fbe3c2d348267567feacaddf89c50.zip
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
<https://github.com/rust-lang/rust/pull/121208> related to never type
adjustments in expr typecheck errors.
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 65345048bfc..66978399efb 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -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);