Skip to content

Commit 13cf3b4

Browse files
bors[bot]Veykril
andauthored
Merge #6513
6513: Support qualified function calls in remove_unused_param r=Veykril a=Veykril Also adds a test to check that it removes unused params across files. Co-authored-by: Lukas Wirth <[email protected]>
2 parents e3227bd + b6e2b28 commit 13cf3b4

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

crates/assists/src/handlers/remove_unused_param.rs

Lines changed: 82 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);
@@ -128,4 +176,37 @@ fn main() { foo(9, 2) }
128176
"#,
129177
);
130178
}
179+
180+
#[test]
181+
fn remove_across_files() {
182+
check_assist(
183+
remove_unused_param,
184+
r#"
185+
//- /main.rs
186+
fn foo(x: i32, <|>y: i32) { x; }
187+
188+
mod foo;
189+
190+
//- /foo.rs
191+
use super::foo;
192+
193+
fn bar() {
194+
let _ = foo(1, 2);
195+
}
196+
"#,
197+
r#"
198+
//- /main.rs
199+
fn foo(x: i32) { x; }
200+
201+
mod foo;
202+
203+
//- /foo.rs
204+
use super::foo;
205+
206+
fn bar() {
207+
let _ = foo(1);
208+
}
209+
"#,
210+
)
211+
}
131212
}

0 commit comments

Comments
 (0)