Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion crates/ide-assists/src/handlers/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -6233,4 +6233,64 @@ 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);
}"#,
);
}

#[test]
fn parameter_is_added_used_in_eq_expression_in_macro() {
check_assist(
extract_function,
r#"
//- minicore: fmt
fn foo() {
let v = 123;
$0print!("{v:?}{}", v == 123);$0
}"#,
r#"
fn foo() {
let v = 123;
fun_name(v);
}

fn $0fun_name(v: i32) {
print!("{v:?}{}", v == 123);
}"#,
);
}
}
2 changes: 1 addition & 1 deletion crates/parser/src/grammar/expressions/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
if p.eat(T![,]) {
while !p.at(EOF) && !p.at(T![')']) {
let m = p.start();
if p.at(IDENT) && p.nth_at(1, T![=]) {
if p.at(IDENT) && p.nth_at(1, T![=]) && !p.nth_at(2, T![=]) {
name(p);
p.bump(T![=]);
}
Expand Down