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 lint gives false positives because it doesn't consider if all fields are public #6515

Closed
sdroege opened this issue Dec 29, 2020 · 5 comments
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

@sdroege
Copy link

sdroege commented Dec 29, 2020

Lint name: field-reassign-with-default

I tried this code:

let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string();

I expected to see this happen: No warning because

let pretty_config = ron::ser::PrettyConfig {
    new_line: "".to_string(),
    ..Default::default()
};

Doesn't compile:

error[E0451]: field `_future_proof` of struct `ron::ser::PrettyConfig` is private
   --> test.rs:18:15
    |
 18 |             ..Default::default()
    |               ^^^^^^^^^^^^^^^^^^ field `_future_proof` is private

Instead, this happened: I got a warning:

error: field assignment outside of initializer for an instance created with Default::default()
   --> test.rs:17:9
    |
 17 |         pretty_config.new_line = "".to_string();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
note: consider initializing the variable with `ron::ser::PrettyConfig { new_line: "".to_string(), ..Default::default() }` and removing relevant reassignments

Meta

  • cargo clippy -V: clippy 0.0.212 (e1884a8 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-unknown-linux-gnu
release: 1.49.0
@sdroege sdroege 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 29, 2020
@xFrednet
Copy link
Member

This is a duplicate of #6344. The fix has been merged two days ago in #6375 🙃

@sdroege
Copy link
Author

sdroege commented Dec 30, 2020

I guess that's too late for 1.49? :)

@xFrednet
Copy link
Member

Looking at the change log draft it actually seams like it will be in 1.51. The PR sadly got merged after the 1.50 cut of point if I understood it correctly 🙃

@sdroege
Copy link
Author

sdroege commented Dec 31, 2020

No problem, I'll just disable the lint until 1.51 problem then :)

@flip1995
Copy link
Member

flip1995 commented Jan 2, 2021

Closing because it is fixed. I will create a beta backport, so the fix will get into 1.50.

bors added a commit that referenced this issue Jan 3, 2021
[beta] Backport of #6375 - field_reassign_with_default fix

With the pinned nightly we can test backports to our beta branch now 🎉

cc #6515

changelog: beta 1.50: Backport of private fields fix in [`field_reassign_with_default`] lints
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

3 participants