1
Fork 0

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```
This commit is contained in:
Matthias Krüger 2025-02-21 12:45:24 +01:00 committed by GitHub
commit 3a04ec8c56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 9 deletions

View file

@ -613,9 +613,14 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
// types, so there's no guarantee that it succeeds. We also
// can't rely on the the `ErrorGuaranteed` from `fully_perform` here
// because it comes from delay_span_bug.
//
// Do this inside of a probe because we don't particularly care (or want)
// any region side-effects of this operation in our infcx.
typeck.infcx.probe(|_| {
let ocx = ObligationCtxt::new_with_diagnostics(&typeck.infcx);
let errors =
match dropck_outlives::compute_dropck_outlives_with_errors(&ocx, op, span) {
let errors = match dropck_outlives::compute_dropck_outlives_with_errors(
&ocx, op, span,
) {
Ok(_) => ocx.select_all_or_error(),
Err(e) => {
if e.is_empty() {
@ -631,6 +636,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
} else {
span_bug!(span, "Rerunning drop data query produced no error.");
}
});
DropData { dropck_result: Default::default(), region_constraint_data: None }
}
}

View file

@ -950,7 +950,7 @@ impl<'tcx> InferCtxt<'tcx> {
let inner = self.inner.borrow();
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
let storage = inner.region_constraint_storage.as_ref().expect("regions already resolved");
assert!(storage.data.is_empty());
assert!(storage.data.is_empty(), "{:#?}", storage.data);
// We clone instead of taking because borrowck still wants to use the
// inference context after calling this for diagnostics and the new
// trait solver.

View file

@ -0,0 +1,18 @@
// Regression test for <https://github.com/rust-lang/rust/issues/137288>.
trait B {
type C;
}
impl<U> B for &Missing {
//~^ ERROR cannot find type `Missing` in this scope
type C = ();
}
struct E<T: B> {
g: <T as B>::C,
}
fn h(i: Box<E<&()>>) {}
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/bad-drop-side-effects.rs:7:16
|
LL | impl<U> B for &Missing {
| ^^^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0412`.