mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
add useless types to the styleguide
This commit is contained in:
parent
8720f7f146
commit
283c3b0133
1 changed files with 14 additions and 0 deletions
|
@ -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 a new issue