Skip to content

Commit 3a04ec8

Browse files
authored
Rollup merge of #137302 - compiler-errors:stray-drop-regions, r=matthewjasper
Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck Fixes #137288. See the comment I left on the probe. I'm not totally sure why this depends on *both* an unconstrained type parameter in the impl and a type error for the self type, but I think the fix is at least theoretically well motivated. r? ```@matthewjasper```
2 parents 72861ea + d4609f8 commit 3a04ec8

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,14 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
613613
// types, so there's no guarantee that it succeeds. We also
614614
// can't rely on the the `ErrorGuaranteed` from `fully_perform` here
615615
// because it comes from delay_span_bug.
616-
let ocx = ObligationCtxt::new_with_diagnostics(&typeck.infcx);
617-
let errors =
618-
match dropck_outlives::compute_dropck_outlives_with_errors(&ocx, op, span) {
616+
//
617+
// Do this inside of a probe because we don't particularly care (or want)
618+
// any region side-effects of this operation in our infcx.
619+
typeck.infcx.probe(|_| {
620+
let ocx = ObligationCtxt::new_with_diagnostics(&typeck.infcx);
621+
let errors = match dropck_outlives::compute_dropck_outlives_with_errors(
622+
&ocx, op, span,
623+
) {
619624
Ok(_) => ocx.select_all_or_error(),
620625
Err(e) => {
621626
if e.is_empty() {
@@ -626,11 +631,12 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
626631
}
627632
};
628633

629-
if !errors.is_empty() {
630-
typeck.infcx.err_ctxt().report_fulfillment_errors(errors);
631-
} else {
632-
span_bug!(span, "Rerunning drop data query produced no error.");
633-
}
634+
if !errors.is_empty() {
635+
typeck.infcx.err_ctxt().report_fulfillment_errors(errors);
636+
} else {
637+
span_bug!(span, "Rerunning drop data query produced no error.");
638+
}
639+
});
634640
DropData { dropck_result: Default::default(), region_constraint_data: None }
635641
}
636642
}

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ impl<'tcx> InferCtxt<'tcx> {
950950
let inner = self.inner.borrow();
951951
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
952952
let storage = inner.region_constraint_storage.as_ref().expect("regions already resolved");
953-
assert!(storage.data.is_empty());
953+
assert!(storage.data.is_empty(), "{:#?}", storage.data);
954954
// We clone instead of taking because borrowck still wants to use the
955955
// inference context after calling this for diagnostics and the new
956956
// trait solver.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/137288>.
2+
3+
trait B {
4+
type C;
5+
}
6+
7+
impl<U> B for &Missing {
8+
//~^ ERROR cannot find type `Missing` in this scope
9+
type C = ();
10+
}
11+
12+
struct E<T: B> {
13+
g: <T as B>::C,
14+
}
15+
16+
fn h(i: Box<E<&()>>) {}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/bad-drop-side-effects.rs:7:16
3+
|
4+
LL | impl<U> B for &Missing {
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)