Skip to content

Commit f4a77f3

Browse files
committed
Fix renaming owned self to parameter emitting ref
1 parent 65a7893 commit f4a77f3

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

crates/ide/src/references/rename.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ fn text_edit_from_self_param(
280280

281281
let mut replacement_text = String::from(new_name);
282282
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+
};
284288
replacement_text.push_str(type_name.as_str());
285289

286290
Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
@@ -1109,6 +1113,31 @@ impl Foo {
11091113
);
11101114
}
11111115

1116+
#[test]
1117+
fn test_owned_self_to_parameter() {
1118+
check(
1119+
"foo",
1120+
r#"
1121+
struct Foo { i: i32 }
1122+
1123+
impl Foo {
1124+
fn f(<|>self) -> i32 {
1125+
self.i
1126+
}
1127+
}
1128+
"#,
1129+
r#"
1130+
struct Foo { i: i32 }
1131+
1132+
impl Foo {
1133+
fn f(foo: Foo) -> i32 {
1134+
foo.i
1135+
}
1136+
}
1137+
"#,
1138+
);
1139+
}
1140+
11121141
#[test]
11131142
fn test_self_in_path_to_parameter() {
11141143
check(

0 commit comments

Comments
 (0)