diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-02 13:09:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-02 13:09:21 +0000 |
| commit | 96f9f0741f0b1ba345f35637cd5b21f5fad2a354 (patch) | |
| tree | 1c3f2e2cda9b579e70ee6b6c55a89b4428d0170b /docs/dev | |
| parent | 8720f7f14688257d320de44e1354c62fce1a6bcf (diff) | |
| parent | 283c3b0133ec4d3217a29547a45092d6e64e4935 (diff) | |
| download | rust-96f9f0741f0b1ba345f35637cd5b21f5fad2a354.tar.gz rust-96f9f0741f0b1ba345f35637cd5b21f5fad2a354.zip | |
Merge #7519
7519: add useless types to the styleguide r=matklad a=matklad bors r+ Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Diffstat (limited to 'docs/dev')
| -rw-r--r-- | docs/dev/style.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md index 0c5e2ad33cb..e2f1b6996af 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -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 |
