-
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 reserved impl impl<T> From<!> for T
#64715
Comments
Edit: nevermind, the fix was #69448 Will this fix the problem I am having refactoring the apint crate? I am refactoring some code involving the invariant management type The reason for this is the blanket impl |
@AaronKutch this is not an end-user facing feature, so it won't really fix anything with your crate. It was intended as a way for us to stabilize |
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.
Background
This is a tracking issue for a temporary limitation related to the
From
trait and the!
type. Specifically, we wish to eventually add an impl like the following:We cannot do so now because it would overlap with existing impls. Specifically, the impl
impl<T> From<T> for T
as well as impls of the formimpl<T> From<T> for Foo<T>
, which exist for a number of smart pointer types. There are some plans for how we might add such an impl in the future, described below.What is allowed today
Currently you are permitted to add impls of
From<!>
for your own types:This is true even though such impls will overlap our planned addition: after all, we already have a number of overlapping cases to deal with.
However, you are not permitted to assume that
From<!>
is not implemented. If that double negative threw you for a loop, consider this example (which will not compile):Here, the two impls do not presently overlap. This is because
LocalType: From<!>
is not implemented. However, if we were to add theimpl<T> From<!> for T
impl that we would like to add, then these two impls would start to overlap, and your code would stop compiling. Thus we say that this program assumes thatFrom<!>
is not implemented -- because it cannot pass the coherence check unless that is the case. This is precisely the sort of case that is not currently allowed. For more information, see RFC 1023, which introduced the rules limiting negative reasoning.How might we add the reserved impl in the future?
The precise mechanism to permit us to add the
From<!> for T
impl is not yet clear. The current "plan of record" is to extend the "marker trait mechanism" to accommodate the idea of impls whose entire body consists of unreachable methods and to permit overlap.cc #64631 -- the internal rustc mechanism used to achieve this limitation
The text was updated successfully, but these errors were encountered: