diff options
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 70 | ||||
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 28 |
2 files changed, 84 insertions, 14 deletions
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 1fca6de1f..7d1190af9 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -382,6 +382,76 @@ mod tests { | |||
382 | } | 382 | } |
383 | 383 | ||
384 | #[test] | 384 | #[test] |
385 | fn test_field_shorthand_correct_struct() { | ||
386 | test_rename( | ||
387 | r#" | ||
388 | struct Foo { | ||
389 | i<|>: i32, | ||
390 | } | ||
391 | |||
392 | struct Bar { | ||
393 | i: i32, | ||
394 | } | ||
395 | |||
396 | impl Bar { | ||
397 | fn new(i: i32) -> Self { | ||
398 | Self { i } | ||
399 | } | ||
400 | } | ||
401 | "#, | ||
402 | "j", | ||
403 | r#" | ||
404 | struct Foo { | ||
405 | j: i32, | ||
406 | } | ||
407 | |||
408 | struct Bar { | ||
409 | i: i32, | ||
410 | } | ||
411 | |||
412 | impl Bar { | ||
413 | fn new(i: i32) -> Self { | ||
414 | Self { i } | ||
415 | } | ||
416 | } | ||
417 | "#, | ||
418 | ); | ||
419 | } | ||
420 | |||
421 | #[test] | ||
422 | fn test_shadow_local_for_struct_shorthand() { | ||
423 | test_rename( | ||
424 | r#" | ||
425 | struct Foo { | ||
426 | i: i32, | ||
427 | } | ||
428 | |||
429 | fn baz(i<|>: i32) -> Self { | ||
430 | let x = Foo { i }; | ||
431 | { | ||
432 | let i = 0; | ||
433 | Foo { i } | ||
434 | } | ||
435 | } | ||
436 | "#, | ||
437 | "j", | ||
438 | r#" | ||
439 | struct Foo { | ||
440 | i: i32, | ||
441 | } | ||
442 | |||
443 | fn baz(j: i32) -> Self { | ||
444 | let x = Foo { i: j }; | ||
445 | { | ||
446 | let i = 0; | ||
447 | Foo { i } | ||
448 | } | ||
449 | } | ||
450 | "#, | ||
451 | ); | ||
452 | } | ||
453 | |||
454 | #[test] | ||
385 | fn test_rename_mod() { | 455 | fn test_rename_mod() { |
386 | let (analysis, position) = analysis_and_position( | 456 | let (analysis, position) = analysis_and_position( |
387 | " | 457 | " |
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index b843b5b57..cf78d3e41 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -256,21 +256,21 @@ impl Definition { | |||
256 | access: reference_access(&def, &name_ref), | 256 | access: reference_access(&def, &name_ref), |
257 | }); | 257 | }); |
258 | } | 258 | } |
259 | Some(NameRefClass::FieldShorthand { local, field: _ }) => { | 259 | Some(NameRefClass::FieldShorthand { local, field }) => { |
260 | let kind = match self { | 260 | match self { |
261 | Definition::StructField(_) => { | 261 | Definition::StructField(_) if &field == self => refs.push(Reference { |
262 | ReferenceKind::StructFieldShorthandForField | 262 | file_range: sema.original_range(name_ref.syntax()), |
263 | } | 263 | kind: ReferenceKind::StructFieldShorthandForField, |
264 | Definition::Local(_) => ReferenceKind::StructFieldShorthandForLocal, | 264 | access: reference_access(&field, &name_ref), |
265 | _ => continue, | 265 | }), |
266 | Definition::Local(l) if &local == l => refs.push(Reference { | ||
267 | file_range: sema.original_range(name_ref.syntax()), | ||
268 | kind: ReferenceKind::StructFieldShorthandForLocal, | ||
269 | access: reference_access(&Definition::Local(local), &name_ref), | ||
270 | }), | ||
271 | |||
272 | _ => {} // not a usage | ||
266 | }; | 273 | }; |
267 | |||
268 | let file_range = sema.original_range(name_ref.syntax()); | ||
269 | refs.push(Reference { | ||
270 | file_range, | ||
271 | kind, | ||
272 | access: reference_access(&Definition::Local(local), &name_ref), | ||
273 | }); | ||
274 | } | 274 | } |
275 | _ => {} // not a usage | 275 | _ => {} // not a usage |
276 | } | 276 | } |