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

FP: default_constructed_unit_structs #10755

Closed
matthiaskrgr opened this issue May 6, 2023 · 0 comments · Fixed by #10813
Closed

FP: default_constructed_unit_structs #10755

matthiaskrgr opened this issue May 6, 2023 · 0 comments · Fixed by #10813
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

default_constructed_unit_structs

Reproducer

I tried this code:

struct Sqlite {}

trait HasArguments<'q> {
    type Arguments;
}

impl<'q> HasArguments<'q> for Sqlite {
    type Arguments = std::marker::PhantomData<&'q ()>;
}

fn foo() {
    let _ = <Sqlite as HasArguments>::Arguments::default();
}

fn main() {}

I saw this happen:

warning: use of `default` to create a unit struct
  --> elided-lifetime-in-path-in-type-relative-expression.rs:12:48
   |
12 |     let _ = <Sqlite as HasArguments>::Arguments::default();
   |                                                ^^^^^^^^^^^ help: remove this call to `default`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
   = note: requested on the command line with `-W clippy::default-constructed-unit-structs`

warning: 2 warnings emitted

The suggestion does not compile

error[E0575]: expected method or associated constant, found associated type `HasArguments::Arguments`
  --> elided-lifetime-in-path-in-type-relative-expression.rs:12:13
   |
12 |     let _ = <Sqlite as HasArguments>::Arguments;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: can't use a type alias as a constructor

error: aborting due to previous error

Version

rustc 1.71.0-nightly (6d140d59b 2023-05-06)
binary: rustc
commit-hash: 6d140d59bb957903b02ddb993450509d8d92b448
commit-date: 2023-05-06
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

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 I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 6, 2023
@bors bors closed this as completed in f1fd467 May 26, 2023
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant