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

inconsistent_struct_constructor deletes cfgs #12524

Open
kpreid opened this issue Mar 21, 2024 · 0 comments
Open

inconsistent_struct_constructor deletes cfgs #12524

kpreid opened this issue Mar 21, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@kpreid
Copy link
Contributor

kpreid commented Mar 21, 2024

Summary

The fix for inconsistent_struct_constructor deletes fields in a struct literal that are cfged out, and deletes all the cfgs. It should preserve all cfgs, not give a suggestion in this case, or be made not MachineApplicable.

Reproducer

I tried this code:

#![warn(clippy::inconsistent_struct_constructor)]

pub struct Foo {
    a: bool,
    #[cfg(something)]
    b: bool,
    #[cfg(all())]
    c: bool,
}

impl Foo {
    pub fn new(a: bool, b: bool, c: bool) -> Self {
        Self {
            #[cfg(something)]
            b,
            #[cfg(all())]
            c,
            a,
        }
    }
}

I expected to see this happen: Suggestion of

        Self {
            a,
            #[cfg(something)]
            b,
            #[cfg(all())]
            c,
        }

or no suggestion.

Instead, this happened: Suggestion of Self { a, c }.

Version

rustc 1.77.0 (aedd173a2 2024-03-17)
binary: rustc
commit-hash: aedd173a2c086e558c2b66d3743b344f977621a7
commit-date: 2024-03-17
host: x86_64-apple-darwin
release: 1.77.0
LLVM version: 17.0.6

Also reproduces on nightly.

Additional Labels

@rustbot label +I-suggestion-causes-error

@kpreid kpreid added the C-bug Category: Clippy is not doing the correct thing label Mar 21, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Mar 21, 2024
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants