Skip to content
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

#[optfield(attrs)] critically (and unexpectedly) depends on attribute ordering #4

Closed
cyqsimon opened this issue May 12, 2023 · 4 comments

Comments

@cyqsimon
Copy link
Contributor

First of all, thanks for your amazing work on this crate. It made my work a hell lot easier.

Currently, #[optfield(attrs)] only works on attributes declared after it. The ones before it are not picked up. This behaviour is confusing and is not mentioned anywhere in the documentation (I think).


Example:

fn main() {
    let bar0 = Bar::default(); // works
    let bar1 = bar0.clone(); // errors
}

#[derive(Clone)]
#[optfield(Bar, attrs)]
#[derive(Default)]
struct Foo {
    foo: u8,
}

Moreover, it is extremely rare for attribute order to be important in the entire Rust ecosystem, so I guess it's fair to say that this behaviour is not very idiomatic. I think it would be ideal if this is not the case, but if there are technical limitations that prevent a fix, this idiosyncrasy should at be noted in the documentation.

@cyqsimon
Copy link
Contributor Author

$ rustc --version
rustc 1.69.0 (84c898d65 2023-04-16)
$ uname -msr
Linux 6.3.1-arch2-1 x86_64

@roignpar
Copy link
Owner

Thanks for pointing this out!
I'm happy to hear that you found optfield useful.
I haven't touched it in quite some time. I now ran into some difficulties while updating the github actions, but will look into this issue after those are solved.

@roignpar
Copy link
Owner

@cyqsimon apparently it's a Rust thing: rust-lang/rust#111589 (comment)
I'm going to make a new release and will add this detail to documentation.

@roignpar
Copy link
Owner

Added to documentation at end of Attributes section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants