From 7f71000c12248b0d19833dcd749ca1ec5871dda3 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Fri, 11 Jun 2021 12:24:56 +0530 Subject: Don't suggest Remove unused param in trait impls --- .../src/handlers/remove_unused_param.rs | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ide_assists/src/handlers/remove_unused_param.rs b/crates/ide_assists/src/handlers/remove_unused_param.rs index 2699d2861..fabfe7e93 100644 --- a/crates/ide_assists/src/handlers/remove_unused_param.rs +++ b/crates/ide_assists/src/handlers/remove_unused_param.rs @@ -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( -- cgit v1.2.3