Rust-clippy: allow new_without_default is broken

Created on 19 Sep 2018  路  4Comments  路  Source: rust-lang/rust-clippy

Playground:

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 [...]
L-bug

Most helpful comment

Adding the attribute to the function should raise a warning / error then.

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitorenesduarte picture vitorenesduarte  路  3Comments

Robbepop picture Robbepop  路  3Comments

matthiaskrgr picture matthiaskrgr  路  3Comments

jyn514 picture jyn514  路  3Comments

Luro02 picture Luro02  路  3Comments