Skip to content

Commit

Permalink
Work around opaque types hiding needs_drop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthewjasper committed Jun 25, 2024
1 parent 0a726b6 commit 5c356c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_mir_build/src/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::middle::region;
use rustc_middle::mir::*;
use rustc_middle::thir::{ExprId, LintLevel};
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::{bug, span_bug};
use rustc_session::lint::Level;
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -1056,6 +1057,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
{
return;
}
// Opaque type may not have been scheduled if its underlying
// type does not need drop.
None if self.local_decls[local].ty.has_opaque_types() => return,
_ => bug!(
"found wrong drop, expected value drop of {:?}, found {:?}",
local,
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/impl-trait/rpit/non-drop-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ check-pass

fn if_else(c: bool) -> impl Sized {
if c { () } else { () }
}

fn if_no_else(c: bool) -> impl Sized {
if c {}
}

fn matches(c: bool) -> impl Sized {
match c {
true => (),
_ => (),
}
}

fn tuple_tuple(c: bool) -> (impl Sized,) {
if c { ((),) } else { ((),) }
}

fn main() {}

0 comments on commit 5c356c7

Please sign in to comment.