Skip to content

Tracking issue for dyn upcasting coercion #65991

Description

@alexreg

This is a tracking issue for RFC3324. Corresponding MCP is here.
The feature gate for the issue is #![feature(trait_upcasting)].

STATUS UPDATE

Stabilized in Rust 1.86 via #134367.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Previous discussions

Unresolved Questions

  • Currently CoerceUnsized trait cannot express this case: a smart pointers that wrap a raw pointer and don't guarantee via a custom invariant that it is valid. Maybe a separate CoerceUnsizedUnsafe trait is needed. (see Trait upcasting coercion (part4) #88010 (comment)).
  • Should we make upcasting opt-in in some form to limit vtable size by default? The current inclination of the lang-team is "no", but it would be useful to gather data on how much supporting upcasting contributors to overall binary size.
  • Before stabilizing it we should check that libs-api is ok with upcasting for all dyn-allowed traits in the library, since those we can't change. (addressed by Tracking issue for dyn upcasting coercion #65991 (comment))
  • Should we add an opt-out mechanism, and extend library stabilization checklist with "do we want to opt-out for now"?

Implementation history

Activity

  1. added a commit that references this issue on Jun 16, 2021
  2. added a commit that references this issue on Jul 7, 2021
  3. changed the title [-]Tracking issue for trait upcasting[/-] [+]Tracking issue for trait upcasting coercion[/+] on Jul 8, 2021
  4. nikomatsakis commented on Dec 13, 2021

    @nikomatsakis
    Contributor

    This is currently blocked on resolving the safety conditions for upcasting. The following updated document describes my current thinking, looking for feedback:

    https://rust-lang.github.io/dyn-upcasting-coercion-initiative/design-discussions/upcast-safety-2.html

  5. dimpolo commented on Feb 4, 2022

    @dimpolo
    Contributor

    I was playing around with this and discovered that the feature gate (and its incomplete_features warning) can be bypassed using #![feature(unsize)] instead.

    This will upcast a &dyn Bar where Foo is a supertrait of Bar.

    fn upcast<Dyn: ?Sized + Unsize<dyn Foo>>(bar: &Dyn) -> &dyn Foo { bar }

    Playground

    Would this mean the unsize feature should be incomplete as well?

  6. danielhenrymantilla commented on Feb 11, 2022

    @danielhenrymantilla
    Contributor

    Came to comment the same observation that @dimpolo has made: I think the impl of Unsize<dyn '_ + Super> for dyn '_ + Sub ought, itself, to be feature-gated by trait_upcasting.

  7. nikomatsakis commented on Feb 14, 2022

    @nikomatsakis
    Contributor

    That makes sense, although really I just want to stabilize this.

  8. Mark-Simulacrum commented on Jul 27, 2022

    @Mark-Simulacrum
    Member

    cc #89460, which is tracking a future-compat lint that seems related to this feature.

  9. changed the title [-]Tracking issue for trait upcasting coercion[/-] [+]Tracking issue for dyn upcasting coercion[/+] on Jul 28, 2022
  10. pnkfelix commented on Aug 4, 2022

    @pnkfelix
    Contributor

    @joshtriplett can you confirm that when you added the S-waiting-on-team label, that was a reference to T-lang, and not T-compiler?

  11. pnkfelix commented on Aug 18, 2022

    @pnkfelix
    Contributor

    @rustbot label: I-lang-nominated

    I am seeking an answer to the question, requoted here:

    @joshtriplett can you confirm that when you added the S-waiting-on-team label, that was a reference to T-lang, and not T-compiler?

  12. 124 remaining items

  13. added a commit that references this issue on Feb 10, 2025
  14. added a commit that references this issue on Mar 11, 2025
    faf1fa5
  15. added
    relnotesMarks issues that should be documented in the release notes of the next release.
    on Mar 21, 2025
  16. added a commit that references this issue on May 27, 2025
  17. added a commit that references this issue on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-trait_upcasting`#![feature(trait_upcasting)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.relnotesMarks issues that should be documented in the release notes of the next release.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions