Skip to content

Merge new_without_default_derive into new_without_default #3558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ All notable changes to this project will be documented in this file.
[`never_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self
[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
[`new_without_default_derive`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default_derive
[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
neg_multiply::NEG_MULTIPLY,
new_without_default::NEW_WITHOUT_DEFAULT,
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
no_effect::NO_EFFECT,
no_effect::UNNECESSARY_OPERATION,
non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
Expand Down Expand Up @@ -837,7 +836,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
mut_reference::UNNECESSARY_MUT_PASSED,
neg_multiply::NEG_MULTIPLY,
new_without_default::NEW_WITHOUT_DEFAULT,
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
ok_if_let::IF_LET_SOME_RESULT,
Expand Down Expand Up @@ -1032,6 +1030,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {

pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
}

// only exists to let the dogfood integration test works.
Expand Down
44 changes: 23 additions & 21 deletions clippy_lints/src/new_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ use if_chain::if_chain;
/// implementation of
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
///
/// It detects both the case when a manual
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
/// implementation is required and also when it can be created with
/// `#[derive(Default)]
///
/// **Why is this bad?** The user might expect to be able to use
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) as the
/// type can be constructed without arguments.
Expand Down Expand Up @@ -54,27 +59,24 @@ use if_chain::if_chain;
/// }
/// ```
///
/// You can also have `new()` call `Default::default()`.
declare_clippy_lint! {
pub NEW_WITHOUT_DEFAULT,
style,
"`fn new() -> Self` method without `Default` implementation"
}

/// **What it does:** Checks for types with a `fn new() -> Self` method
/// and no implementation of
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html),
/// where the `Default` can be derived by `#[derive(Default)]`.
/// Or, if
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
/// can be derived by `#[derive(Default)]`:
///
/// **Why is this bad?** The user might expect to be able to use
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) as the
/// type can be constructed without arguments.
/// ```rust
/// struct Foo;
///
/// **Known problems:** Hopefully none.
/// impl Foo {
/// fn new() -> Self {
/// Foo
/// }
/// }
/// ```
///
/// **Example:**
/// Instead, use:
///
/// ```rust
/// #[derive(Default)]
/// struct Foo;
///
/// impl Foo {
Expand All @@ -84,11 +86,11 @@ declare_clippy_lint! {
/// }
/// ```
///
/// Just prepend `#[derive(Default)]` before the `struct` definition.
/// You can also have `new()` call `Default::default()`.
declare_clippy_lint! {
pub NEW_WITHOUT_DEFAULT_DERIVE,
pub NEW_WITHOUT_DEFAULT,
style,
"`fn new() -> Self` without `#[derive]`able `Default` implementation"
"`fn new() -> Self` method without `Default` implementation"
}

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

impl LintPass for NewWithoutDefault {
fn get_lints(&self) -> LintArray {
lint_array!(NEW_WITHOUT_DEFAULT, NEW_WITHOUT_DEFAULT_DERIVE)
lint_array!(NEW_WITHOUT_DEFAULT)
}
}

Expand Down Expand Up @@ -167,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
if let Some(sp) = can_derive_default(self_ty, cx, default_trait_id) {
span_lint_node_and_then(
cx,
NEW_WITHOUT_DEFAULT_DERIVE,
NEW_WITHOUT_DEFAULT,
id,
impl_item.span,
&format!(
Expand Down
1 change: 0 additions & 1 deletion tests/ui/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
clippy::print_stdout,
clippy::non_ascii_literal,
clippy::new_without_default,
clippy::new_without_default_derive,
clippy::missing_docs_in_private_items,
clippy::needless_pass_by_value,
clippy::default_trait_access,
Expand Down
Loading