aboutsummaryrefslogtreecommitdiff
path: root/docs/user/generated_assists.adoc
diff options
context:
space:
mode:
Diffstat (limited to 'docs/user/generated_assists.adoc')
-rw-r--r--docs/user/generated_assists.adoc973
1 files changed, 973 insertions, 0 deletions
diff --git a/docs/user/generated_assists.adoc b/docs/user/generated_assists.adoc
new file mode 100644
index 000000000..b8cdfb1cd
--- /dev/null
+++ b/docs/user/generated_assists.adoc
@@ -0,0 +1,973 @@
1[discrete]
2=== `add_custom_impl`
3
4Adds impl block for derived trait.
5
6.Before
7```rust
8#[derive(Deb┃ug, Display)]
9struct S;
10```
11
12.After
13```rust
14#[derive(Display)]
15struct S;
16
17impl Debug for S {
18 $0
19}
20```
21
22
23[discrete]
24=== `add_derive`
25
26Adds a new `#[derive()]` clause to a struct or enum.
27
28.Before
29```rust
30struct Point {
31 x: u32,
32 y: u32,┃
33}
34```
35
36.After
37```rust
38#[derive($0)]
39struct Point {
40 x: u32,
41 y: u32,
42}
43```
44
45
46[discrete]
47=== `add_explicit_type`
48
49Specify type for a let binding.
50
51.Before
52```rust
53fn main() {
54 let x┃ = 92;
55}
56```
57
58.After
59```rust
60fn main() {
61 let x: i32 = 92;
62}
63```
64
65
66[discrete]
67=== `add_from_impl_for_enum`
68
69Adds a From impl for an enum variant with one tuple field.
70
71.Before
72```rust
73enum A { ┃One(u32) }
74```
75
76.After
77```rust
78enum A { One(u32) }
79
80impl From<u32> for A {
81 fn from(v: u32) -> Self {
82 A::One(v)
83 }
84}
85```
86
87
88[discrete]
89=== `add_function`
90
91Adds a stub function with a signature matching the function under the cursor.
92
93.Before
94```rust
95struct Baz;
96fn baz() -> Baz { Baz }
97fn foo() {
98 bar┃("", baz());
99}
100
101```
102
103.After
104```rust
105struct Baz;
106fn baz() -> Baz { Baz }
107fn foo() {
108 bar("", baz());
109}
110
111fn bar(arg: &str, baz: Baz) {
112 ${0:todo!()}
113}
114
115```
116
117
118[discrete]
119=== `add_hash`
120
121Adds a hash to a raw string literal.
122
123.Before
124```rust
125fn main() {
126 r#"Hello,┃ World!"#;
127}
128```
129
130.After
131```rust
132fn main() {
133 r##"Hello, World!"##;
134}
135```
136
137
138[discrete]
139=== `add_impl`
140
141Adds a new inherent impl for a type.
142
143.Before
144```rust
145struct Ctx<T: Clone> {
146 data: T,┃
147}
148```
149
150.After
151```rust
152struct Ctx<T: Clone> {
153 data: T,
154}
155
156impl<T: Clone> Ctx<T> {
157 $0
158}
159```
160
161
162[discrete]
163=== `add_impl_default_members`
164
165Adds scaffold for overriding default impl members.
166
167.Before
168```rust
169trait Trait {
170 Type X;
171 fn foo(&self);
172 fn bar(&self) {}
173}
174
175impl Trait for () {
176 Type X = ();
177 fn foo(&self) {}┃
178
179}
180```
181
182.After
183```rust
184trait Trait {
185 Type X;
186 fn foo(&self);
187 fn bar(&self) {}
188}
189
190impl Trait for () {
191 Type X = ();
192 fn foo(&self) {}
193 $0fn bar(&self) {}
194
195}
196```
197
198
199[discrete]
200=== `add_impl_missing_members`
201
202Adds scaffold for required impl members.
203
204.Before
205```rust
206trait Trait<T> {
207 Type X;
208 fn foo(&self) -> T;
209 fn bar(&self) {}
210}
211
212impl Trait<u32> for () {┃
213
214}
215```
216
217.After
218```rust
219trait Trait<T> {
220 Type X;
221 fn foo(&self) -> T;
222 fn bar(&self) {}
223}
224
225impl Trait<u32> for () {
226 fn foo(&self) -> u32 {
227 ${0:todo!()}
228 }
229
230}
231```
232
233
234[discrete]
235=== `add_new`
236
237Adds a new inherent impl for a type.
238
239.Before
240```rust
241struct Ctx<T: Clone> {
242 data: T,┃
243}
244```
245
246.After
247```rust
248struct Ctx<T: Clone> {
249 data: T,
250}
251
252impl<T: Clone> Ctx<T> {
253 fn $0new(data: T) -> Self { Self { data } }
254}
255
256```
257
258
259[discrete]
260=== `add_turbo_fish`
261
262Adds `::<_>` to a call of a generic method or function.
263
264.Before
265```rust
266fn make<T>() -> T { todo!() }
267fn main() {
268 let x = make┃();
269}
270```
271
272.After
273```rust
274fn make<T>() -> T { todo!() }
275fn main() {
276 let x = make::<${0:_}>();
277}
278```
279
280
281[discrete]
282=== `apply_demorgan`
283
284Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
285This transforms expressions of the form `!l || !r` into `!(l && r)`.
286This also works with `&&`. This assist can only be applied with the cursor
287on either `||` or `&&`, with both operands being a negation of some kind.
288This means something of the form `!x` or `x != y`.
289
290.Before
291```rust
292fn main() {
293 if x != 4 ||┃ !y {}
294}
295```
296
297.After
298```rust
299fn main() {
300 if !(x == 4 && y) {}
301}
302```
303
304
305[discrete]
306=== `auto_import`
307
308If the name is unresolved, provides all possible imports for it.
309
310.Before
311```rust
312fn main() {
313 let map = HashMap┃::new();
314}
315```
316
317.After
318```rust
319use std::collections::HashMap;
320
321fn main() {
322 let map = HashMap::new();
323}
324```
325
326
327[discrete]
328=== `change_lifetime_anon_to_named`
329
330Change an anonymous lifetime to a named lifetime.
331
332.Before
333```rust
334impl Cursor<'_┃> {
335 fn node(self) -> &SyntaxNode {
336 match self {
337 Cursor::Replace(node) | Cursor::Before(node) => node,
338 }
339 }
340}
341```
342
343.After
344```rust
345impl<'a> Cursor<'a> {
346 fn node(self) -> &SyntaxNode {
347 match self {
348 Cursor::Replace(node) | Cursor::Before(node) => node,
349 }
350 }
351}
352```
353
354
355[discrete]
356=== `change_return_type_to_result`
357
358Change the function's return type to Result.
359
360.Before
361```rust
362fn foo() -> i32┃ { 42i32 }
363```
364
365.After
366```rust
367fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
368```
369
370
371[discrete]
372=== `change_visibility`
373
374Adds or changes existing visibility specifier.
375
376.Before
377```rust
378┃fn frobnicate() {}
379```
380
381.After
382```rust
383pub(crate) fn frobnicate() {}
384```
385
386
387[discrete]
388=== `convert_to_guarded_return`
389
390Replace a large conditional with a guarded return.
391
392.Before
393```rust
394fn main() {
395 ┃if cond {
396 foo();
397 bar();
398 }
399}
400```
401
402.After
403```rust
404fn main() {
405 if !cond {
406 return;
407 }
408 foo();
409 bar();
410}
411```
412
413
414[discrete]
415=== `fill_match_arms`
416
417Adds missing clauses to a `match` expression.
418
419.Before
420```rust
421enum Action { Move { distance: u32 }, Stop }
422
423fn handle(action: Action) {
424 match action {
425
426 }
427}
428```
429
430.After
431```rust
432enum Action { Move { distance: u32 }, Stop }
433
434fn handle(action: Action) {
435 match action {
436 $0Action::Move { distance } => {}
437 Action::Stop => {}
438 }
439}
440```
441
442
443[discrete]
444=== `fix_visibility`
445
446Makes inaccessible item public.
447
448.Before
449```rust
450mod m {
451 fn frobnicate() {}
452}
453fn main() {
454 m::frobnicate┃() {}
455}
456```
457
458.After
459```rust
460mod m {
461 $0pub(crate) fn frobnicate() {}
462}
463fn main() {
464 m::frobnicate() {}
465}
466```
467
468
469[discrete]
470=== `flip_binexpr`
471
472Flips operands of a binary expression.
473
474.Before
475```rust
476fn main() {
477 let _ = 90 +┃ 2;
478}
479```
480
481.After
482```rust
483fn main() {
484 let _ = 2 + 90;
485}
486```
487
488
489[discrete]
490=== `flip_comma`
491
492Flips two comma-separated items.
493
494.Before
495```rust
496fn main() {
497 ((1, 2),┃ (3, 4));
498}
499```
500
501.After
502```rust
503fn main() {
504 ((3, 4), (1, 2));
505}
506```
507
508
509[discrete]
510=== `flip_trait_bound`
511
512Flips two trait bounds.
513
514.Before
515```rust
516fn foo<T: Clone +┃ Copy>() { }
517```
518
519.After
520```rust
521fn foo<T: Copy + Clone>() { }
522```
523
524
525[discrete]
526=== `inline_local_variable`
527
528Inlines local variable.
529
530.Before
531```rust
532fn main() {
533 let x┃ = 1 + 2;
534 x * 4;
535}
536```
537
538.After
539```rust
540fn main() {
541 (1 + 2) * 4;
542}
543```
544
545
546[discrete]
547=== `introduce_variable`
548
549Extracts subexpression into a variable.
550
551.Before
552```rust
553fn main() {
554 ┃(1 + 2)┃ * 4;
555}
556```
557
558.After
559```rust
560fn main() {
561 let $0var_name = (1 + 2);
562 var_name * 4;
563}
564```
565
566
567[discrete]
568=== `invert_if`
569
570Apply invert_if
571This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}`
572This also works with `!=`. This assist can only be applied with the cursor
573on `if`.
574
575.Before
576```rust
577fn main() {
578 if┃ !y { A } else { B }
579}
580```
581
582.After
583```rust
584fn main() {
585 if y { B } else { A }
586}
587```
588
589
590[discrete]
591=== `make_raw_string`
592
593Adds `r#` to a plain string literal.
594
595.Before
596```rust
597fn main() {
598 "Hello,┃ World!";
599}
600```
601
602.After
603```rust
604fn main() {
605 r#"Hello, World!"#;
606}
607```
608
609
610[discrete]
611=== `make_usual_string`
612
613Turns a raw string into a plain string.
614
615.Before
616```rust
617fn main() {
618 r#"Hello,┃ "World!""#;
619}
620```
621
622.After
623```rust
624fn main() {
625 "Hello, \"World!\"";
626}
627```
628
629
630[discrete]
631=== `merge_imports`
632
633Merges two imports with a common prefix.
634
635.Before
636```rust
637use std::┃fmt::Formatter;
638use std::io;
639```
640
641.After
642```rust
643use std::{fmt::Formatter, io};
644```
645
646
647[discrete]
648=== `merge_match_arms`
649
650Merges identical match arms.
651
652.Before
653```rust
654enum Action { Move { distance: u32 }, Stop }
655
656fn handle(action: Action) {
657 match action {
658 ┃Action::Move(..) => foo(),
659 Action::Stop => foo(),
660 }
661}
662```
663
664.After
665```rust
666enum Action { Move { distance: u32 }, Stop }
667
668fn handle(action: Action) {
669 match action {
670 Action::Move(..) | Action::Stop => foo(),
671 }
672}
673```
674
675
676[discrete]
677=== `move_arm_cond_to_match_guard`
678
679Moves if expression from match arm body into a guard.
680
681.Before
682```rust
683enum Action { Move { distance: u32 }, Stop }
684
685fn handle(action: Action) {
686 match action {
687 Action::Move { distance } => ┃if distance > 10 { foo() },
688 _ => (),
689 }
690}
691```
692
693.After
694```rust
695enum Action { Move { distance: u32 }, Stop }
696
697fn handle(action: Action) {
698 match action {
699 Action::Move { distance } if distance > 10 => foo(),
700 _ => (),
701 }
702}
703```
704
705
706[discrete]
707=== `move_bounds_to_where_clause`
708
709Moves inline type bounds to a where clause.
710
711.Before
712```rust
713fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U {
714 f(x)
715}
716```
717
718.After
719```rust
720fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
721 f(x)
722}
723```
724
725
726[discrete]
727=== `move_guard_to_arm_body`
728
729Moves match guard into match arm body.
730
731.Before
732```rust
733enum Action { Move { distance: u32 }, Stop }
734
735fn handle(action: Action) {
736 match action {
737 Action::Move { distance } ┃if distance > 10 => foo(),
738 _ => (),
739 }
740}
741```
742
743.After
744```rust
745enum Action { Move { distance: u32 }, Stop }
746
747fn handle(action: Action) {
748 match action {
749 Action::Move { distance } => if distance > 10 { foo() },
750 _ => (),
751 }
752}
753```
754
755
756[discrete]
757=== `remove_dbg`
758
759Removes `dbg!()` macro call.
760
761.Before
762```rust
763fn main() {
764 ┃dbg!(92);
765}
766```
767
768.After
769```rust
770fn main() {
771 92;
772}
773```
774
775
776[discrete]
777=== `remove_hash`
778
779Removes a hash from a raw string literal.
780
781.Before
782```rust
783fn main() {
784 r#"Hello,┃ World!"#;
785}
786```
787
788.After
789```rust
790fn main() {
791 r"Hello, World!";
792}
793```
794
795
796[discrete]
797=== `remove_mut`
798
799Removes the `mut` keyword.
800
801.Before
802```rust
803impl Walrus {
804 fn feed(&mut┃ self, amount: u32) {}
805}
806```
807
808.After
809```rust
810impl Walrus {
811 fn feed(&self, amount: u32) {}
812}
813```
814
815
816[discrete]
817=== `reorder_fields`
818
819Reorder the fields of record literals and record patterns in the same order as in
820the definition.
821
822.Before
823```rust
824struct Foo {foo: i32, bar: i32};
825const test: Foo = ┃Foo {bar: 0, foo: 1}
826```
827
828.After
829```rust
830struct Foo {foo: i32, bar: i32};
831const test: Foo = Foo {foo: 1, bar: 0}
832```
833
834
835[discrete]
836=== `replace_if_let_with_match`
837
838Replaces `if let` with an else branch with a `match` expression.
839
840.Before
841```rust
842enum Action { Move { distance: u32 }, Stop }
843
844fn handle(action: Action) {
845 ┃if let Action::Move { distance } = action {
846 foo(distance)
847 } else {
848 bar()
849 }
850}
851```
852
853.After
854```rust
855enum Action { Move { distance: u32 }, Stop }
856
857fn handle(action: Action) {
858 match action {
859 Action::Move { distance } => foo(distance),
860 _ => bar(),
861 }
862}
863```
864
865
866[discrete]
867=== `replace_let_with_if_let`
868
869Replaces `let` with an `if-let`.
870
871.Before
872```rust
873
874fn main(action: Action) {
875 ┃let x = compute();
876}
877
878fn compute() -> Option<i32> { None }
879```
880
881.After
882```rust
883
884fn main(action: Action) {
885 if let Some(x) = compute() {
886 }
887}
888
889fn compute() -> Option<i32> { None }
890```
891
892
893[discrete]
894=== `replace_qualified_name_with_use`
895
896Adds a use statement for a given fully-qualified name.
897
898.Before
899```rust
900fn process(map: std::collections::┃HashMap<String, String>) {}
901```
902
903.After
904```rust
905use std::collections::HashMap;
906
907fn process(map: HashMap<String, String>) {}
908```
909
910
911[discrete]
912=== `replace_unwrap_with_match`
913
914Replaces `unwrap` a `match` expression. Works for Result and Option.
915
916.Before
917```rust
918enum Result<T, E> { Ok(T), Err(E) }
919fn main() {
920 let x: Result<i32, i32> = Result::Ok(92);
921 let y = x.┃unwrap();
922}
923```
924
925.After
926```rust
927enum Result<T, E> { Ok(T), Err(E) }
928fn main() {
929 let x: Result<i32, i32> = Result::Ok(92);
930 let y = match x {
931 Ok(a) => a,
932 $0_ => unreachable!(),
933 };
934}
935```
936
937
938[discrete]
939=== `split_import`
940
941Wraps the tail of import into braces.
942
943.Before
944```rust
945use std::┃collections::HashMap;
946```
947
948.After
949```rust
950use std::{collections::HashMap};
951```
952
953
954[discrete]
955=== `unwrap_block`
956
957This assist removes if...else, for, while and loop control statements to just keep the body.
958
959.Before
960```rust
961fn foo() {
962 if true {┃
963 println!("foo");
964 }
965}
966```
967
968.After
969```rust
970fn foo() {
971 println!("foo");
972}
973```