about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-23 09:49:18 +0100
committerGitHub <noreply@github.com>2025-01-23 09:49:18 +0100
commit73dc08d470b3fcad4eb247a853b67575982b32c1 (patch)
tree5f368e6b5f1943dca371f781ac5b6a39ae123907 /compiler
parentcf577f34c47937ccb9983186eca5f8719da585f4 (diff)
parent72fa87445670046d64222980ec9988bf6975fc56 (diff)
downloadrust-73dc08d470b3fcad4eb247a853b67575982b32c1.tar.gz
rust-73dc08d470b3fcad4eb247a853b67575982b32c1.zip
Rollup merge of #134746 - compiler-errors:autoderef-norm-non-wf-coerce-ice, r=lcnr
Don't ICE in coerce when autoderef fails to structurally normalize non-WF type in new solver

r? lcnr
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/coercion.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs
index 3c25f4a8b7c..47abba1cc29 100644
--- a/compiler/rustc_hir_typeck/src/coercion.rs
+++ b/compiler/rustc_hir_typeck/src/coercion.rs
@@ -461,9 +461,17 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
         // to the target type), since that should be the least
         // confusing.
         let Some(InferOk { value: ty, mut obligations }) = found else {
-            let err = first_error.expect("coerce_borrowed_pointer had no error");
-            debug!("coerce_borrowed_pointer: failed with err = {:?}", err);
-            return Err(err);
+            if let Some(first_error) = first_error {
+                debug!("coerce_borrowed_pointer: failed with err = {:?}", first_error);
+                return Err(first_error);
+            } else {
+                // This may happen in the new trait solver since autoderef requires
+                // the pointee to be structurally normalizable, or else it'll just bail.
+                // So when we have a type like `&<not well formed>`, then we get no
+                // autoderef steps (even though there should be at least one). That means
+                // we get no type mismatches, since the loop above just exits early.
+                return Err(TypeError::Mismatch);
+            }
         };
 
         if ty == a && mt_a.mutbl.is_not() && autoderef.step_count() == 1 {