Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -1141,6 +1142,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,

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the affected code is

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

where the opaque type gets unified with () and () does not need drop while impl Sized does? 🤔 we probably never emit drop for the return value of an if without an else block or sth?

_ => 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() {}