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

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

Closed
Cldfire opened this issue Dec 31, 2020 · 1 comment · Fixed by #65
Closed

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

Cldfire opened this issue Dec 31, 2020 · 1 comment · Fixed by #65

Comments

@Cldfire
Copy link

Cldfire commented Dec 31, 2020

Minimal repro:

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct MyStruct {
    pub my_int: i32,
    pub my_bool: bool,
}

Output when running cargo clippy with Rust 1.48:

work1pass@jareks-mbp-work schemars-test % cargo clippy              
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.56
   Compiling serde_derive v1.0.118
   Compiling ryu v1.0.5
   Compiling serde v1.0.118
   Compiling serde_json v1.0.61
   Compiling schemars v0.8.0
    Checking itoa v0.4.7
    Checking dyn-clone v1.0.4
   Compiling quote v1.0.8
   Compiling serde_derive_internals v0.25.0
   Compiling schemars_derive v0.8.0
    Checking schemars-test v0.1.0 (/Users/work1pass/programming/schemars-test)
    Finished dev [unoptimized + debuginfo] target(s) in 17.08s

Output when running cargo clippy with Rust 1.49:

work1pass@jareks-mbp-work schemars-test % cargo clippy
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.56
   Compiling serde_derive v1.0.118
   Compiling ryu v1.0.5
   Compiling serde v1.0.118
   Compiling serde_json v1.0.61
    Checking itoa v0.4.7
   Compiling schemars v0.8.0
    Checking dyn-clone v1.0.4
   Compiling quote v1.0.8
   Compiling serde_derive_internals v0.25.0
   Compiling schemars_derive v0.8.0
    Checking schemars-test v0.1.0 (/Users/work1pass/programming/schemars-test)
warning: field assignment outside of initializer for an instance created with Default::default()
 --> src/lib.rs:3:57
  |
3 | #[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
  |                                                         ^^^^^^^^^^
  |
  = note: `#[warn(clippy::field_reassign_with_default)]` on by default
note: consider initializing the variable with `schemars::schema::Metadata { default: JsonSchema, ..Default::default() }` and removing relevant reassignments
 --> src/lib.rs:3:57
  |
3 | #[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
  |                                                         ^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
  = note: this warning originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: field assignment outside of initializer for an instance created with Default::default()
 --> src/lib.rs:3:57
  |
3 | #[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
  |                                                         ^^^^^^^^^^
  |
note: consider initializing the variable with `schemars::schema::Metadata { default: JsonSchema, ..Default::default() }` and removing relevant reassignments
 --> src/lib.rs:3:57
  |
3 | #[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
  |                                                         ^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
  = note: this warning originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 2 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 16.39s
@Cldfire Cldfire changed the title JsonSchema derive + #[serde(default)] triggers clippy lint in Rust 1.49 JsonSchema derive + #[serde(default)] triggers clippy lint in Rust 1.49 Dec 31, 2020
@jan-auer
Copy link
Contributor

jan-auer commented Jan 6, 2021

This has been fixed in clippy by ignoring generated code: rust-lang/rust-clippy#6553

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 a pull request may close this issue.

2 participants