-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Tracking issue for rustc_reservation_impl attribute #64631
Copy link
Copy link
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.Internal rustc attributes gated on the `#[rustc_attrs]` feature gate.S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.Status: The feature will stay unstable indefinitely.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.Internal rustc attributes gated on the `#[rustc_attrs]` feature gate.S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.Status: The feature will stay unstable indefinitely.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Background
The
#[rustc_reservation_impl]attribute was added as part of the effort to stabilize!. Its goal is to make it possible to add aimpl<T> From<!> for Timpl in the future by disallowing downstream crates to do negative reasoning that might conflict with that.Warning: the effect of this attribute is quite subtle, and it should be used with caution! In particular, adding a "reservation impl" alone does not guarantee that one can add the impl in the future, as described below.
History
impl<T> From<!> for T#62661Current blockers before this attribute can be used to affect end-users
Usage
You can use the
#[rustc_reservation_impl]attribute as follows:For the most part, rustc will act as though this impl does not exist. For example, users can add overlapping impls if they prefer:
Note that this implies that the
#[rustc_reservation_impl]attribute alone does not guarantee that you can add the reservation impl in a future compatible way. Adding the reserved impl in the future may still cause coherence overlap (e.g., the impl forLocalType<T>for the impl for allTwould overlap here). This will typically result in errors.In order to add the impl, you must be able to ensure that coherence will allow the overlapping impls. This can be done in two ways, both of which are presently unstable:
LocalType2example above, since neither impl is a subset of one another.From, but we could grow this definition.What does the attribute do?
The attribute prevents negative reasoning. In particular, it forbids impls like this:
Without the reservation impl, this would be legal, because the crate may assume that
LocalType: From<!>does not hold (sinceLocalTypeis local to the crate). With the reservation impl, however, code like this will get an error.