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

unnecessary-struct-initialization changes code to require type annotations (which are not provided) #10548

Open
matthiaskrgr opened this issue Mar 25, 2023 · 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

@matthiaskrgr
Copy link
Member

Summary

.

Reproducer

I tried this code:

#[derive(Default)]
struct NonGeneric {
    field1: usize,
}

fn main() {
    let default1 = NonGeneric { ..Default::default() };
}

clippy suggestion:

warning: unnecessary struct building
 --> src/main.rs:9:20
  |
9 |     let default1 = NonGeneric { ..Default::default() };
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `Default::default()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_struct_initialization
```

This gets auto applied with `--fix` but it does not compile since we are lacking type annotations for `Default`

```
The following errors were reported:
error[E0282]: type annotations needed
 --> src/main.rs:9:9
  |
9 |     let _default1 = Default::default();
  |         ^^^^^^^^^
  |
help: consider giving `_default1` an explicit type
  |
9 |     let _default1: /* Type */ = Default::default();
  |                  ++++++++++++

error: aborting due to previous error
```

### Version

```text
rustc 1.70.0-nightly (8be3c2bda 2023-03-24)
binary: rustc
commit-hash: 8be3c2bda6b683f87b24714ba595e8b04faef54c
commit-date: 2023-03-24
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7
```


### Additional Labels

_No response_
@matthiaskrgr matthiaskrgr added 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 labels Mar 25, 2023
bors added a commit that referenced this issue Mar 27, 2023
…rsery, r=flip1995

Move unnecessary_struct_initialization to nursery

changelog: none, assuming it makes into the same release as #10489

Mostly because of #10547 but there is also #10548
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

1 participant