diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-25 12:54:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-25 12:54:36 +0200 |
| commit | 3fc8fe0490557fa8c8cf4827943d0a75db59fd0d (patch) | |
| tree | f9059f20863df652e6101f407224d79b322d32e8 | |
| parent | 00c51bda3f02275f9d3a7747f82d45ab5af63e7b (diff) | |
| parent | 045f448e26257c7b19bf6d68c8e5e9d09ab4df79 (diff) | |
| download | rust-3fc8fe0490557fa8c8cf4827943d0a75db59fd0d.tar.gz rust-3fc8fe0490557fa8c8cf4827943d0a75db59fd0d.zip | |
Rollup merge of #125513 - compiler-errors:impossible-drop, r=jackh726
Don't eagerly monomorphize drop for types that are impossible to instantiate Self-explanatory title I think Fixes #125509
| -rw-r--r-- | compiler/rustc_monomorphize/src/collector.rs | 9 | ||||
| -rw-r--r-- | tests/ui/codegen/mono-impossible-drop.rs | 18 |
2 files changed, 27 insertions, 0 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 76972ff2263..9487692662b 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -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); } diff --git a/tests/ui/codegen/mono-impossible-drop.rs b/tests/ui/codegen/mono-impossible-drop.rs new file mode 100644 index 00000000000..dec013cfe54 --- /dev/null +++ b/tests/ui/codegen/mono-impossible-drop.rs @@ -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; |
