Merge #7519
7519: add useless types to the styleguide r=matklad a=matklad bors r+ Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
96f9f0741f
@ -267,6 +267,20 @@ Non-local code properties degrade under change, privacy makes invariant local.
|
||||
Borrowed own data discloses irrelevant details about origin of data.
|
||||
Irrelevant (neither right nor wrong) things obscure correctness.
|
||||
|
||||
## Useless Types
|
||||
|
||||
More generally, always prefer types on the left
|
||||
|
||||
```rust
|
||||
// GOOD BAD
|
||||
&[T] &Vec<T>
|
||||
&str &String
|
||||
Option<&T> &Option<T>
|
||||
```
|
||||
|
||||
**Rationale:** types on the left are strictly more general.
|
||||
Even when generality is not required, consistency is important.
|
||||
|
||||
## Constructors
|
||||
|
||||
Prefer `Default` to zero-argument `new` function
|
||||
|
Loading…
Reference in New Issue
Block a user