mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
add useless types to the styleguide
This commit is contained in:
parent
8720f7f146
commit
283c3b0133
@ -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.
|
Borrowed own data discloses irrelevant details about origin of data.
|
||||||
Irrelevant (neither right nor wrong) things obscure correctness.
|
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
|
## Constructors
|
||||||
|
|
||||||
Prefer `Default` to zero-argument `new` function
|
Prefer `Default` to zero-argument `new` function
|
||||||
|
Loading…
x
Reference in New Issue
Block a user