-
Notifications
You must be signed in to change notification settings - Fork 211
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
Cannot find chained trait impl in macros #6681
Comments
Maybe there's something with I'm trying to reduce the code or find simpler code to start working on fixing this. For now I found this code doesn't compiler either: trait Serialize<let N: u32> {}
pub struct MyStruct {}
impl Serialize<1> for MyStruct {}
pub struct MyGenericStruct<T> {}
trait Storage<let N: u32> {}
impl<T, let N: u32> Storage<N + N> for MyGenericStruct<T>
where
T: Serialize<N>,
{}
pub struct Foo {
my_container: MyGenericStruct<MyStruct>,
}
fn foo<T>()
where
T: Storage<2>,
{}
fn main() {
foo::<MyGenericStruct<MyStruct>>();
} It does compile if |
So it seems we have some rules in the compiler to compute the value of a numeric generic value. For example if we need to match We could add a new rule to solve @jfecher What do you think? |
@asterite I haven't investigated this issue yet but it is true that we don't perform the transformation of If the handling of |
Aim
I'm running into issues with macros when dealing with relatively involved handling of traits and structs. Sorry for the bad title, I don't really know what might be going on and that's my best guess.
Expected Behavior
Ultimately what I want to do is have some types that implement
Serialize
, put those inside generic that also implement serialize if their fields do, and then wrap all of that in a container that can reason about the serialization lenght of whatever is inside of it. I'll try to illustrate with code (the impls are left empty as they are not relevant):So far it's all quite standard. Now I'll put this inside a struct that takes a generic, and derive
Serialize
using arithmetic over generics:Lovely stuff. Now I'll define a new marker trait (because of reasons) that will be tied to the serialization length:
We expect
MyGenericStruct<MyStruct>
to implementStorage<4>
, sinceT: MyStruct
, which has a serialization length of 2. Note that in this example we're sort of reimplementing the notion thatMyGenericStruct
contains twoT
's by doingN+N
(we'll get back to this).I know want to find this 4 value via macros:
and indeed it works!
Bug
Now I want to not have to repeat the
N+N
bit from above, so I change theStorage
impl slightly:but I run into errors:
This seems wrong:
MyGenericStruct
definitely implementsStorage
as it definitely implementsSerialize
andDeserialize
as well. Maybe the issue is that this implementation is 'derived' and hinges on arithmetic with generics?I get the same behavior if I put
MyGenericStruct
on a container struct and attempt to access itsSerialize
impl:To Reproduce
Here's a file with the above, where the two failing cases are commented out (remember to uncomment the passing case):
The text was updated successfully, but these errors were encountered: