Skip to content

Commit de9e989

Browse files
bors[bot]maan2003
andauthored
Merge #9209
9209: Don't suggest Remove unused param in trait impls r=Veykril a=Maan2003 See the added test for description Co-authored-by: Maan2003 <manmeetmann2003@gmail.com>
2 parents c62ec3d + 7f71000 commit de9e989

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

crates/ide_assists/src/handlers/remove_unused_param.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt
3737
_ => return None,
3838
};
3939
let func = param.syntax().ancestors().find_map(ast::Fn::cast)?;
40-
let param_position = func.param_list()?.params().position(|it| it == param)?;
4140

41+
// check if fn is in impl Trait for ..
42+
if func
43+
.syntax()
44+
.parent() // AssocItemList
45+
.and_then(|x| x.parent())
46+
.and_then(ast::Impl::cast)
47+
.map_or(false, |imp| imp.trait_().is_some())
48+
{
49+
cov_mark::hit!(trait_impl);
50+
return None;
51+
}
52+
53+
let param_position = func.param_list()?.params().position(|it| it == param)?;
4254
let fn_def = {
4355
let func = ctx.sema.to_def(&func)?;
4456
Definition::ModuleDef(func.into())
@@ -253,6 +265,22 @@ fn main() { foo(9, 2) }
253265
);
254266
}
255267

268+
#[test]
269+
fn trait_impl() {
270+
cov_mark::check!(trait_impl);
271+
check_assist_not_applicable(
272+
remove_unused_param,
273+
r#"
274+
trait Trait {
275+
fn foo(x: i32);
276+
}
277+
impl Trait for () {
278+
fn foo($0x: i32) {}
279+
}
280+
"#,
281+
);
282+
}
283+
256284
#[test]
257285
fn remove_across_files() {
258286
check_assist(

0 commit comments

Comments
 (0)