-
Notifications
You must be signed in to change notification settings - Fork 13.4k
When subtyping can switch out trait impls, Pin::new
’s check for Target: Unpin
becomes insufficient
#134407
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Pin::new
’s check for Target = Unpin
becomes insufficientPin::new
’s check for Target: Unpin
becomes insufficient
lol |
A bit more on this.
@rustbot label +regression-from-stable-to-beta |
It's highly likely that this warning will never get moved to a hard error and be allowed instead. I therefore do not consider this to be a regression |
This comment has been minimized.
This comment has been minimized.
While also requiring You could have That can only cause unsoundness if I do really like this idea though 😁 been thinking of "add a I agree that the temporary? fix uses specialization in an acceptable and sound way |
I have another snippet which pushed things further to cover this " I have thus hidden my previous post (too large for a currently unviable solution), but if rustc were to develop the ability to force/override the variance of a type, then it might be worth revisiting it. |
@danielhenrymantilla What issue involving "any user type wrapping" are you talking about? This seems to work fine. https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=bbf50ce4d24a72448b78b214f47e7085 |
a type wrapping struct Foo<T>(Pin<T>);
fn foo<'a>(x: Foo<Pin<(&'static i32, PhantomPinned)>>) -> Foo<Pin<(&'a i32, PhantomPinned)>> {
x
} |
What is the long-term plan here -- to fix traits/subtyping such that coherence actually becomes useful to unsafe code, or to tell unsafe code authors that this kind of reasoning it not sound? |
Why do higher-ranked function pointers have subtyping anyway? And how much code relies on that? |
Pin::new
’s check for Target: Unpin
becomes insufficientPin::new
’s check for Target: Unpin
becomes insufficient
Perhaps the existence of this issue suggests that this “highly likely” outcome should in fact be reconsidered, and that the reduction in scope of |
Doing so would be feasible by adding a flag to I am confident that fully removing the leak check won't happen, given that the fallout of slightly (depending on perspective) weakening it in #119820 ended up getting reverted again due to its impact. Only disabling it in coherence (or only doing it when for binders from types or sth) ends up giving u different types for which u can't write separate impls. It pretty much results in higher ranked function pointers never being able to implement user defined traits. |
Below,
Marker1
is a subtype ofMarker2
; this means we can also coercePin<CustomType<Marker1>>
toPin<CustomType<Marker2>>
for any covariantCustomType
. If we now write differentDeref
implementations forCustomType
forMarker1
vs.Marker2
, then we can switch out theTarget
underneath aPin
, breakingPin::new
’s soundness.This does run into the
coherence_leak_check
warning easily, though as far as I understand that warning is supposed to go away eventually, and already was weakened recently [the below code doesn’t hit any warning at all anymore, since 1.84].(playground)
Unlike #85099, this one has nothing to do with unsizing.
@rustbot label A-pin, I-unsound, T-types, T-libs-api
(I’m roughly guessing appropriate
T-…
labels; feel free to adjust these, like e.g. ifT-compiler
seems relevant)The text was updated successfully, but these errors were encountered: