Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/type-inference/box_has_sigdrop.rs
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions tests/ui/type-inference/box_has_sigdrop.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading