@@ -9,8 +9,6 @@ use syntax::{
99 AstNode ,
1010} ;
1111
12- use super :: remove_unused_param:: is_trait_impl;
13-
1412// Assist: bind_unused_param
1513//
1614// Binds unused function parameter to an underscore.
@@ -29,12 +27,6 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
2927
3028 let Some ( ast:: Pat :: IdentPat ( ident_pat) ) = param. pat ( ) else { return None } ;
3129
32- let func = param. syntax ( ) . ancestors ( ) . find_map ( ast:: Fn :: cast) ?;
33- if is_trait_impl ( & func) {
34- cov_mark:: hit!( trait_impl) ;
35- return None ;
36- }
37-
3830 let param_def = {
3931 let local = ctx. sema . to_def ( & ident_pat) ?;
4032 Definition :: Local ( local)
@@ -44,6 +36,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
4436 return None ;
4537 }
4638
39+ let func = param. syntax ( ) . ancestors ( ) . find_map ( ast:: Fn :: cast) ?;
4740 let stmt_list = func. body ( ) ?. stmt_list ( ) ?;
4841 let l_curly_range = stmt_list. l_curly_token ( ) ?. text_range ( ) ;
4942 let r_curly_range = stmt_list. r_curly_token ( ) ?. text_range ( ) ;
@@ -55,16 +48,16 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
5548 |builder| {
5649 let line_index = ctx. db ( ) . line_index ( ctx. file_id ( ) ) ;
5750
58- let mut indent = func. indent_level ( ) ;
59- indent. 0 += 1 ;
60- let mut text = format ! ( "\n {indent }let _ = {ident_pat};" ) ;
51+ let indent = func. indent_level ( ) ;
52+ let text_indent = indent + 1 ;
53+ let mut text = format ! ( "\n {text_indent }let _ = {ident_pat};" ) ;
6154
6255 let left_line = line_index. line_col ( l_curly_range. end ( ) ) . line ;
6356 let right_line = line_index. line_col ( r_curly_range. start ( ) ) . line ;
6457
6558 if left_line == right_line {
6659 cov_mark:: hit!( single_line) ;
67- text. push ( '\n' ) ;
60+ text. push_str ( & format ! ( " \n {indent}" ) ) ;
6861 }
6962
7063 builder. insert ( l_curly_range. end ( ) , text) ;
@@ -130,8 +123,7 @@ where T : Default {
130123
131124 #[ test]
132125 fn trait_impl ( ) {
133- cov_mark:: check!( trait_impl) ;
134- check_assist_not_applicable (
126+ check_assist (
135127 bind_unused_param,
136128 r#"
137129trait Trait {
@@ -140,6 +132,16 @@ trait Trait {
140132impl Trait for () {
141133 fn foo($0x: i32) {}
142134}
135+ "# ,
136+ r#"
137+ trait Trait {
138+ fn foo(x: i32);
139+ }
140+ impl Trait for () {
141+ fn foo(x: i32) {
142+ let _ = x;
143+ }
144+ }
143145"# ,
144146 ) ;
145147 }
0 commit comments