Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't eagerly monomorphize drop for types that are impossible to instantiate #125513

Merged
merged 1 commit into from
May 25, 2024
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
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
18 changes: 18 additions & 0 deletions tests/ui/codegen/mono-impossible-drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ compile-flags: -Clink-dead-code=on --crate-type=lib
//@ build-pass

#![feature(trivial_bounds)]
#![allow(trivial_bounds)]

// 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;

struct Baz(<Bar as Foo>::Assoc)
where
Bar: Foo;
Loading