Skip to content

Commit 77f8229

Browse files
Don't eagerly monomorphize drop for types that are impossible to instantiate
1 parent 213ad10 commit 77f8229

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 9 additions & 0 deletions
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
}

tests/ui/codegen/mono-impossible.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
// Make sure that we don't monomorphize the impossible method `<() as Visit>::visit`,
55
// which does not hold under a reveal-all param env.
6-
76
pub trait Visit {
87
fn visit() {}
98
}
10-
119
pub trait Array<'a> {}
12-
1310
impl Visit for () where (): for<'a> Array<'a> {}
11+
12+
// Make sure we don't monomorphize the drop impl for `Baz`, since it has predicates
13+
// that don't hold under a reveal-all param env.
14+
trait Foo {
15+
type Assoc;
16+
}
17+
struct Bar;
18+
pub struct Baz(<Bar as Foo>::Assoc)
19+
where
20+
Bar: Foo;

0 commit comments

Comments
 (0)