diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 91c64bd4a16..e15b9f88e34 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( let mut replacement_text = String::from(new_name); replacement_text.push_str(": "); - replacement_text.push_str(self_param.mut_token().map_or("&", |_| "&mut ")); + match (self_param.amp_token(), self_param.mut_token()) { + (None, None) => (), + (Some(_), None) => replacement_text.push('&'), + (_, Some(_)) => replacement_text.push_str("&mut "), + }; replacement_text.push_str(type_name.as_str()); Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text)) @@ -1109,6 +1113,31 @@ impl Foo { ); } + #[test] + fn test_owned_self_to_parameter() { + check( + "foo", + r#" +struct Foo { i: i32 } + +impl Foo { + fn f(<|>self) -> i32 { + self.i + } +} +"#, + r#" +struct Foo { i: i32 } + +impl Foo { + fn f(foo: Foo) -> i32 { + foo.i + } +} +"#, + ); + } + #[test] fn test_self_in_path_to_parameter() { check(