Skip to content

Commit 3e0db6a

Browse files
committed
Work around opaque types hiding needs_drop
When building the MIR we sometimes try to unschedule drops. In this we assert that the drop has already been scheduled. Opaque types however may be initialized with an expression kind that we know doesn't have a type that needs to be dropped. To fix this we don't panic if we can't find the drop of a variable with an opaque type.
1 parent 8b4edef commit 3e0db6a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

compiler/rustc_mir_build/src/build/scope.rs

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ use rustc_index::{IndexSlice, IndexVec};
9090
use rustc_middle::middle::region;
9191
use rustc_middle::mir::*;
9292
use rustc_middle::thir::{ExprId, LintLevel};
93+
use rustc_middle::ty::TypeVisitableExt;
9394
use rustc_middle::{bug, span_bug};
9495
use rustc_session::lint::Level;
9596
use rustc_span::{Span, DUMMY_SP};
@@ -1141,6 +1142,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11411142
{
11421143
return;
11431144
}
1145+
// Opaque type may not have been scheduled if its underlying
1146+
// type does not need drop.
1147+
None if self.local_decls[local].ty.has_opaque_types() => return,
11441148
_ => bug!(
11451149
"found wrong drop, expected value drop of {:?}, found {:?}",
11461150
local,
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ check-pass
2+
3+
fn if_else(c: bool) -> impl Sized {
4+
if c { () } else { () }
5+
}
6+
7+
fn if_no_else(c: bool) -> impl Sized {
8+
if c {}
9+
}
10+
11+
fn matches(c: bool) -> impl Sized {
12+
match c {
13+
true => (),
14+
_ => (),
15+
}
16+
}
17+
18+
fn tuple_tuple(c: bool) -> (impl Sized,) {
19+
if c { ((),) } else { ((),) }
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)