Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-assists/src/handlers/extract_function.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs
index ef4b977fe5..2a0a3839b3 100644
--- a/crates/ide-assists/src/handlers/extract_function.rs
+++ b/crates/ide-assists/src/handlers/extract_function.rs
@@ -2060,7 +2060,7 @@ fn fix_param_usages(
.filter_map(|reference| path_element_of_reference(syntax, reference))
.map(|expr| tm.make_mut(&expr));
- usages_for_param.push((param, usages.collect()));
+ usages_for_param.push((param, usages.dedup().collect()));
}
let res = tm.make_syntax_mut(syntax);
@@ -6233,4 +6233,42 @@ fn $0fun_name(a: i32, b: i32) {
cov_mark::check!(extract_function_in_braces_is_not_applicable);
check_assist_not_applicable(extract_function, r"fn foo(arr: &mut $0[$0i32]) {}");
}
+
+ #[test]
+ fn issue_20965_panic() {
+ check_assist(
+ extract_function,
+ r#"
+//- minicore: fmt
+#[derive(Debug)]
+struct Foo(&'static str);
+
+impl Foo {
+ fn text(&self) -> &str { self.0 }
+}
+
+fn main() {
+ let s = Foo("");
+ $0print!("{}{}", s, s);$0
+ let _ = s.text() == "";
+}"#,
+ r#"
+#[derive(Debug)]
+struct Foo(&'static str);
+
+impl Foo {
+ fn text(&self) -> &str { self.0 }
+}
+
+fn main() {
+ let s = Foo("");
+ fun_name(&s);
+ let _ = s.text() == "";
+}
+
+fn $0fun_name(s: &Foo) {
+ *print!("{}{}", s, s);
+}"#,
+ );
+ }
}