Skip to content

TAIT decision on "may define implies must define" #117861

Closed
@traviscross

Description

@traviscross

Nominating for T-lang to decide whether to adopt the following restriction for the stabilization of TAIT:

At least until the new trait solver is stabilized, any item that is allowed to define the hidden type of some opaque type must define the hidden type of that opaque type.

If adopted, we would call this the "may define implies must define" restriction.

For the purposes of this question, please set aside how we know whether an item is allowed to define the hidden type; this question is invariant to the details of that.

This restriction leaves space for the new trait solver. That solver will consider more uses of the opaque type to be defining and it will implement lazy normalization. Given this, items that may define the hidden type but do not present the potential for differences between the old and new solver that we would prefer to avoid so as to ease the stabilization of the new trait solver.

With this restriction, TAIT becomes roughly equivalent to RPIT with respect to many of the relevant challenges.

The effect of this restriction would be to reject the following code:

#![feature(type_alias_impl_trait)]

type Tait = impl Sized;
fn define() -> Tait {} // Defines the hidden type.
fn passthrough(x: Tait) -> Tait { // Allowed to define but does not.
    // ~^ ERROR Any item that may define a hidden type must define that hidden type.
    x
}

Please set aside how we know that define and passthrough are both allowed to define the hidden type of the opaque. There are many ways that could be notated, and that question is orthogonal to this restriction.

Whether or not this restriction could be lifted later is a question of what is possible under the new trait solver and of what other rules we might decide to adopt that may make this more or less possible. Adopting this restriction now does not in and of itself close the door to possibly permitting this later.

This rule was described and proposed in the 2023-11-08 T-lang Mini-TAIT design meeting (minutes): rust-lang/lang-team#233.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions