Don't suggest Remove unused param in trait impls

This commit is contained in:
Maan2003 2021-06-11 12:24:56 +05:30
parent c62ec3d998
commit 7f71000c12
No known key found for this signature in database
GPG Key ID: E9AF024BA63C70ED

View File

@ -37,8 +37,20 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt
_ => return None,
};
let func = param.syntax().ancestors().find_map(ast::Fn::cast)?;
let param_position = func.param_list()?.params().position(|it| it == param)?;
// check if fn is in impl Trait for ..
if func
.syntax()
.parent() // AssocItemList
.and_then(|x| x.parent())
.and_then(ast::Impl::cast)
.map_or(false, |imp| imp.trait_().is_some())
{
cov_mark::hit!(trait_impl);
return None;
}
let param_position = func.param_list()?.params().position(|it| it == param)?;
let fn_def = {
let func = ctx.sema.to_def(&func)?;
Definition::ModuleDef(func.into())
@ -253,6 +265,22 @@ fn main() { foo(9, 2) }
);
}
#[test]
fn trait_impl() {
cov_mark::check!(trait_impl);
check_assist_not_applicable(
remove_unused_param,
r#"
trait Trait {
fn foo(x: i32);
}
impl Trait for () {
fn foo($0x: i32) {}
}
"#,
);
}
#[test]
fn remove_across_files() {
check_assist(