Skip to content

Trait upcasting coercion #98

Closed
Closed
@crlf0710

Description

@crlf0710

Proposal

Summary and problem statement

  • Add the trait_upcasting feature to the language.

Motivation, use-cases, and solution sketches

  • The trait_upcasting feature adds support for trait upcasting coercion. This allows a
    trait object of type dyn Bar to be cast to a trait object of type dyn Foo
    so long as Bar: Foo.
#![feature(trait_upcasting)]

trait Foo {}

trait Bar: Foo {}

impl Foo for i32 {}

impl<T: Foo + ?Sized> Bar for T {}

let foo: &dyn Foo = &123;
let bar: &dyn Bar = foo;

Prioritization

Links and related work

Initial people involved

Also cc @alexreg and @eddyb in case they're interested.

What happens now?

This issue is part of the experimental MCP process described in RFC 2936. Once this issue is filed, a Zulip topic will be opened for discussion, and the lang-team will review open MCPs in its weekly triage meetings. You should receive feedback within a week or two.

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langdisposition-mergeThe FCP starter wants to merge (accept) thisfinal-comment-periodThe FCP has started, most (if not all) team members are in agreementmajor-changeMajor change proposalmajor-change-acceptedMajor change proposal that was acceptedto-announceNot yet announced MCP proposals

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions