Skip to content

Commit b6e2b28

Browse files
committed
Support qualified function calls in remove_unused_param
1 parent 949c580 commit b6e2b28

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

crates/assists/src/handlers/remove_unused_param.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ fn process_usage(
7373
let source_file = ctx.sema.parse(usage.file_range.file_id);
7474
let call_expr: ast::CallExpr =
7575
find_node_at_range(source_file.syntax(), usage.file_range.range)?;
76-
if call_expr.expr()?.syntax().text_range() != usage.file_range.range {
76+
let call_expr_range = call_expr.expr()?.syntax().text_range();
77+
if !call_expr_range.contains_range(usage.file_range.range) {
7778
return None;
7879
}
7980
let arg = call_expr.arg_list()?.args().nth(arg_to_remove)?;
@@ -117,6 +118,53 @@ fn b() { foo(9, ) }
117118
);
118119
}
119120

121+
#[test]
122+
fn remove_unused_qualified_call() {
123+
check_assist(
124+
remove_unused_param,
125+
r#"
126+
mod bar { pub fn foo(x: i32, <|>y: i32) { x; } }
127+
fn b() { bar::foo(9, 2) }
128+
"#,
129+
r#"
130+
mod bar { pub fn foo(x: i32) { x; } }
131+
fn b() { bar::foo(9) }
132+
"#,
133+
);
134+
}
135+
136+
#[test]
137+
fn remove_unused_turbofished_func() {
138+
check_assist(
139+
remove_unused_param,
140+
r#"
141+
pub fn foo<T>(x: T, <|>y: i32) { x; }
142+
fn b() { foo::<i32>(9, 2) }
143+
"#,
144+
r#"
145+
pub fn foo<T>(x: T) { x; }
146+
fn b() { foo::<i32>(9) }
147+
"#,
148+
);
149+
}
150+
151+
#[test]
152+
fn remove_unused_generic_unused_param_func() {
153+
check_assist(
154+
remove_unused_param,
155+
r#"
156+
pub fn foo<T>(x: i32, <|>y: T) { x; }
157+
fn b() { foo::<i32>(9, 2) }
158+
fn b2() { foo(9, 2) }
159+
"#,
160+
r#"
161+
pub fn foo<T>(x: i32) { x; }
162+
fn b() { foo::<i32>(9) }
163+
fn b2() { foo(9) }
164+
"#,
165+
);
166+
}
167+
120168
#[test]
121169
fn keep_used() {
122170
mark::check!(keep_used);

0 commit comments

Comments
 (0)