@@ -9,8 +9,6 @@ use syntax::{
9
9
AstNode ,
10
10
} ;
11
11
12
- use super :: remove_unused_param:: is_trait_impl;
13
-
14
12
// Assist: bind_unused_param
15
13
//
16
14
// Binds unused function parameter to an underscore.
@@ -29,12 +27,6 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
29
27
30
28
let Some ( ast:: Pat :: IdentPat ( ident_pat) ) = param. pat ( ) else { return None } ;
31
29
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
-
38
30
let param_def = {
39
31
let local = ctx. sema . to_def ( & ident_pat) ?;
40
32
Definition :: Local ( local)
@@ -44,6 +36,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
44
36
return None ;
45
37
}
46
38
39
+ let func = param. syntax ( ) . ancestors ( ) . find_map ( ast:: Fn :: cast) ?;
47
40
let stmt_list = func. body ( ) ?. stmt_list ( ) ?;
48
41
let l_curly_range = stmt_list. l_curly_token ( ) ?. text_range ( ) ;
49
42
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
55
48
|builder| {
56
49
let line_index = ctx. db ( ) . line_index ( ctx. file_id ( ) ) ;
57
50
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};" ) ;
61
54
62
55
let left_line = line_index. line_col ( l_curly_range. end ( ) ) . line ;
63
56
let right_line = line_index. line_col ( r_curly_range. start ( ) ) . line ;
64
57
65
58
if left_line == right_line {
66
59
cov_mark:: hit!( single_line) ;
67
- text. push ( '\n' ) ;
60
+ text. push_str ( & format ! ( " \n {indent}" ) ) ;
68
61
}
69
62
70
63
builder. insert ( l_curly_range. end ( ) , text) ;
@@ -130,8 +123,7 @@ where T : Default {
130
123
131
124
#[ test]
132
125
fn trait_impl ( ) {
133
- cov_mark:: check!( trait_impl) ;
134
- check_assist_not_applicable (
126
+ check_assist (
135
127
bind_unused_param,
136
128
r#"
137
129
trait Trait {
@@ -140,6 +132,16 @@ trait Trait {
140
132
impl Trait for () {
141
133
fn foo($0x: i32) {}
142
134
}
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
+ }
143
145
"# ,
144
146
) ;
145
147
}
0 commit comments