summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/new_without_default.txt
blob: 662d39c8efdd2b6c311359de9e881ba1580cb9ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### What it does
Checks for public types with a `pub fn new() -> Self` method and no
implementation of
[`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).

### 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.

### Example
```
pub struct Foo(Bar);

impl Foo {
    pub fn new() -> Self {
        Foo(Bar::new())
    }
}
```

To fix the lint, add a `Default` implementation that delegates to `new`:

```
pub struct Foo(Bar);

impl Default for Foo {
    fn default() -> Self {
        Foo::new()
    }
}
```