mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
Merge pull request #875 from Manishearth/fx-doc
Improve new_without_default docs
This commit is contained in:
commit
c66e90303f
1 changed files with 21 additions and 3 deletions
|
@ -6,10 +6,13 @@ use syntax::codemap::Span;
|
||||||
use utils::paths;
|
use utils::paths;
|
||||||
use utils::{get_trait_def_id, implements_trait, in_external_macro, return_ty, same_tys, span_lint};
|
use utils::{get_trait_def_id, implements_trait, in_external_macro, return_ty, same_tys, span_lint};
|
||||||
|
|
||||||
/// **What it does:** This lints about type with a `fn new() -> Self` method and no `Default`
|
/// **What it does:** This lints about type with a `fn new() -> Self` method
|
||||||
/// implementation.
|
/// and no implementation of
|
||||||
|
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)
|
||||||
///
|
///
|
||||||
/// **Why is this bad?** User might expect to be able to use `Default` as the type can be
|
/// **Why is this bad?** 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.
|
/// constructed without arguments.
|
||||||
///
|
///
|
||||||
/// **Known problems:** Hopefully none.
|
/// **Known problems:** Hopefully none.
|
||||||
|
@ -25,6 +28,21 @@ use utils::{get_trait_def_id, implements_trait, in_external_macro, return_ty, sa
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// Instead, use:
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// struct Foo;
|
||||||
|
///
|
||||||
|
/// impl Default for Foo {
|
||||||
|
/// fn default() -> Self {
|
||||||
|
/// Foo
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// You can also have `new()` call `Default::default()`
|
||||||
|
///
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
pub NEW_WITHOUT_DEFAULT,
|
pub NEW_WITHOUT_DEFAULT,
|
||||||
Warn,
|
Warn,
|
||||||
|
|
Loading…
Reference in a new issue