about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-02-24 19:21:49 -0500
committerGitHub <noreply@github.com>2025-02-24 19:21:49 -0500
commit6e6dcedb616d89b03ad4d8f3c024c2bf4f6cfe55 (patch)
tree3e7534aa147ccfcf63ebb9d4c2ec365963da72e1
parent87f3908066243c86ff540ed0dd57750624634772 (diff)
parenta4a9fb412e1b0420b570a2d6ac2cf81142c5cc11 (diff)
downloadrust-6e6dcedb616d89b03ad4d8f3c024c2bf4f6cfe55.tar.gz
rust-6e6dcedb616d89b03ad4d8f3c024c2bf4f6cfe55.zip
Rollup merge of #137550 - matthewjasper:panic-later-for-missing-dropck-error, r=compiler-errors
Don't immediately panic if dropck fails without returning errors

This span_bug was a little too optimistic. I've decided that matching on the ErrorGuaranteed is a little more sensible than a delay bug that will always be ignored.

closes #137329
r? `@compiler-errors`
-rw-r--r--compiler/rustc_borrowck/src/type_check/liveness/trace.rs9
-rw-r--r--tests/ui/dropck/dropck-after-failed-type-lowering.rs14
-rw-r--r--tests/ui/dropck/dropck-after-failed-type-lowering.stderr19
3 files changed, 37 insertions, 5 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs
index 12e8be41614..dc35d5eb89c 100644
--- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs
+++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs
@@ -4,7 +4,6 @@ use rustc_index::interval::IntervalSet;
 use rustc_infer::infer::canonical::QueryRegionConstraints;
 use rustc_infer::infer::outlives::for_liveness;
 use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, HasLocalDecls, Local, Location};
-use rustc_middle::span_bug;
 use rustc_middle::traits::query::DropckOutlivesResult;
 use rustc_middle::ty::relate::Relate;
 use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
@@ -12,7 +11,7 @@ use rustc_mir_dataflow::ResultsCursor;
 use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
 use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
 use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
-use rustc_span::{DUMMY_SP, Span};
+use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
 use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
 use rustc_trait_selection::traits::ObligationCtxt;
 use rustc_trait_selection::traits::query::dropck_outlives;
@@ -608,7 +607,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
             Ok(TypeOpOutput { output, constraints, .. }) => {
                 DropData { dropck_result: output, region_constraint_data: constraints }
             }
-            Err(_) => {
+            Err(ErrorGuaranteed { .. }) => {
                 // We don't run dropck on HIR, and dropck looks inside fields of
                 // types, so there's no guarantee that it succeeds. We also
                 // can't rely on the the `ErrorGuaranteed` from `fully_perform` here
@@ -631,10 +630,10 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
                         }
                     };
 
+                    // Could have no errors if a type lowering error, say, caused the query
+                    // to fail.
                     if !errors.is_empty() {
                         typeck.infcx.err_ctxt().report_fulfillment_errors(errors);
-                    } else {
-                        span_bug!(span, "Rerunning drop data query produced no error.");
                     }
                 });
                 DropData { dropck_result: Default::default(), region_constraint_data: None }
diff --git a/tests/ui/dropck/dropck-after-failed-type-lowering.rs b/tests/ui/dropck/dropck-after-failed-type-lowering.rs
new file mode 100644
index 00000000000..2441e26fec9
--- /dev/null
+++ b/tests/ui/dropck/dropck-after-failed-type-lowering.rs
@@ -0,0 +1,14 @@
+// Regression test for #137329
+
+trait B {
+    type C<'a>;
+    fn d<E>() -> F<E> {
+        todo!()
+    }
+}
+struct F<G> {
+    h: Option<<G as B>::C>,
+    //~^ ERROR missing generics for associated type `B::C`
+}
+
+fn main() {}
diff --git a/tests/ui/dropck/dropck-after-failed-type-lowering.stderr b/tests/ui/dropck/dropck-after-failed-type-lowering.stderr
new file mode 100644
index 00000000000..56ea72de0c5
--- /dev/null
+++ b/tests/ui/dropck/dropck-after-failed-type-lowering.stderr
@@ -0,0 +1,19 @@
+error[E0107]: missing generics for associated type `B::C`
+  --> $DIR/dropck-after-failed-type-lowering.rs:10:25
+   |
+LL |     h: Option<<G as B>::C>,
+   |                         ^ expected 1 lifetime argument
+   |
+note: associated type defined here, with 1 lifetime parameter: `'a`
+  --> $DIR/dropck-after-failed-type-lowering.rs:4:10
+   |
+LL |     type C<'a>;
+   |          ^ --
+help: add missing lifetime argument
+   |
+LL |     h: Option<<G as B>::C<'a>>,
+   |                          ++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0107`.