Skip to content

Commit f915d65

Browse files
committed
Merge new_without_default_derive into new_without_default
1 parent 091fd03 commit f915d65

File tree

7 files changed

+195
-183
lines changed

7 files changed

+195
-183
lines changed

clippy_lints/src/deprecated_lints.rs

+10
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,13 @@ declare_deprecated_lint! {
123123
pub UNSAFE_VECTOR_INITIALIZATION,
124124
"the replacement suggested by this lint had substantially different behavior"
125125
}
126+
127+
128+
/// **What it does:** Nothing, this lint has been deprecated.
129+
///
130+
/// **Deprecation reason:** This lint was merged with new_without_default
131+
declare_deprecated_lint! {
132+
pub NEW_WITHOUT_DEFAULT_DERIVE,
133+
style,
134+
"`fn new() -> Self` without `#[derive]`able `Default` implementation"
135+
}

clippy_lints/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
336336
"unsafe_vector_initialization",
337337
"the replacement suggested by this lint had substantially different behavior",
338338
);
339+
store.register_removed(
340+
"new_without_default_derive",
341+
"this lint has been moved into new_without_default"
342+
);
339343
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
340344

341345
reg.register_late_lint_pass(box serde_api::Serde);
@@ -701,7 +705,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
701705
neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
702706
neg_multiply::NEG_MULTIPLY,
703707
new_without_default::NEW_WITHOUT_DEFAULT,
704-
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
705708
no_effect::NO_EFFECT,
706709
no_effect::UNNECESSARY_OPERATION,
707710
non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
@@ -837,7 +840,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
837840
mut_reference::UNNECESSARY_MUT_PASSED,
838841
neg_multiply::NEG_MULTIPLY,
839842
new_without_default::NEW_WITHOUT_DEFAULT,
840-
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
841843
non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
842844
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
843845
ok_if_let::IF_LET_SOME_RESULT,

clippy_lints/src/new_without_default.rs

+31-28
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ use if_chain::if_chain;
2323
/// **What it does:** Checks for types with a `fn new() -> Self` method and no
2424
/// implementation of
2525
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
26+
///
27+
/// It detects both the case when a manual
28+
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
29+
/// implementation is required and also when it can be created with
30+
/// `#[derive(Default)]
2631
///
2732
/// **Why is this bad?** The user might expect to be able to use
2833
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) as the
@@ -53,52 +58,50 @@ use if_chain::if_chain;
5358
/// }
5459
/// }
5560
/// ```
56-
///
57-
/// You can also have `new()` call `Default::default()`.
58-
declare_clippy_lint! {
59-
pub NEW_WITHOUT_DEFAULT,
60-
style,
61-
"`fn new() -> Self` method without `Default` implementation"
62-
}
63-
64-
/// **What it does:** Checks for types with a `fn new() -> Self` method
65-
/// and no implementation of
66-
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html),
67-
/// where the `Default` can be derived by `#[derive(Default)]`.
68-
///
69-
/// **Why is this bad?** The user might expect to be able to use
70-
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) as the
71-
/// type can be constructed without arguments.
72-
///
73-
/// **Known problems:** Hopefully none.
74-
///
75-
/// **Example:**
76-
///
61+
///
62+
/// Or, if
63+
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
64+
/// can be derived by `#[derive(Default)]`:
65+
///
7766
/// ```rust
7867
/// struct Foo;
79-
///
68+
///
8069
/// impl Foo {
8170
/// fn new() -> Self {
8271
/// Foo
8372
/// }
8473
/// }
8574
/// ```
86-
///
87-
/// Just prepend `#[derive(Default)]` before the `struct` definition.
75+
///
76+
/// Instead, use:
77+
///
78+
/// ```rust
79+
/// #[derive(Default)]
80+
/// struct Foo;
81+
///
82+
/// impl Foo {
83+
/// fn new() -> Self {
84+
/// Foo
85+
/// }
86+
/// }
87+
/// ```
88+
///
89+
/// You can also have `new()` call `Default::default()`.
8890
declare_clippy_lint! {
89-
pub NEW_WITHOUT_DEFAULT_DERIVE,
91+
pub NEW_WITHOUT_DEFAULT,
9092
style,
91-
"`fn new() -> Self` without `#[derive]`able `Default` implementation"
93+
"`fn new() -> Self` method without `Default` implementation"
9294
}
9395

96+
9497
#[derive(Clone, Default)]
9598
pub struct NewWithoutDefault {
9699
impling_types: Option<NodeSet>,
97100
}
98101

99102
impl LintPass for NewWithoutDefault {
100103
fn get_lints(&self) -> LintArray {
101-
lint_array!(NEW_WITHOUT_DEFAULT, NEW_WITHOUT_DEFAULT_DERIVE)
104+
lint_array!(NEW_WITHOUT_DEFAULT)
102105
}
103106
}
104107

@@ -167,7 +170,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
167170
if let Some(sp) = can_derive_default(self_ty, cx, default_trait_id) {
168171
span_lint_node_and_then(
169172
cx,
170-
NEW_WITHOUT_DEFAULT_DERIVE,
173+
NEW_WITHOUT_DEFAULT,
171174
id,
172175
impl_item.span,
173176
&format!(

tests/ui/methods.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
clippy::print_stdout,
1515
clippy::non_ascii_literal,
1616
clippy::new_without_default,
17-
clippy::new_without_default_derive,
1817
clippy::missing_docs_in_private_items,
1918
clippy::needless_pass_by_value,
2019
clippy::default_trait_access,

0 commit comments

Comments
 (0)