Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/rename.rs')
| -rw-r--r-- | crates/ide/src/rename.rs | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index d0a49d1f37..9d452f40ba 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -274,6 +274,7 @@ mod tests { use super::{RangeInfo, RenameError}; + #[track_caller] fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) { let ra_fixture_after = &trim_indent(ra_fixture_after); let (analysis, position) = fixture::position(ra_fixture_before); @@ -1332,11 +1333,73 @@ fn foo(foo: Foo) { struct Foo { baz: i32 } fn foo(foo: Foo) { - let Foo { ref baz @ qux } = foo; + let Foo { baz: ref baz @ qux } = foo; let _ = qux; } "#, ); + check( + "baz", + r#" +struct Foo { i$0: i32 } + +fn foo(foo: Foo) { + let Foo { i: ref baz } = foo; + let _ = qux; +} +"#, + r#" +struct Foo { baz: i32 } + +fn foo(foo: Foo) { + let Foo { ref baz } = foo; + let _ = qux; +} +"#, + ); + } + + #[test] + fn test_struct_local_pat_into_shorthand() { + cov_mark::check!(test_rename_local_put_init_shorthand_pat); + check( + "field", + r#" +struct Foo { field: i32 } + +fn foo(foo: Foo) { + let Foo { field: qux$0 } = foo; + let _ = qux; +} +"#, + r#" +struct Foo { field: i32 } + +fn foo(foo: Foo) { + let Foo { field } = foo; + let _ = field; +} +"#, + ); + check( + "field", + r#" +struct Foo { field: i32 } + +fn foo(foo: Foo) { + let Foo { field: x @ qux$0 } = foo; + let _ = qux; +} +"#, + r#" +struct Foo { field: i32 } + +fn foo(foo: Foo) { + let Foo { field: x @ field } = foo; + let _ = field; +} +"#, + ); } #[test] @@ -1390,7 +1453,7 @@ struct Foo { i: i32 } -fn foo(Foo { i }: foo) -> i32 { +fn foo(Foo { i }: Foo) -> i32 { i$0 } "#, @@ -1399,7 +1462,7 @@ struct Foo { i: i32 } -fn foo(Foo { i: bar }: foo) -> i32 { +fn foo(Foo { i: bar }: Foo) -> i32 { bar } "#, @@ -1408,6 +1471,7 @@ fn foo(Foo { i: bar }: foo) -> i32 { #[test] fn test_struct_field_complex_ident_pat() { + cov_mark::check!(rename_record_pat_field_name_split); check( "baz", r#" |