-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
Summary
I have an HtmlBuilder type that can only be constructed via a macro (html!). It achieves this by marking its new method as #[doc(hidden)].
Implementing Default would defeat the purpose of the #[doc(hidden)], as users could bypass the intended macro API.
Lint Name
new-without-default
Reproducer
I tried this code:
pub struct Homura;
impl Homura {
#[doc(hidden)]
pub fn new() -> Self { Homura }
}I saw this happen:
warning: you should consider adding a `Default` implementation for `Homura`
--> src/lib.rs:5:5
|
5 | pub fn new() -> Self { Homura }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(clippy::new_without_default)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try adding this
|
3 + impl Default for Homura {
4 + fn default() -> Self {
5 + Self::new()
6 + }
7 + }
|
I expected to see this happen:
(no warnings)
Version
clippy 0.1.59 (e100ec5 2021-12-21)
rustc 1.59.0-nightly (e100ec5bc 2021-12-21)
binary: rustc
commit-hash: e100ec5bc7cd768ec17d75448b29c9ab4a39272b
commit-date: 2021-12-21
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy