1
1
use hir:: { db:: ExpandDatabase , Const , Function , HasSource , HirDisplay , TypeAlias } ;
2
2
use ide_db:: {
3
3
assists:: { Assist , AssistId , AssistKind } ,
4
- base_db:: FileRange ,
5
4
label:: Label ,
6
5
source_change:: SourceChangeBuilder ,
7
6
} ;
8
- use syntax:: { AstNode , SyntaxKind } ;
9
7
use text_edit:: TextRange ;
10
8
11
9
use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
@@ -64,7 +62,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
64
62
Diagnostic :: new (
65
63
DiagnosticCode :: RustcHardError ( "E0407" ) ,
66
64
format ! ( "{redundant_item_name} is not a member of trait `{trait_name}`" ) ,
67
- FileRange { file_id : d. file_id . file_id ( ) . unwrap ( ) , range : diagnostic_range } ,
65
+ hir :: InFile :: new ( d. file_id , diagnostic_range ) . original_node_file_range_rooted ( db ) ,
68
66
)
69
67
. with_fixes ( quickfix_for_redundant_assoc_item (
70
68
ctx,
@@ -90,12 +88,11 @@ fn quickfix_for_redundant_assoc_item(
90
88
if trait_def_crate != current_crate {
91
89
return None ;
92
90
}
91
+
93
92
let trait_def = d. trait_ . source ( db) ?. value ;
94
- let where_to_insert = trait_def
95
- . syntax ( )
96
- . descendants_with_tokens ( )
97
- . find ( |it| it. kind ( ) == SyntaxKind :: L_CURLY )
98
- . map ( |it| it. text_range ( ) ) ?;
93
+ let l_curly = trait_def. assoc_item_list ( ) ?. l_curly_token ( ) ?. text_range ( ) ;
94
+ let where_to_insert =
95
+ hir:: InFile :: new ( d. file_id , l_curly) . original_node_file_range_rooted ( db) . range ;
99
96
100
97
Some ( builder. insert ( where_to_insert. end ( ) , redundant_item_def) )
101
98
} ;
0 commit comments