-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
__UnpinStruct
is restricting the pinned field.
#102
Comments
This logic is current. |
This error is because the
Lines 93 to 95 in 1b0e552
However, perhaps we can provide an option to support this. (Add the (FYI: I found this problem about two weeks ago and added two tests.)
|
Actually, the full error message tells that the problem is because of rust-lang/rust#48214 This reduce the utility of this macro if it can only be done for generic types. Maybe the pin_project macro should add a |
I'm not sure about how does this resolve the problem - Could you explain in a little more detail? |
Because having a generic in the structure work around the issue 48214. I don't understand how to use
|
Oops, sorry, my comment is wrong. It doesn't work. |
This comment has been minimized.
This comment has been minimized.
@taiki-e your |
Oh... you are right. |
This worked well in 0.3, so I think it should actually be considered a regression. |
Perhaps a realistic solution would be to add a new @Aaron1011 Any thoughts? |
How about But yes, the documentation should maybe recommend the trick to add a (useless) generic parameter so it compiles.
It also work with a generic lifetime
And the compilation error can be hinting about this. The macro can detect that there is no generic argument and have its own error, or rename the field |
Can
|
For clarity: |
Depends what code the macro generates. But if you use the Span from the unsafe keyword, it will be reported as a waring/error there.
It is a problem related to not having generic. (rust issue 48214) If the struct have generics, everything works fine. |
Oh, you are right, I confirmed locally. I didn't understand about this feature properly... sorry.
This seems to work well, thanks. (If this is actually adopted, it seems necessary to propagate |
(In fact, many of my comments on this issue seem wrong... sorry for that.) |
|
I think I found a way to fix this: playground |
Filed #107 |
Nice! I also found another way to error out if Unpin is implemented #![allow(dead_code)]
use core::marker::{PhantomPinned};
mod pin_project {
pub trait ThouShalltNotImlementUnpin {
fn test(&self) {}
}
impl<T : Unpin> ThouShalltNotImlementUnpin for T {}
pub trait Xx {
fn test(&self) {}
}
impl<T> Xx for T {}
}
struct Foo {
// #[pin]
x: PhantomPinned,
}
fn test(f : &Foo) {
#[allow(unused_imports)]
use pin_project::ThouShalltNotImlementUnpin;
use pin_project::Xx;
f.test();
}
//impl Unpin for Foo {} // this would error |
I wonder if https://docs.rs/static_assertions/0.3/static_assertions/macro.assert_not_impl_any.html might be something to look into. |
@ogoffart @jonhoo |
I've filed #108 to investigate how to guarantee negative implementation. |
Good catch! |
Cool! But it still doesn't seem to work well with generics and conditional implementations. |
By the way, it seems If we can support this without |
Published 0.4.1 which fixes this issue completely. |
Reading this thread here I am mostly left confused. Given all the corrections I do not seem to be the only one. ;) Is there a write-up somewhere of the solution you ended up with, how it works and what it relies on from rustc? |
@RalfJung The actual fix is different from what was mainly discussed in this thread because I misunderstood a lot about this error (RFC 2056, rust-lang/rust#48214). Sorry for the confusion. A short explanation is in #107, but... This error occurs when the where clause has an Unpin bound that satisfies the following requirements:
For example, this code gives an error ( pin-project/tests/ui/unstable-features/trivial_bounds-feature-gate.rs Lines 10 to 16 in 4803d04
This can be avoided by adding a lifetime to the Wrapper in the previous example. pin-project/tests/ui/unstable-features/trivial_bounds-feature-gate.rs Lines 18 to 24 in 4803d04
As Wrapper implements Unpin regardless of a lifetime and the lifetime used in the wrapper does not overlap with the lifetime used in #107 and #111 used this way to avoid the restriction. i.e., they added a lifetime to the wrapper (and added some related tests). (Note: Since #53, pin-project implements Unpin via wrappers in all cases, so there hasn't been a big change in the way to generat Unpin implementation.) |
Okay, so it's basically a weird hack to hack around a weird rule in the trait system. Thanks. The number of hacks that keep piling up in this crate is quite impressive... and worrying. |
Unless I misunderstand something, it seems the logic to put the field in __UnpinStruct is reversed, as it checks that the #[pin]'ed field are Unpin.
For example:
Result in this error:
__UnpinStruct constraints all the pin'ed types. But I believe it should be the opposite, only the types that are not pinned should satisfy Unpin.
The text was updated successfully, but these errors were encountered: