-
Notifications
You must be signed in to change notification settings - Fork 13k
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 derive(Debug) for a struct with a function with a reference parameter #45048
Comments
@mathstuf I think it has something to do with
What if we did this exact thing but with edit: also with |
Also, you can edit: better playground |
@anirudhb If I need to store a function which takes a reference, how does a box solve any of that? |
I was suggesting an alternative to storing functions that take references. |
A box doesn't solve any of the problems you raised, but maybe a change to |
That works if you can change the interface, but that isn't always possible (e.g., storing something like |
No, I mean that |
Heh, I think there was a race here :) . I was replying to "suggesting an alternative", not "but maybe a change to". |
Also, doesn't the macro expansions become: fnptr_impls_args! { }
fnptr_impls_args! { A }
fnptr_impls_args! { &A }
fnptr_impls_args! { &mut A }
fnptr_impls_args! { A, B }
fnptr_impls_args! { A, &B }
fnptr_impls_args! { A, &mut B }
fnptr_impls_args! { &A, B }
fnptr_impls_args! { &A, &B }
fnptr_impls_args! { &A, &mut B }
fnptr_impls_args! { &mut A, B }
fnptr_impls_args! { &mut A, &B }
fnptr_impls_args! { &mut A, &mut B } Would raw pointer versions be needed as well? This seems…unwieldy. |
Create another macro. macro_rules! fnptr_impsl_argsptr {
($($arg: ident),+) => {
fnptr_impls_args! { $($arg),+ };
fnptr_impls_args! { $(&$arg),+ };
fnptr_impls_args! { $(&mut $arg),+ };
};
() => {
fnptr_impls_args! {};
};
}
fnptr_impls_argsptr! { }
fnptr_impls_argsptr! { A }
fnptr_impls_argsptr! { A, B }
fnptr_impls_argsptr! { A, B, C }
fnptr_impls_argsptr! { A, B, C, D }
fnptr_impls_argsptr! { A, B, C, D, E }
fnptr_impls_argsptr! { A, B, C, D, E, F }
fnptr_impls_argsptr! { A, B, C, D, E, F, G }
fnptr_impls_argsptr! { A, B, C, D, E, F, G, H }
fnptr_impls_argsptr! { A, B, C, D, E, F, G, H, I }
fnptr_impls_argsptr! { A, B, C, D, E, F, G, H, I, J }
fnptr_impls_argsptr! { A, B, C, D, E, F, G, H, I, J, K }
fnptr_impls_argsptr! { A, B, C, D, E, F, G, H, I, J, K, L } |
Macros solve repetition :) |
No, that only does |
That's what my edit is for. We should look into a compiler plugin to do the enumeration. |
Sorry, github doesn't autoload edits here, so I didn't see it. |
I'm trying to think of a good way to enumerate |
That is, for a certain length of list. |
Fun fact: that's just a base-3 number with a number of digits equal to the number of parameters. Suuuuper easy to enumerate. For To be clear: 0 is I have no idea how to make a compiler plugin, or else I'd try doing this myself. |
This doesn't just affect reference types though, it affects all types with lifetimes. The issue is that So, for example, once you covered |
Blah. That increases the complexity considerably. I wonder if there shouldn't just be some compiler magic for |
Triage: This now works as expected on beta, but I don't know why. |
Thanks for the update. Seems like #55517 from discussion on the referencing issue. |
A bit late to the party now, but I'm not sure it would have been reasonable to generate over 3^12=531441 trait impls, compiler plugin or not... |
Doesn't seem to work on stable today. |
Change Fn,R1, & R2 to struct tuple types. impl Debug and PartialEq for fn types manually. see rust-lang/rust#45048 Adjust types to work with now-borrowed values. Reduce clones when available. In general, by borrowing the arguments for all builtin functions, this lets us only clone when creating a new value. This ends up being significant because previously during "table" for example, each "call" applied to the Array values cloned the value when calling the builtin fn. Now it will only clone the value when returning a Vs to the stack.
This now works on latest stable and nightly so closing it |
This fails to compile:
It does work if the parameter is a non-reference (mutable reference also fails) including pointers. I'm using rustc 1.20.0 from Fedora's packages.
The text was updated successfully, but these errors were encountered: