Skip to content

Stabilize RFC 2451, re-rebalance coherence #63599

Closed
@nikomatsakis

Description

@nikomatsakis

Stabilization Proposal

I am writing to propose we stabilize the implementation of RFC 2451, "re-rebalancing coherence" (tracking issue).

Brief Summary

The RFC modifies the coherence rules. It used to be that, when implementing a non-local trait, if Ti was the first "local type", then all type parameters were forbidden before that point. In practice, that meant that this impl was illegal:

struct Local;

impl<T> Foreign<Local> for Vec<T> { }
//              ^^^^^          ^
//              |              type parameter
//              first local type

The RFC lightly generalizes these rules. In particular, type parameters are now allowed before Ti, but only if they are covered, defined in the RFC as:

Covered Type: A type which appears as a parameter to another type. For example, T is uncovered, but the T in Vec<T> is covered. This is only relevant for type parameters.

This means that the impl above is now legal, because the typeT is covered by Vec. Note that an impl like the following would still be illegal:

struct Local;

impl<T> Foreign<Local> for T { }
//              ^^^^^      ^
//              |          type parameter (uncovered)
//              first local type

It is considered a (semver) breaking change for parent crates to add impls with uncovered type parameters (this was already the case even with the old rules, I believe). Therefore, this generalization of the rules cannot permit a conflict between the parent crate and a child crate. (See RFC for a more detailed argument.)

(NB: I've elided details of #[fundamental] in this summary, see the RFC for full details.)

Changes since the RFC was approved

None

Test cases

This section describes the patterns covered by new tests added for this RFC, or tests that seemed relevant to this RFC, with links to the test files.

Missing items

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-re_rebalance_coherence`#![feature(re_rebalance_coherence)]`T-langRelevant to the language 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