@@ -326,12 +326,16 @@ pub fn source_edit_from_references(
326
326
327
327
fn source_edit_from_name ( name : & ast:: Name , new_name : & str ) -> Option < ( TextRange , String ) > {
328
328
if let Some ( _) = ast:: RecordPatField :: for_field_name ( name) {
329
- // FIXME: instead of splitting the shorthand, recursively trigger a rename of the
330
- // other name https://github.com/rust-analyzer/rust-analyzer/issues/6547
331
329
if let Some ( ident_pat) = name. syntax ( ) . parent ( ) . and_then ( ast:: IdentPat :: cast) {
330
+ cov_mark:: hit!( rename_record_pat_field_name_split) ;
331
+ // Foo { ref mut field } -> Foo { new_name: ref mut field }
332
+ // ^ insert `new_name: `
333
+
334
+ // FIXME: instead of splitting the shorthand, recursively trigger a rename of the
335
+ // other name https://github.com/rust-analyzer/rust-analyzer/issues/6547
332
336
return Some ( (
333
337
TextRange :: empty ( ident_pat. syntax ( ) . text_range ( ) . start ( ) ) ,
334
- [ new_name , " : "] . concat ( ) ,
338
+ format ! ( "{} : ", new_name ) ,
335
339
) ) ;
336
340
}
337
341
}
@@ -347,21 +351,29 @@ fn source_edit_from_name_ref(
347
351
if let Some ( record_field) = ast:: RecordExprField :: for_name_ref ( name_ref) {
348
352
let rcf_name_ref = record_field. name_ref ( ) ;
349
353
let rcf_expr = record_field. expr ( ) ;
350
- match ( rcf_name_ref, rcf_expr. and_then ( |it| it. name_ref ( ) ) ) {
354
+ match & ( rcf_name_ref, rcf_expr. and_then ( |it| it. name_ref ( ) ) ) {
351
355
// field: init-expr, check if we can use a field init shorthand
352
356
( Some ( field_name) , Some ( init) ) => {
353
- if field_name == * name_ref {
357
+ if field_name == name_ref {
354
358
if init. text ( ) == new_name {
355
359
cov_mark:: hit!( test_rename_field_put_init_shorthand) ;
360
+ // Foo { field: local } -> Foo { local }
361
+ // ^^^^^^^^ delete this
362
+ // FIXME: Actually delete this instead of replacing the entire thing
363
+
356
364
// same names, we can use a shorthand here instead.
357
365
// we do not want to erase attributes hence this range start
358
366
let s = field_name. syntax ( ) . text_range ( ) . start ( ) ;
359
367
let e = record_field. syntax ( ) . text_range ( ) . end ( ) ;
360
368
return Some ( ( TextRange :: new ( s, e) , new_name. to_owned ( ) ) ) ;
361
369
}
362
- } else if init == * name_ref {
370
+ } else if init == name_ref {
363
371
if field_name. text ( ) == new_name {
364
372
cov_mark:: hit!( test_rename_local_put_init_shorthand) ;
373
+ // Foo { field: local } -> Foo { field }
374
+ // ^^^^^^^ delete this
375
+ // FIXME: Actually delete this instead of replacing the entire thing
376
+
365
377
// same names, we can use a shorthand here instead.
366
378
// we do not want to erase attributes hence this range start
367
379
let s = field_name. syntax ( ) . text_range ( ) . start ( ) ;
@@ -374,11 +386,15 @@ fn source_edit_from_name_ref(
374
386
// init shorthand
375
387
( None , Some ( _) ) if matches ! ( def, Definition :: Field ( _) ) => {
376
388
cov_mark:: hit!( test_rename_field_in_field_shorthand) ;
389
+ // Foo { field } -> Foo { new_name: field }
390
+ // ^ insert `new_name: `
377
391
let s = name_ref. syntax ( ) . text_range ( ) . start ( ) ;
378
392
Some ( ( TextRange :: empty ( s) , format ! ( "{}: " , new_name) ) )
379
393
}
380
394
( None , Some ( _) ) if matches ! ( def, Definition :: Local ( _) ) => {
381
395
cov_mark:: hit!( test_rename_local_in_field_shorthand) ;
396
+ // Foo { field } -> Foo { field: new_name }
397
+ // ^ insert `: new_name`
382
398
let s = name_ref. syntax ( ) . text_range ( ) . end ( ) ;
383
399
Some ( ( TextRange :: empty ( s) , format ! ( ": {}" , new_name) ) )
384
400
}
@@ -395,6 +411,11 @@ fn source_edit_from_name_ref(
395
411
// field name is being renamed
396
412
if pat. name ( ) . map_or ( false , |it| it. text ( ) == new_name) {
397
413
cov_mark:: hit!( test_rename_field_put_init_shorthand_pat) ;
414
+ // Foo { field: ref mut local } -> Foo { ref mut field }
415
+ // ^^^^^^^ delete this
416
+ // ^^^^^ replace this with `field`
417
+ // FIXME: do this the way its written here
418
+
398
419
// same names, we can use a shorthand here instead/
399
420
// we do not want to erase attributes hence this range start
400
421
let s = field_name. syntax ( ) . text_range ( ) . start ( ) ;
0 commit comments