about summary refs log tree commit diff
path: root/compiler/rustc_traits
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-11-23 05:24:39 +0000
committerMichael Goulet <michael@errs.io>2024-11-23 05:27:45 +0000
commit50fb40a987746e8847091ce354b649be4a44cde1 (patch)
treee27318a583bafcc87e9f457c8aac8f2bbe84c869 /compiler/rustc_traits
parentf5be3ca1e35bbd504b3dea531dd15377c535f287 (diff)
downloadrust-50fb40a987746e8847091ce354b649be4a44cde1.tar.gz
rust-50fb40a987746e8847091ce354b649be4a44cde1.zip
Delay a bug when encountering an impl with unconstrained generics in codegen_select
Diffstat (limited to 'compiler/rustc_traits')
-rw-r--r--compiler/rustc_traits/src/codegen.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/compiler/rustc_traits/src/codegen.rs b/compiler/rustc_traits/src/codegen.rs
index 57225df0819..e5276e6d515 100644
--- a/compiler/rustc_traits/src/codegen.rs
+++ b/compiler/rustc_traits/src/codegen.rs
@@ -74,12 +74,21 @@ pub(crate) fn codegen_select_candidate<'tcx>(
     }
 
     let impl_source = infcx.resolve_vars_if_possible(impl_source);
-    let impl_source = infcx.tcx.erase_regions(impl_source);
-    if impl_source.has_infer() {
-        // Unused lifetimes on an impl get replaced with inference vars, but never resolved,
-        // causing the return value of a query to contain inference vars. We do not have a concept
-        // for this and will in fact ICE in stable hashing of the return value. So bail out instead.
-        infcx.tcx.dcx().has_errors().unwrap();
+    let impl_source = tcx.erase_regions(impl_source);
+    if impl_source.has_non_region_infer() {
+        // Unused generic types or consts on an impl get replaced with inference vars,
+        // but never resolved, causing the return value of a query to contain inference
+        // vars. We do not have a concept for this and will in fact ICE in stable hashing
+        // of the return value. So bail out instead.
+        match impl_source {
+            ImplSource::UserDefined(impl_) => {
+                tcx.dcx().span_delayed_bug(
+                    tcx.def_span(impl_.impl_def_id),
+                    "this impl has unconstrained generic parameters",
+                );
+            }
+            _ => unreachable!(),
+        }
         return Err(CodegenObligationError::FulfillmentError);
     }