作者:老娘要做泼妇i | 来源:互联网 | 2023-08-29 11:10
Playground:
1 2 3 4 5 6 7 8 9 10 11 12 13
| rust
pub struct Foo {
pub x: *const i32,
}
impl Foo {
#[cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
pub fn new() -> Self {
Self {
x: std::ptr::null(),
}
}
} |
produces
1 2 3 4 5 6 7 8 9 10 11 12 13
| warning: you should consider adding a `Default` implementation for `Foo`
--> src/main.rs:9:5
|
9 | / pub fn new() -> Self {
10 | | Self {
11 | | x: std::ptr::null(),
12 | | }
13 | | }
| |_____^
|
= note: #[warn(clippy::new_without_default)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#new_without_default
help: try this [...] |
该提问来源于开源项目:rust-lang/rust-clippy
That is a good point!