aboutsummaryrefslogtreecommitdiff
path: root/docs/user
diff options
context:
space:
mode:
Diffstat (limited to 'docs/user')
-rw-r--r--docs/user/assists.md137
-rw-r--r--docs/user/features.md91
2 files changed, 137 insertions, 91 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md
index cb4b0b9fb..eeb486832 100644
--- a/docs/user/assists.md
+++ b/docs/user/assists.md
@@ -1,5 +1,142 @@
1# Assists 1# Assists
2 2
3## `add_derive`
4
5Adds a new `#[derive()]` clause to a struct or enum.
6
7```rust
8// BEFORE
9struct Point {
10 x: u32,
11 y: u32,<|>
12}
13
14// AFTER
15#[derive()]
16struct Point {
17 x: u32,
18 y: u32,
19}
20```
21
22## `add_explicit_type`
23
24Specify type for a let binding
25
26```rust
27// BEFORE
28fn main() {
29 let x<|> = 92;
30}
31
32// AFTER
33fn main() {
34 let x: i32 = 92;
35}
36```
37
38## `add_impl`
39
40Adds a new inherent impl for a type
41
42```rust
43// BEFORE
44struct Ctx<T: Clone> {
45 data: T,<|>
46}
47
48// AFTER
49struct Ctx<T: Clone> {
50 data: T,
51}
52
53impl<T: Clone> Ctx<T> {
54
55}
56```
57
58## `add_impl_default_members`
59
60Adds scaffold for overriding default impl members
61
62```rust
63// BEFORE
64trait T {
65 Type X;
66 fn foo(&self);
67 fn bar(&self) {}
68}
69
70impl T for () {
71 Type X = ();
72 fn foo(&self) {}<|>
73
74}
75
76// AFTER
77trait T {
78 Type X;
79 fn foo(&self);
80 fn bar(&self) {}
81}
82
83impl T for () {
84 Type X = ();
85 fn foo(&self) {}
86 fn bar(&self) {}
87
88}
89```
90
91## `add_impl_missing_members`
92
93Adds scaffold for required impl members
94
95```rust
96// BEFORE
97trait T {
98 Type X;
99 fn foo(&self);
100 fn bar(&self) {}
101}
102
103impl T for () {<|>
104
105}
106
107// AFTER
108trait T {
109 Type X;
110 fn foo(&self);
111 fn bar(&self) {}
112}
113
114impl T for () {
115 fn foo(&self) { unimplemented!() }
116
117}
118```
119
120## `apply_demorgan`
121
122Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
123This transforms expressions of the form `!l || !r` into `!(l && r)`.
124This also works with `&&`. This assist can only be applied with the cursor
125on either `||` or `&&`, with both operands being a negation of some kind.
126This means something of the form `!x` or `x != y`.
127
128```rust
129// BEFORE
130fn main() {
131 if x != 4 ||<|> !y {}
132}
133
134// AFTER
135fn main() {
136 if !(x == 4 && y) {}
137}
138```
139
3## `convert_to_guarded_return` 140## `convert_to_guarded_return`
4 141
5Replace a large conditional with a guarded return. 142Replace a large conditional with a guarded return.
diff --git a/docs/user/features.md b/docs/user/features.md
index a94b65ad4..acf092cec 100644
--- a/docs/user/features.md
+++ b/docs/user/features.md
@@ -104,84 +104,6 @@ the VS Code side to be able to position cursor. `<|>` signifies cursor
104 104
105See [assists.md](./assists.md) 105See [assists.md](./assists.md)
106 106
107- Add `#[derive]`
108
109```rust
110// before:
111struct Foo {
112 <|>x: i32
113}
114// after:
115#[derive(<|>)]
116struct Foo {
117 x: i32
118}
119```
120
121- Add `impl`
122
123```rust
124// before:
125struct Foo<'a, T: Debug> {
126 <|>t: T
127}
128// after:
129struct Foo<'a, T: Debug> {
130 t: T
131}
132
133impl<'a, T: Debug> Foo<'a, T> {
134 <|>
135}
136```
137
138- Add missing `impl` members
139
140```rust
141// before:
142trait Foo {
143 fn foo(&self);
144 fn bar(&self);
145 fn baz(&self);
146}
147
148struct S;
149
150impl Foo for S {
151 fn bar(&self) {}
152 <|>
153}
154
155// after:
156trait Foo {
157 fn foo(&self);
158 fn bar(&self);
159 fn baz(&self);
160}
161
162struct S;
163
164impl Foo for S {
165 fn bar(&self) {}
166 fn foo(&self) { unimplemented!() }
167 fn baz(&self) { unimplemented!() }<|>
168}
169```
170
171- Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws)
172
173```rust
174// before:
175fn example(x: bool) -> bool {
176 !x || !x
177}
178
179// after:
180fn example(x: bool) -> bool {
181 !(x && x)
182}
183```
184
185- Import path 107- Import path
186 108
187```rust 109```rust
@@ -391,19 +313,6 @@ fn foo() {
391} 313}
392``` 314```
393 315
394- Add explicit type
395
396```rust
397// before:
398fn foo() {
399 let t<|> = (&2, Some(1));
400}
401// after:
402fn foo() {
403 let t<|>: (&i32, Option<i32>) = (&2, Some(1));
404}
405```
406
407- Move guard expression to match arm body 316- Move guard expression to match arm body
408```rust 317```rust
409// before: 318// before: