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>
This commit is contained in:
bors[bot] 2021-06-11 10:05:28 +00:00 committed by GitHub
commit de9e989cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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(