Skip virtual dispatches when collecting default impl mono items#158822
Skip virtual dispatches when collecting default impl mono items#158822peterphitran wants to merge 2 commits into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
This PR changes a file inside |
|
☔ The latest upstream changes (presumably #159407) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
Fixes #158411.
Problem
Under eager mono item collection (
-Clink-dead-code),create_mono_items_for_default_implswalks a trait's provided methods for each impl. When a trait is implemented for (something that
normalizes to) its own trait object type, e.g.
impl Trait for dyn Traitspelled through alazy_type_aliasor an associated type projection, resolving a provided method with the traitobject as the
Selftype yields anInstanceKind::Virtualrather than a concreteItem.That virtual dispatch was pushed as a mono item and later fed to
instance_mir, which bugs:These impls are accepted by coherence (only the syntactic
impl Trait for dyn Traitis rejectedwith E0371; the alias and projection forms are allowed, and are relied upon by the run-pass test
tests/ui/traits/object/ambiguity-vtable-segfault.rs), so the program should compile.Fix
Skip the item when the resolved instance is a virtual dispatch. A virtual dispatch has no
standalone MIR body to codegen, so there is nothing to collect. This mirrors the normal
use-collection path
visit_instance_use, which already skipsVirtual/Intrinsicinstances.Tests
tests/ui/codegen/mono-item-collector-dyn-self-default-impl.rs, abuild-passtest compiled with-Clink-dead-code, covering:lazy_type_aliasself type (the original report),dyn Qux + Send).