Skip to content

Commit 4677cea

Browse files
bors[bot]matklad
andauthored
Merge #4540
4540: More snippets r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 64afbf8 + 5e13e4e commit 4677cea

File tree

10 files changed

+133
-172
lines changed

10 files changed

+133
-172
lines changed

crates/ra_assists/src/handlers/early_return.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
9797
}
9898

9999
then_block.syntax().last_child_or_token().filter(|t| t.kind() == R_CURLY)?;
100-
let cursor_position = ctx.offset();
101100

102101
let target = if_expr.syntax().text_range();
103102
acc.add(AssistId("convert_to_guarded_return"), "Convert to guarded return", target, |edit| {
@@ -148,7 +147,6 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
148147
}
149148
};
150149
edit.replace_ast(parent_block, ast::BlockExpr::cast(new_block).unwrap());
151-
edit.set_cursor(cursor_position);
152150

153151
fn replace(
154152
new_expr: &SyntaxNode,
@@ -207,7 +205,7 @@ mod tests {
207205
r#"
208206
fn main() {
209207
bar();
210-
if<|> !true {
208+
if !true {
211209
return;
212210
}
213211
foo();
@@ -237,7 +235,7 @@ mod tests {
237235
r#"
238236
fn main(n: Option<String>) {
239237
bar();
240-
le<|>t n = match n {
238+
let n = match n {
241239
Some(it) => it,
242240
_ => return,
243241
};
@@ -263,7 +261,7 @@ mod tests {
263261
"#,
264262
r#"
265263
fn main() {
266-
le<|>t x = match Err(92) {
264+
let x = match Err(92) {
267265
Ok(it) => it,
268266
_ => return,
269267
};
@@ -291,7 +289,7 @@ mod tests {
291289
r#"
292290
fn main(n: Option<String>) {
293291
bar();
294-
le<|>t n = match n {
292+
let n = match n {
295293
Ok(it) => it,
296294
_ => return,
297295
};
@@ -321,7 +319,7 @@ mod tests {
321319
r#"
322320
fn main() {
323321
while true {
324-
if<|> !true {
322+
if !true {
325323
continue;
326324
}
327325
foo();
@@ -349,7 +347,7 @@ mod tests {
349347
r#"
350348
fn main() {
351349
while true {
352-
le<|>t n = match n {
350+
let n = match n {
353351
Some(it) => it,
354352
_ => continue,
355353
};
@@ -378,7 +376,7 @@ mod tests {
378376
r#"
379377
fn main() {
380378
loop {
381-
if<|> !true {
379+
if !true {
382380
continue;
383381
}
384382
foo();
@@ -406,7 +404,7 @@ mod tests {
406404
r#"
407405
fn main() {
408406
loop {
409-
le<|>t n = match n {
407+
let n = match n {
410408
Some(it) => it,
411409
_ => continue,
412410
};

crates/ra_assists/src/handlers/inline_local_variable.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
116116
let replacement = if should_wrap { init_in_paren.clone() } else { init_str.clone() };
117117
builder.replace(desc.file_range.range, replacement)
118118
}
119-
builder.set_cursor(delete_range.start())
120119
})
121120
}
122121

@@ -149,7 +148,7 @@ fn foo() {
149148
r"
150149
fn bar(a: usize) {}
151150
fn foo() {
152-
<|>1 + 1;
151+
1 + 1;
153152
if 1 > 10 {
154153
}
155154
@@ -183,7 +182,7 @@ fn foo() {
183182
r"
184183
fn bar(a: usize) {}
185184
fn foo() {
186-
<|>(1 + 1) + 1;
185+
(1 + 1) + 1;
187186
if (1 + 1) > 10 {
188187
}
189188
@@ -217,7 +216,7 @@ fn foo() {
217216
r"
218217
fn bar(a: usize) {}
219218
fn foo() {
220-
<|>bar(1) + 1;
219+
bar(1) + 1;
221220
if bar(1) > 10 {
222221
}
223222
@@ -251,7 +250,7 @@ fn foo() {
251250
r"
252251
fn bar(a: usize): usize { a }
253252
fn foo() {
254-
<|>(bar(1) as u64) + 1;
253+
(bar(1) as u64) + 1;
255254
if (bar(1) as u64) > 10 {
256255
}
257256
@@ -283,7 +282,7 @@ fn foo() {
283282
}",
284283
r"
285284
fn foo() {
286-
<|>{ 10 + 1 } + 1;
285+
{ 10 + 1 } + 1;
287286
if { 10 + 1 } > 10 {
288287
}
289288
@@ -315,7 +314,7 @@ fn foo() {
315314
}",
316315
r"
317316
fn foo() {
318-
<|>( 10 + 1 ) + 1;
317+
( 10 + 1 ) + 1;
319318
if ( 10 + 1 ) > 10 {
320319
}
321320
@@ -353,7 +352,7 @@ fn foo() {
353352
}",
354353
r"
355354
fn foo() {
356-
<|>let b = bar(10 + 1) * 10;
355+
let b = bar(10 + 1) * 10;
357356
let c = bar(10 + 1) as usize;
358357
}",
359358
);
@@ -373,7 +372,7 @@ fn foo() {
373372
r"
374373
fn foo() {
375374
let x = vec![1, 2, 3];
376-
<|>let b = x[0] * 10;
375+
let b = x[0] * 10;
377376
let c = x[0] as usize;
378377
}",
379378
);
@@ -393,7 +392,7 @@ fn foo() {
393392
r"
394393
fn foo() {
395394
let bar = vec![1];
396-
<|>let b = bar.len() * 10;
395+
let b = bar.len() * 10;
397396
let c = bar.len() as usize;
398397
}",
399398
);
@@ -421,7 +420,7 @@ struct Bar {
421420
422421
fn foo() {
423422
let bar = Bar { foo: 1 };
424-
<|>let b = bar.foo * 10;
423+
let b = bar.foo * 10;
425424
let c = bar.foo as usize;
426425
}",
427426
);
@@ -442,7 +441,7 @@ fn foo() -> Option<usize> {
442441
r"
443442
fn foo() -> Option<usize> {
444443
let bar = Some(1);
445-
<|>let b = bar? * 10;
444+
let b = bar? * 10;
446445
let c = bar? as usize;
447446
None
448447
}",
@@ -462,7 +461,7 @@ fn foo() {
462461
r"
463462
fn foo() {
464463
let bar = 10;
465-
<|>let b = &bar * 10;
464+
let b = &bar * 10;
466465
}",
467466
);
468467
}
@@ -478,7 +477,7 @@ fn foo() {
478477
}",
479478
r"
480479
fn foo() {
481-
<|>let b = (10, 20)[0];
480+
let b = (10, 20)[0];
482481
}",
483482
);
484483
}
@@ -494,7 +493,7 @@ fn foo() {
494493
}",
495494
r"
496495
fn foo() {
497-
<|>let b = [1, 2, 3].len();
496+
let b = [1, 2, 3].len();
498497
}",
499498
);
500499
}
@@ -511,7 +510,7 @@ fn foo() {
511510
}",
512511
r"
513512
fn foo() {
514-
<|>let b = (10 + 20) * 10;
513+
let b = (10 + 20) * 10;
515514
let c = (10 + 20) as usize;
516515
}",
517516
);
@@ -531,7 +530,7 @@ fn foo() {
531530
r"
532531
fn foo() {
533532
let d = 10;
534-
<|>let b = d * 10;
533+
let b = d * 10;
535534
let c = d as usize;
536535
}",
537536
);
@@ -549,7 +548,7 @@ fn foo() {
549548
}",
550549
r"
551550
fn foo() {
552-
<|>let b = { 10 } * 10;
551+
let b = { 10 } * 10;
553552
let c = { 10 } as usize;
554553
}",
555554
);
@@ -569,7 +568,7 @@ fn foo() {
569568
}",
570569
r"
571570
fn foo() {
572-
<|>let b = (10 + 20) * 10;
571+
let b = (10 + 20) * 10;
573572
let c = (10 + 20, 20);
574573
let d = [10 + 20, 10];
575574
let e = (10 + 20);
@@ -588,7 +587,7 @@ fn foo() {
588587
}",
589588
r"
590589
fn foo() {
591-
<|>for i in vec![10, 20] {}
590+
for i in vec![10, 20] {}
592591
}",
593592
);
594593
}
@@ -604,7 +603,7 @@ fn foo() {
604603
}",
605604
r"
606605
fn foo() {
607-
<|>while 1 > 0 {}
606+
while 1 > 0 {}
608607
}",
609608
);
610609
}
@@ -622,7 +621,7 @@ fn foo() {
622621
}",
623622
r"
624623
fn foo() {
625-
<|>loop {
624+
loop {
626625
break 1 + 1;
627626
}
628627
}",
@@ -640,7 +639,7 @@ fn foo() {
640639
}",
641640
r"
642641
fn foo() {
643-
<|>return 1 > 0;
642+
return 1 > 0;
644643
}",
645644
);
646645
}
@@ -656,7 +655,7 @@ fn foo() {
656655
}",
657656
r"
658657
fn foo() {
659-
<|>match 1 > 0 {}
658+
match 1 > 0 {}
660659
}",
661660
);
662661
}

0 commit comments

Comments
 (0)