Description
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 theT
inVec<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.
impl<T> Foreign<Local> for Foreign<T, Foreign>
-- re-rebalance-coherence.rs, re-rebalance-coherence-rpass.rs (these appear to be duplicate tests)impl<T> Foreign for Foreign<T, Local<T>>
-- coherence-cow.rs, coherence-cow.rsimpl<T,U> Foreign for Foreign<T, Local<U>>
-- coherence-cow.rs, coherence-pair-covered-uncovered.rsimpl<T> Foreign<Local> for T
-- coherence-bigint-param.rsimpl Foreign for Local<T>
-- coherence-covered-type-parameter.rs, coherence-iterator-vec.rsimpl<T> Foreign<T> for Foreign
-- coherence-all-remote.rsimpl Foreign<Local> for Foreign
-- coherence-bigint-int.rs, coherence-bigint-vecint.rsimpl<T> Foreign for T
-- coherence-cross-crate-conflict.rs, coherence-lone-type-parameter.rsimpl Foreign for Foreign<Local>
-- coherence-vec-local.rsimpl<T> Foreign<Foreign<T>, Local> for Foreign<T>
-- in add new tests for re_rebalance_coherence #64414impl<T> Foreign<Local> for Fundamental<T>
-- in add new tests for re_rebalance_coherence #64414
Missing items
- Open PR against the reference, updating documentation
- Fix
re_rebalance_coherence
doesn't properly account for fundamental types #64412 - Add more tests for fundamental patterns -- we did not by any means tile the space