mirror of
https://github.com/rust-lang/rust.git
synced 2026-07-26 17:42:22 -04:00
61d77161a5
Expose an API for polymorphic drop glue translation At my $dayjob I work on a rustc driver called [Charon](https://github.com/AeneasVerif/charon), whose main selling point is its ability to accurately represent polymorphic Rust code. In adding support for drops I ran into an issue: the code that generates drop glue shim expects monomorphized types and ICEs when used in some polymorphic contexts. Example output: ``` error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:373:13: cannot find `K/#0` in param-env: ParamEnv { caller_bounds: [ Binder { value: HostEffectPredicate { trait_ref: <T as std::marker::Destruct>, constness: Maybe }, bound_vars: [] }, Binder { value: TraitPredicate(<T as std::marker::Destruct>, polarity:Positive), bound_vars: [] }, ], } thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:373:13: ``` I recall a Zulip discussion about this but cannot find it. This PR exposes `build_drop_shim` and gives it a `TypingEnv` argument, for use in rustc drivers like mine. Disclosure: I used LLM assistance to make this very complicated PR. This consisted in me repeatedly telling it to do something simpler until I eventually cleaned it up myself. I like the test it wrote tho.