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
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 [...]
You have to add the#[cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))] to the impl, not the new function. Did this work before?
I think this is expected behavior, so I'm closing this issue. If you think this is unexpected, feel free to reopen.
Adding the attribute to the function should raise a warning / error then.
Also, the error message for new_without_default points to the new method, but if the attribute should be applied to the impl, shouldn't it point to the impl ? or at least suggest adding the allow on the impl instead of the method ?
As in, the error message pointed to the new method, so I assumed the allow belonged there, and nothing suggested otherwise. When it did not work, I assumed that the allow was broken.
The bug here is that I should have "somehow" know that the allow belongs to the impl, but no information in the whole process tells me that.
That is a good point!
Most helpful comment
Adding the attribute to the function should raise a warning / error then.