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 clippy field_reassign_with_default in generated code #65

Merged
merged 1 commit into from
Mar 21, 2021

Conversation

jan-auer
Copy link
Contributor

@jan-auer jan-auer commented Dec 7, 2020

In the next stable release, clippy will ship the field_reassign_with_default lint by default. This lint is also triggered in code generated by #[derive(JsonSchema)] when building schemars::schema::Metadata. This can be avoided by constructing the type in a single expression.

Instead of generating code like this:

let mut metadata = Metadata::default();
metadata.title = Some("title".to_owned());
metadata

This PR will generate code like this:

Metadata {
	title: Some("title".to_owned()),
	..Default::default()
}

Fixes #69

@jan-auer
Copy link
Contributor Author

jan-auer commented Jan 4, 2021

This lint is now enabled in clippy::all on Rust stable 1.49.0. @GREsau could you please take a look?

I've also briefly tried to find out why clippy is warning in generated code in the first place, but haven't been able to figure out how to suppress all checks.

@GREsau
Copy link
Owner

GREsau commented Mar 21, 2021

Thanks for the PR @jan-auer, sorry for the delay in merging!

@GREsau GREsau added this to the v0.8.1 milestone Mar 21, 2021
@jan-auer jan-auer deleted the clippy-field-reassign branch March 22, 2021 13:03
@GREsau
Copy link
Owner

GREsau commented Mar 23, 2021

This is now in the latest version on crates.io - https://crates.io/crates/schemars/0.8.1

@webmaster128
Copy link
Contributor

This is now in the latest version on crates.io - https://crates.io/crates/schemars/0.8.1

Thank you! This helps for clippy versions < 1.51.0 in which the problem will be fixed as well.

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.

JsonSchema derive + #[serde(default)] triggers clippy lint in Rust 1.49
3 participants