about summary refs log tree commit diff
path: root/docs/dev
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2021-08-11 14:16:15 +0300
committerAleksey Kladov <aleksey.kladov@gmail.com>2021-08-11 14:16:15 +0300
commit629c68e80d3d9473226c8f3713e95a2011999f2c (patch)
tree6bfb3733a706a15646dd1bed14edd018db6fcd5a /docs/dev
parent145b51f9daf5371f1754c09eb2e3a77e0a24a0dc (diff)
downloadrust-629c68e80d3d9473226c8f3713e95a2011999f2c.tar.gz
rust-629c68e80d3d9473226c8f3713e95a2011999f2c.zip
internal: document that ascription is preferred to a turbo fish
Diffstat (limited to 'docs/dev')
-rw-r--r--docs/dev/style.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md
index 257049915df..ac9ad8fc282 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -950,6 +950,26 @@ At the same time, it is more crowded -- it takes more time to visually scan it.
 **Rationale:** consistency, playing to language's strengths.
 Rust has first-class support for imperative control flow constructs like `for` and `if`, while functions are less first-class due to lack of universal function type, currying, and non-first-class effects (`?`, `.await`).
 
+## Turbofish
+
+Prefer type ascription over the turbofish.
+When ascribing types, avoid `_`
+
+```rust
+// GOOD
+let mutable: Vec<T> = old.into_iter().map(|it| builder.make_mut(it)).collect();
+
+// BAD
+let mutable: Vec<_> = old.into_iter().map(|it| builder.make_mut(it)).collect();
+
+// BAD
+let mutable = old.into_iter().map(|it| builder.make_mut(it)).collect::<Vec<_>>();
+```
+
+**Rationale:** consistency, readability.
+If compiler struggles to infer the type, the human would as well.
+Having the result type specified up-front helps with understanding what the chain of iterator methods is doing.
+
 ## Helper Functions
 
 Avoid creating singe-use helper functions: