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

field_reassign_with_default false positive with private fields #6527

Closed
djc opened this issue Dec 31, 2020 · 1 comment
Closed

field_reassign_with_default false positive with private fields #6527

djc opened this issue Dec 31, 2020 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@djc
Copy link
Contributor

djc commented Dec 31, 2020

Lint name: field_reassign_with_default

I tried this code:

    use http::uri;
    let mut parts = uri::Parts::default();
    parts.path_and_query = Some(uri::PathAndQuery::from_static(crate::DNS_QUERY_PATH));
    parts.scheme = Some(uri::Scheme::HTTPS);
    parts.authority = Some(
        uri::Authority::from_str(&name_server_name)
            .map_err(|e| ProtoError::from(format!("invalid authority: {}", e)))?,
    );

clippy diagnosed this with:

warning: field assignment outside of initializer for an instance created with Default::default()
  --> crates/https/src/request.rs:44:5
   |
44 |     parts.path_and_query = Some(uri::PathAndQuery::from_static(crate::DNS_QUERY_PATH));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::field_reassign_with_default)]` on by default
note: consider initializing the variable with `http::uri::Parts { path_and_query: Some(uri::PathAndQuery::from_static(crate::DNS_QUERY_PATH)), scheme: Some(uri::Scheme::HTTPS), authority: Some(
        uri::Authority::from_str(&name_server_name)
            .map_err(|e| ProtoError::from(format!("invalid authority: {}", e)))?,
    ), ..Default::default() }` and removing relevant reassignments
  --> crates/https/src/request.rs:43:5
   |
43 |     let mut parts = uri::Parts::default();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default

However, Parts has a private _priv field, so functional record syntax to apply Default::default() doesn't work here.

Meta

  • cargo clippy -V: clippy 0.0.212 (e1884a8e 2020-12-29)
  • rustc -Vv:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-apple-darwin
release: 1.49.0

@djc djc added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 31, 2020
@alex-700
Copy link
Contributor

duplicate of #6344 and #6515, fixed in #6375

@djc djc closed this as completed Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants