aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/references/rename.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 91c64bd4a..e15b9f88e 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -280,7 +280,11 @@ fn text_edit_from_self_param(
280 280
281 let mut replacement_text = String::from(new_name); 281 let mut replacement_text = String::from(new_name);
282 replacement_text.push_str(": "); 282 replacement_text.push_str(": ");
283 replacement_text.push_str(self_param.mut_token().map_or("&", |_| "&mut ")); 283 match (self_param.amp_token(), self_param.mut_token()) {
284 (None, None) => (),
285 (Some(_), None) => replacement_text.push('&'),
286 (_, Some(_)) => replacement_text.push_str("&mut "),
287 };
284 replacement_text.push_str(type_name.as_str()); 288 replacement_text.push_str(type_name.as_str());
285 289
286 Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text)) 290 Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
@@ -1110,6 +1114,31 @@ impl Foo {
1110 } 1114 }
1111 1115
1112 #[test] 1116 #[test]
1117 fn test_owned_self_to_parameter() {
1118 check(
1119 "foo",
1120 r#"
1121struct Foo { i: i32 }
1122
1123impl Foo {
1124 fn f(<|>self) -> i32 {
1125 self.i
1126 }
1127}
1128"#,
1129 r#"
1130struct Foo { i: i32 }
1131
1132impl Foo {
1133 fn f(foo: Foo) -> i32 {
1134 foo.i
1135 }
1136}
1137"#,
1138 );
1139 }
1140
1141 #[test]
1113 fn test_self_in_path_to_parameter() { 1142 fn test_self_in_path_to_parameter() {
1114 check( 1143 check(
1115 "foo", 1144 "foo",