aboutsummaryrefslogtreecommitdiff
path: root/docs/dev
diff options
context:
space:
mode:
Diffstat (limited to 'docs/dev')
-rw-r--r--docs/dev/README.md7
-rw-r--r--docs/dev/lsp-extensions.md10
-rw-r--r--docs/dev/style.md44
3 files changed, 60 insertions, 1 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 36edddc70..90e74f226 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -35,7 +35,12 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0
35* [E-easy](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy), 35* [E-easy](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy),
36 [E-medium](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-medium), 36 [E-medium](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-medium),
37 [E-hard](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-hard), 37 [E-hard](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-hard),
38 labels are *estimates* for how hard would be to write a fix. 38 [E-unknown](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-unknown),
39 labels are *estimates* for how hard would be to write a fix. Each triaged issue should have one of these labels.
40* [S-actionable](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AS-actionable) and
41 [S-unactionable](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AS-unactionable)
42 specify if there are concrete steps to resolve or advance an issue. Roughly, actionable issues need only work to be fixed,
43 while unactionable ones are effectively wont-fix. Each triaged issue should have one of these labels.
39* [fun](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3Afun) 44* [fun](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3Afun)
40 is for cool, but probably hard stuff. 45 is for cool, but probably hard stuff.
41 46
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 3f861f3e0..43a69d6ce 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,3 +1,13 @@
1<!---
2lsp_ext.rs hash: 286f8bbac885531a
3
4If you need to change the above hash to make the test pass, please check if you
5need to adjust this doc as well and ping this issue:
6
7 https://github.com/rust-analyzer/rust-analyzer/issues/4604
8
9--->
10
1# LSP Extensions 11# LSP Extensions
2 12
3This document describes LSP extensions used by rust-analyzer. 13This document describes LSP extensions used by rust-analyzer.
diff --git a/docs/dev/style.md b/docs/dev/style.md
index 59067d234..883a6845d 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -186,6 +186,31 @@ impl Person {
186} 186}
187``` 187```
188 188
189## Constructors
190
191Prefer `Default` to zero-argument `new` function
192
193```rust
194// Good
195#[derive(Default)]
196struct Foo {
197 bar: Option<Bar>
198}
199
200// Not as good
201struct Foo {
202 bar: Option<Bar>
203}
204
205impl Foo {
206 fn new() -> Foo {
207 Foo { bar: None }
208 }
209}
210```
211
212Prefer `Default` even it has to be implemented manually.
213
189## Avoid Monomorphization 214## Avoid Monomorphization
190 215
191Rust uses monomorphization to compile generic code, meaning that for each instantiation of a generic functions with concrete types, the function is compiled afresh, *per crate*. 216Rust uses monomorphization to compile generic code, meaning that for each instantiation of a generic functions with concrete types, the function is compiled afresh, *per crate*.
@@ -223,6 +248,8 @@ fn frbonicate(f: impl AsRef<Path>) {
223 248
224# Premature Pessimization 249# Premature Pessimization
225 250
251## Avoid Allocations
252
226Avoid writing code which is slower than it needs to be. 253Avoid writing code which is slower than it needs to be.
227Don't allocate a `Vec` where an iterator would do, don't allocate strings needlessly. 254Don't allocate a `Vec` where an iterator would do, don't allocate strings needlessly.
228 255
@@ -242,6 +269,8 @@ if words.len() != 2 {
242} 269}
243``` 270```
244 271
272## Push Allocations to the Call Site
273
245If allocation is inevitable, let the caller allocate the resource: 274If allocation is inevitable, let the caller allocate the resource:
246 275
247```rust 276```rust
@@ -257,6 +286,9 @@ fn frobnicate(s: &str) {
257} 286}
258``` 287```
259 288
289This is better because it reveals the costs.
290It is also more efficient when the caller already owns the allocation.
291
260## Collection types 292## Collection types
261 293
262Prefer `rustc_hash::FxHashMap` and `rustc_hash::FxHashSet` instead of the ones in `std::collections`. 294Prefer `rustc_hash::FxHashMap` and `rustc_hash::FxHashSet` instead of the ones in `std::collections`.
@@ -371,6 +403,18 @@ Default names:
371* `n_foo` -- number of foos 403* `n_foo` -- number of foos
372* `foo_idx` -- index of `foo` 404* `foo_idx` -- index of `foo`
373 405
406Many names in rust-analyzer conflict with keywords.
407We use mangled names instead of `r#ident` syntax:
408
409```
410struct -> strukt
411crate -> krate
412impl -> imp
413trait -> trait_
414fn -> func
415enum -> enum_
416mod -> module
417```
374 418
375## Early Returns 419## Early Returns
376 420