Skip to content

Commit d127aed

Browse files
committed
Merge new_without_default_derive into new_without_default
1 parent f7bdf50 commit d127aed

10 files changed

+94
-82
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ All notable changes to this project will be documented in this file.
785785
[`never_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
786786
[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self
787787
[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
788-
[`new_without_default_derive`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default_derive
789788
[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect
790789
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
791790
[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 291 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 290 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

1212
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1313

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
701701
neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
702702
neg_multiply::NEG_MULTIPLY,
703703
new_without_default::NEW_WITHOUT_DEFAULT,
704-
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
705704
no_effect::NO_EFFECT,
706705
no_effect::UNNECESSARY_OPERATION,
707706
non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
@@ -837,7 +836,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
837836
mut_reference::UNNECESSARY_MUT_PASSED,
838837
neg_multiply::NEG_MULTIPLY,
839838
new_without_default::NEW_WITHOUT_DEFAULT,
840-
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
841839
non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
842840
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
843841
ok_if_let::IF_LET_SOME_RESULT,
@@ -1032,6 +1030,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
10321030

10331031
pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
10341032
ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1033+
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
10351034
}
10361035

10371036
// only exists to let the dogfood integration test works.

clippy_lints/src/new_without_default.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ use if_chain::if_chain;
2424
/// implementation of
2525
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
2626
///
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)]
31+
///
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
2934
/// type can be constructed without arguments.
@@ -54,27 +59,24 @@ use if_chain::if_chain;
5459
/// }
5560
/// ```
5661
///
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)]`.
62+
/// Or, if
63+
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
64+
/// can be derived by `#[derive(Default)]`:
6865
///
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.
66+
/// ```rust
67+
/// struct Foo;
7268
///
73-
/// **Known problems:** Hopefully none.
69+
/// impl Foo {
70+
/// fn new() -> Self {
71+
/// Foo
72+
/// }
73+
/// }
74+
/// ```
7475
///
75-
/// **Example:**
76+
/// Instead, use:
7677
///
7778
/// ```rust
79+
/// #[derive(Default)]
7880
/// struct Foo;
7981
///
8082
/// impl Foo {
@@ -84,11 +86,11 @@ declare_clippy_lint! {
8486
/// }
8587
/// ```
8688
///
87-
/// Just prepend `#[derive(Default)]` before the `struct` definition.
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

9496
#[derive(Clone, Default)]
@@ -98,7 +100,7 @@ pub struct NewWithoutDefault {
98100

99101
impl LintPass for NewWithoutDefault {
100102
fn get_lints(&self) -> LintArray {
101-
lint_array!(NEW_WITHOUT_DEFAULT, NEW_WITHOUT_DEFAULT_DERIVE)
103+
lint_array!(NEW_WITHOUT_DEFAULT)
102104
}
103105
}
104106

@@ -167,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
167169
if let Some(sp) = can_derive_default(self_ty, cx, default_trait_id) {
168170
span_lint_node_and_then(
169171
cx,
170-
NEW_WITHOUT_DEFAULT_DERIVE,
172+
NEW_WITHOUT_DEFAULT,
171173
id,
172174
impl_item.span,
173175
&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)