aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-27 08:27:19 +0000
committerGitHub <[email protected]>2019-10-27 08:27:19 +0000
commitb85f6d522af7630ab227762076a9fbf75de502de (patch)
tree3793da47dbe724189842cabeb5a7cef91ad592ef /docs
parent85984b09e182adca4b03d9f7efab20d48b5b632a (diff)
parenta490ba06fa635ecb34b5ce0b7205621eefaee603 (diff)
Merge #2083
2083: document some more assists r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'docs')
-rw-r--r--docs/user/assists.md93
-rw-r--r--docs/user/features.md84
2 files changed, 93 insertions, 84 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md
index ee1cfa142..34a95696c 100644
--- a/docs/user/assists.md
+++ b/docs/user/assists.md
@@ -265,3 +265,96 @@ fn main() {
265 var_name * 4; 265 var_name * 4;
266} 266}
267``` 267```
268
269## `merge_match_arms`
270
271Merges identical match arms.
272
273```rust
274// BEFORE
275enum Action { Move { distance: u32 }, Stop }
276
277fn handle(action: Action) {
278 match action {
279 ┃Action::Move(..) => foo(),
280 Action::Stop => foo(),
281 }
282}
283
284// AFTER
285enum Action { Move { distance: u32 }, Stop }
286
287fn handle(action: Action) {
288 match action {
289 Action::Move(..) | Action::Stop => foo(),
290 }
291}
292```
293
294## `move_arm_cond_to_match_guard`
295
296Moves if expression from match arm body into a guard.
297
298```rust
299// BEFORE
300enum Action { Move { distance: u32 }, Stop }
301
302fn handle(action: Action) {
303 match action {
304 Action::Move { distance } => ┃if distance > 10 { foo() },
305 _ => (),
306 }
307}
308
309// AFTER
310enum Action { Move { distance: u32 }, Stop }
311
312fn handle(action: Action) {
313 match action {
314 Action::Move { distance } if distance > 10 => foo(),
315 _ => (),
316 }
317}
318```
319
320## `move_bounds_to_where_clause`
321
322Moves inline type bounds to a where clause.
323
324```rust
325// BEFORE
326fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U {
327 f(x)
328}
329
330// AFTER
331fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
332 f(x)
333}
334```
335
336## `move_guard_to_arm_body`
337
338Moves match guard into match arm body.
339
340```rust
341// BEFORE
342enum Action { Move { distance: u32 }, Stop }
343
344fn handle(action: Action) {
345 match action {
346 Action::Move { distance } ┃if distance > 10 => foo(),
347 _ => (),
348 }
349}
350
351// AFTER
352enum Action { Move { distance: u32 }, Stop }
353
354fn handle(action: Action) {
355 match action {
356 Action::Move { distance } => if distance > 10 { foo() },
357 _ => (),
358 }
359}
360```
diff --git a/docs/user/features.md b/docs/user/features.md
index 39dab710d..2e213e34c 100644
--- a/docs/user/features.md
+++ b/docs/user/features.md
@@ -154,45 +154,6 @@ fn main() {
154} 154}
155``` 155```
156 156
157- Flip `,`
158
159```rust
160// before:
161fn foo(x: usize,<|> dim: (usize, usize)) {}
162// after:
163fn foo(dim: (usize, usize), x: usize) {}
164```
165
166- Introduce variable:
167
168```rust
169// before:
170fn foo() {
171 foo(<|>1 + 1<|>);
172}
173
174// after:
175fn foo() {
176 let var_name = 1 + 1;
177 foo(var_name);
178}
179```
180
181- Inline local variable:
182
183```rust
184// before:
185fn foo() {
186 let a<|> = 1 + 1;
187 let b = a * 10;
188}
189
190// after:
191fn foo() {
192 let b = (1 + 1) * 10;
193}
194```
195
196- Remove `dbg!` 157- Remove `dbg!`
197 158
198```rust 159```rust
@@ -245,41 +206,6 @@ use crate:<|>:db::{RootDatabase, FileSymbol};
245use crate::{<|>db::{RootDatabase, FileSymbol}}; 206use crate::{<|>db::{RootDatabase, FileSymbol}};
246``` 207```
247 208
248- Flip binary expression
249
250```rust
251// before:
252fn foo() {
253 if 1 <<|> 2 {
254 println!("Who would have thought?");
255 }
256}
257// after:
258fn foo() {
259 if 2 ><|> 1 {
260 println!("Who would have thought?");
261 }
262}
263```
264
265- Move guard expression to match arm body
266```rust
267// before:
268fn f() {
269 match x {
270 <|>y @ 4 | y @ 5 if y > 5 => true,
271 _ => false
272 }
273}
274// after:
275fn f() {
276 match x {
277 y @ 4 | y @ 5 => if y > 5 { <|>true },
278 _ => false
279 }
280}
281```
282
283- Move if condition to match arm guard 209- Move if condition to match arm guard
284```rust 210```rust
285// before: 211// before:
@@ -309,16 +235,6 @@ fn f() {
309} 235}
310``` 236```
311 237
312- Move type bounds to where clause
313
314```rust
315// before:
316fn foo<T: u32, F: FnOnce(T) -> T>() {}
317
318// after:
319fn foo<T, F>() where T: u32, F: FnOnce(T) -> T {}
320```
321
322- Make raw string unescaped 238- Make raw string unescaped
323 239
324```rust 240```rust