]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/new_ret_no_self.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / new_ret_no_self.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for `new` not returning a type that contains `Self`.
3
4### Why is this bad?
5As a convention, `new` methods are used to make a new
6instance of a type.
7
8### Example
9In an impl block:
10```
11impl Foo {
12 fn new() -> NotAFoo {
13 }
14}
15```
16
17```
18struct Bar(Foo);
19impl Foo {
20 // Bad. The type name must contain `Self`
21 fn new() -> Bar {
22 }
23}
24```
25
26```
27impl Foo {
28 // Good. Return type contains `Self`
29 fn new() -> Result<Foo, FooError> {
30 }
31}
32```
33
34Or in a trait definition:
35```
36pub trait Trait {
37 // Bad. The type name must contain `Self`
38 fn new();
39}
40```
41
42```
43pub trait Trait {
44 // Good. Return type contains `Self`
45 fn new() -> Self;
46}
47```