Closed
Description
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