-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for rustc_reservation_impl
attribute
#64631
Labels
A-trait-system
Area: Trait system
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
F-rustc_attrs
Internal rustc attributes gated on the `#[rustc_attrs]` feature gate.
requires-nightly
This issue requires a nightly compiler in some way.
S-tracking-perma-unstable
Status: The feature will stay unstable indefinitely.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
Comments
nikomatsakis
added
A-trait-system
Area: Trait system
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
F-rustc_attrs
Internal rustc attributes gated on the `#[rustc_attrs]` feature gate.
labels
Sep 20, 2019
This was referenced Sep 20, 2019
Centril
added
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
requires-nightly
This issue requires a nightly compiler in some way.
labels
Sep 20, 2019
5 tasks
Undin
added a commit
to intellij-rust/intellij-rust
that referenced
this issue
Nov 25, 2019
…erence Some time ago `rustc_reservation_impl` attribute was introduced to reserve some implementation and don't allow them in libraries (rust-lang/rust#64631). Such implementations don't take part in type inference but may produce duplicate item errors. Most notable (and maybe only one) impl with such attribute is `impl<T> From<!> for T`. This impl breaks type inference in some cases. These changes just make type inference ignore such `impl` items
Undin
added a commit
to intellij-rust/intellij-rust
that referenced
this issue
Nov 25, 2019
…erence Some time ago `rustc_reservation_impl` attribute was introduced to reserve some implementation (rust-lang/rust#64631). Such implementations mostly don't take part in code analysis. Most notable (and maybe only one) impl with such attribute is `impl<T> From<!> for T`. This impl breaks type inference in some cases. These changes just make type inference ignore such `impl` items
bors bot
added a commit
to intellij-rust/intellij-rust
that referenced
this issue
Nov 25, 2019
4688: TY: skip impls with `rustc_reservation_impl` attribute while type inference r=vlad20012 a=Undin Some time ago `rustc_reservation_impl` attribute was introduced to reserve some implementation (rust-lang/rust#64631). Such implementations mostly don't take part in code analysis. Most notable (and maybe only one) impl with such attribute is `impl<T> From<!> for T`. This impl breaks type inference in some cases. These changes just make type inference ignore such `impl` items Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
joshtriplett
added
the
S-tracking-perma-unstable
Status: The feature will stay unstable indefinitely.
label
Jun 22, 2022
We visited this during lang team backlog bonanza. Conclusions:
|
bors
added a commit
to rust-lang/rust-analyzer
that referenced
this issue
May 6, 2023
fix: ignore impls with `#[rustc_reservation_impl]` Fixes #12247 Fixes #14279 Currently core has two blanket impls for `From`: `impl<T> From<T> for T` and `impl<T> From<!> for T`. These are conflicting and thus chalk cannot uniquely solve `S: From<?0>` for any type `S`. The latter impl is actually a reservation impl and should not be considered during trait selection. More generally, impls attributed with perma-unstable `#[rustc_reservation_impl]` attribute should be disregarded except for coherence checks. See rust-lang/rust#64631 and rust-lang/rust#64715 for details. I chose to entirely ignore them in hir-ty because we don't do coherence checks.
2 tasks
I say we should fix whatever's preventing the blanket impl. Implementations of a method that the compiler can prove is unreachable shouldn't be able to conflict with each other -- otherwise it'd be like making |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-trait-system
Area: Trait system
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
F-rustc_attrs
Internal rustc attributes gated on the `#[rustc_attrs]` feature gate.
requires-nightly
This issue requires a nightly compiler in some way.
S-tracking-perma-unstable
Status: The feature will stay unstable indefinitely.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
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 T
impl 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 allT
would 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:
LocalType2
example 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 (sinceLocalType
is local to the crate). With the reservation impl, however, code like this will get an error.The text was updated successfully, but these errors were encountered: