diff options
| author | ash <ashkernel02@gmail.com> | 2025-09-23 12:37:59 -0600 |
|---|---|---|
| committer | ash <ashkernel02@gmail.com> | 2025-09-23 12:37:59 -0600 |
| commit | 60b35635e8084be2e4f8b55f170e8665edb8e275 (patch) | |
| tree | 3d70087b3d05f4f7c2bec6cffd0704d1cf81bf15 | |
| parent | 6710835ae739ca326441ff6c63d24fb123858300 (diff) | |
| download | rust-60b35635e8084be2e4f8b55f170e8665edb8e275.tar.gz rust-60b35635e8084be2e4f8b55f170e8665edb8e275.zip | |
revert change removing `has_infer` check. Commit conservatively patches for now, but more development proceeding. Also contains a more concise test
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 11 | ||||
| -rw-r--r-- | tests/ui/type-inference/box_has_sigdrop.rs | 9 | ||||
| -rw-r--r-- | tests/ui/type-inference/box_has_sigdrop.stderr | 17 | ||||
| -rw-r--r-- | tests/ui/type-inference/dropper_has_sigdrop.rs (renamed from tests/ui/type-inference/has_sigdrop.rs) | 0 |
4 files changed, 36 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 4f039381e50..a4422abc688 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1368,7 +1368,6 @@ impl<'tcx> Ty<'tcx> { /// 2229 drop reorder migration analysis. #[inline] pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool { - assert!(!self.has_non_region_infer()); // Avoid querying in simple cases. match needs_drop_components(tcx, self) { Err(AlwaysRequiresDrop) => true, @@ -1381,6 +1380,16 @@ impl<'tcx> Ty<'tcx> { _ => self, }; + // FIXME + // We should be canonicalizing, or else moving this to a method of inference + // context, or *something* like that, + // but for now just avoid passing inference variables + // to queries that can't cope with them. + // Instead, conservatively return "true" (may change drop order). + if query_ty.has_infer() { + return true; + } + // This doesn't depend on regions, so try to minimize distinct // query keys used. let erased = tcx.normalize_erasing_regions(typing_env, query_ty); diff --git a/tests/ui/type-inference/box_has_sigdrop.rs b/tests/ui/type-inference/box_has_sigdrop.rs new file mode 100644 index 00000000000..3e801197a78 --- /dev/null +++ b/tests/ui/type-inference/box_has_sigdrop.rs @@ -0,0 +1,9 @@ +//@ should-fail +//@ compile-flags: -Wrust-2021-incompatible-closure-captures +// Inference, canonicalization, and significant drops should work nicely together. +// Related issue: #86868 + +fn main() { + let mut state = 0; + Box::new(move || state) +} diff --git a/tests/ui/type-inference/box_has_sigdrop.stderr b/tests/ui/type-inference/box_has_sigdrop.stderr new file mode 100644 index 00000000000..b61b6322c10 --- /dev/null +++ b/tests/ui/type-inference/box_has_sigdrop.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/box_has_sigdrop.rs:8:5 + | +LL | fn main() { + | - expected `()` because of default return type +LL | let mut state = 0; +LL | Box::new(move || state) + | ^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;` + | | + | expected `()`, found `Box<{closure@box_has_sigdrop.rs:8:14}>` + | + = note: expected unit type `()` + found struct `Box<{closure@$DIR/box_has_sigdrop.rs:8:14: 8:21}>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-inference/has_sigdrop.rs b/tests/ui/type-inference/dropper_has_sigdrop.rs index c3d835cfe16..c3d835cfe16 100644 --- a/tests/ui/type-inference/has_sigdrop.rs +++ b/tests/ui/type-inference/dropper_has_sigdrop.rs |
