-
Notifications
You must be signed in to change notification settings - Fork 4
derive_where attribute macro instead of derive macro #33
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
Conversation
Lol, after all this talk on how to do this, it looks ingenius to me. Looking forward to see how this plays out. |
The only problem seams to be that prior to
Only way around this is removing the import for the derive_where macro and calling it like so: #[derive_where::derive_where(Clone; T::Type)]
struct Test<T: Trait>(T::Type); This can be somewhat circumvented by using an internal replacement: So pre use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[derive_where(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[derive_where(default)]
A {
a: Wrapper<T>,
},
B(Wrapper<T>),
C,
} But since use derive_where::derive_where;
#[derive_where(Clone, Copy, Debug)]
#[derive_where(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[derive_where(default)]
A {
a: Wrapper<T>,
},
B(Wrapper<T>),
C,
} |
I'm starting to remember what the issues were, how are we going to resolve multiple calls and paths? use derive_where::derive_where as blubb;
#[blubb(Clone, Copy, Debug)]
#[blubb(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct Test<T: Trait>(T::Type); |
I would rather have to do
and if I only need one be able to do:
than always have the we can make this a feature that can be opt-out/opt-in, if there is no way around this limitation. another problem is, that in this case the first invocation would fail on the #[dw_macro(Clone, Copy, Debug)]
#[dw_macro(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[derive_where(default)]
A,
B(PhantomData<T>),
} But with the internal_derive I can fix multiple #[dw_macro(Clone, Copy)]
#[dw_macro(Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive_where(Debug)]
enum Test<T> {
A {
a: Wrapper<T>,
},
B(Wrapper<T>),
C,
} But this would have a msrv of use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[dw_macro(Eq, Hash, Ord, PartialEq, PartialOrd)] as prior you will get
TLDRWe can support prior use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[derive_where(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[derive_where(default)]
A,
B(Wrapper<T>),
} We can support prior use derive_where::derive_where;
#[derive_where(Clone, Copy, Debug)]
#[derive_where(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[derive_where(default)]
A,
B(Wrapper<T>),
} With current Rust, we can support: use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[dw_macro(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[derive_where(default)]
A,
B(Wrapper<T>),
} But probably neither: use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[dw_macro(, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive_where(Default)]
enum Test<T> {
#[derive_where(default)]
A,
B(Wrapper<T>),
} nor: use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[dw_macro(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[dw_macro(default)]
A,
B(Wrapper<T>),
} |
Ok maybe we can do in current rust use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[dw_macro(, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive_where(Default)]
enum Test<T> {
#[derive_where(default)]
A,
B(Wrapper<T>),
} The idea would be to replace all #[derive(DeriveWhere)]
#[__derive_where_internal_derive_attr] |
If rust-lang/rust#53012 is fixed, we could also do this: use derive_where::derive_where as dw_macro;
#[dw_macro(Clone, Copy, Debug)]
#[dw_macro(Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Test<T> {
#[dw_macro(default)]
A,
B(Wrapper<T>),
} All we need to do is have the attribute macro expand to |
Oh and we would need to throw out all the sanity checks like dont have I could live with that, but this is a nice feature we would loose this way. (Don't think this would be a breaking change tho as only some errors will get removed) |
As sanity checks only need to be disabled if someone renames |
As the usage of the attribute is pretty seamless (as far as I can tell) in up-to-date rust versions, we can make this the normal (maybe even only) way of using |
168fa51
to
e06a40d
Compare
e06a40d
to
51a37b9
Compare
cfc92e3
to
e342c42
Compare
7823762
to
589f6b9
Compare
589f6b9
to
36913ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. https://github.com/ModProg/derive-where/pull/33/files#r780831274 is the only thing really left to do, the rest are nits.
Co-authored-by: daxpedda <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine now, hopefully
we should document the restriction conserning renaming, and maybe run a test how useful the error message in such a case will be. |
And like I said test what happens if put the attribute_macro on a non struct/enum/unit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The span issue is the only thing remaining.
we should document the restriction conserning renaming, and maybe run a test how useful the error message in such a case will be.
And like I said test what happens if put the attribute_macro on a non struct/enum/unit.
We could also do these in a separate PR, however you prefer.
Feel free to merge or handle these last two points in this PR. |
closes #27