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

Fix rust 2024 warning when using nserde(skip) field annotations #113

Merged

Conversation

Adjective-Object
Copy link
Contributor

@Adjective-Object Adjective-Object commented Sep 29, 2024

At present, the #nserde(skip) attribute on a struct with a derive(DeRon) annotation would cause build warnings. You can see this by running cargo test in the project.

rning: this function depends on never type fallback being `()`
   --> tests/ron.rs:138:14
    |
138 |     #[derive(DeRon, SerRon, PartialEq, Debug)]
    |              ^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
    = help: specify the types explicitly
note: in edition 2024, the requirement `!: DeRon` will fail

From looking at the expanded macros, I think this is because in the generated code, type inference relies on the assignment of the local value to its corresponding struct field to know what the value of the type binding is. Because skip() skips this and replaces the value with Default:;default(), the resulting option type is initialized to the "lowest" possible type, Option<!>.

image

I think that makes the DeSer::de_ron() call to initialize the field values fall back to the DeSer impl for (), which triggers the compiler warning. Not 100% sure about that but either way, adding type annotations makes the warning go away!

@knickish
Copy link
Collaborator

knickish commented Oct 1, 2024

Thanks for making this. Seems like it's passing all tests, so am planning to merge this after I have a chance to review it a bit more thoroughly. Did you happen to check if the same thing happens with DeJson?

@Adjective-Object
Copy link
Contributor Author

I didn't see it happen. It looks like it's because the expanded skip macro for json ends up omitting the field entirely from deserialization when #[nserde(skip]) is set.

image

I believe the difference between json and ron here is because there's no whole_field equivalent for ron, so the parser has to parse skipped fields in order advance the parser state.

@knickish knickish merged commit 938fcf8 into not-fl3:master Oct 7, 2024
16 checks passed
@knickish
Copy link
Collaborator

knickish commented Oct 7, 2024

Thanks for doing this!

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

Successfully merging this pull request may close these issues.

2 participants