11use hir:: { db:: ExpandDatabase , Const , Function , HasSource , HirDisplay , TypeAlias } ;
22use ide_db:: {
33 assists:: { Assist , AssistId , AssistKind } ,
4- base_db:: FileRange ,
54 label:: Label ,
65 source_change:: SourceChangeBuilder ,
76} ;
8- use syntax:: { AstNode , SyntaxKind } ;
97use text_edit:: TextRange ;
108
119use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
@@ -64,7 +62,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
6462 Diagnostic :: new (
6563 DiagnosticCode :: RustcHardError ( "E0407" ) ,
6664 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 ) ,
6866 )
6967 . with_fixes ( quickfix_for_redundant_assoc_item (
7068 ctx,
@@ -90,12 +88,11 @@ fn quickfix_for_redundant_assoc_item(
9088 if trait_def_crate != current_crate {
9189 return None ;
9290 }
91+
9392 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 ;
9996
10097 Some ( builder. insert ( where_to_insert. end ( ) , redundant_item_def) )
10198 } ;
0 commit comments