Skip to content

Commit

Permalink
Don't eagerly monomorphize drop for types that are impossible to inst…
Browse files Browse the repository at this point in the history
…antiate
  • Loading branch information
compiler-errors committed May 24, 2024
1 parent 213ad10 commit 77f8229
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,15 @@ impl<'v> RootCollector<'_, 'v> {
{
debug!("RootCollector: ADT drop-glue for `{id:?}`",);

// This type is impossible to instantiate, so we should not try to
// generate a `drop_in_place` instance for it.
if self.tcx.instantiate_and_check_impossible_predicates((
id.owner_id.to_def_id(),
ty::List::empty(),
)) {
return;
}

let ty = self.tcx.type_of(id.owner_id.to_def_id()).no_bound_vars().unwrap();
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
}
Expand Down
13 changes: 10 additions & 3 deletions tests/ui/codegen/mono-impossible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@

// Make sure that we don't monomorphize the impossible method `<() as Visit>::visit`,
// which does not hold under a reveal-all param env.

pub trait Visit {
fn visit() {}
}

pub trait Array<'a> {}

impl Visit for () where (): for<'a> Array<'a> {}

// Make sure we don't monomorphize the drop impl for `Baz`, since it has predicates
// that don't hold under a reveal-all param env.
trait Foo {
type Assoc;
}
struct Bar;
pub struct Baz(<Bar as Foo>::Assoc)
where
Bar: Foo;

0 comments on commit 77f8229

Please sign in to comment.