Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b68c4b8

Browse files
committedMay 25, 2024
Don't eagerly monomorphize drop for types that are impossible to instantiate
1 parent 36153f1 commit b68c4b8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎compiler/rustc_monomorphize/src/collector.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,15 @@ impl<'v> RootCollector<'_, 'v> {
14341434
{
14351435
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
14361436

1437+
// This type is impossible to instantiate, so we should not try to
1438+
// generate a `drop_in_place` instance for it.
1439+
if self.tcx.instantiate_and_check_impossible_predicates((
1440+
id.owner_id.to_def_id(),
1441+
ty::List::empty(),
1442+
)) {
1443+
return;
1444+
}
1445+
14371446
let ty = self.tcx.type_of(id.owner_id.to_def_id()).no_bound_vars().unwrap();
14381447
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
14391448
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ compile-flags: -Clink-dead-code=on --crate-type=lib
2+
//@ build-pass
3+
4+
#![feature(trivial_bounds)]
5+
6+
// Make sure we don't monomorphize the drop impl for `Baz`, since it has predicates
7+
// that don't hold under a reveal-all param env.
8+
9+
trait Foo {
10+
type Assoc;
11+
}
12+
13+
struct Bar;
14+
15+
pub struct Baz(<Bar as Foo>::Assoc)
16+
where
17+
Bar: Foo;

0 commit comments

Comments
 (0)
Failed to load comments.