1- use hir:: { db:: ExpandDatabase , Const , Function , HasSource , TypeAlias } ;
1+ use hir:: { Const , Function , HasSource , TypeAlias } ;
2+ use ide_db:: base_db:: FileRange ;
23
34use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
45
@@ -13,31 +14,37 @@ pub(crate) fn trait_impl_redundant_assoc_item(
1314 let assoc_item = d. assoc_item . 1 ;
1415 let db = ctx. sema . db ;
1516
16- let range = db . parse_or_expand ( d . file_id ) . text_range ( ) ;
17+ let default_range = d . impl_ . syntax_node_ptr ( ) . text_range ( ) ;
1718 let trait_name = d. trait_ . name ( db) . to_smol_str ( ) ;
1819
1920 let ( redundant_item_name, diagnostic_range) = match assoc_item {
2021 hir:: AssocItem :: Function ( id) => (
2122 format ! ( "`fn {}`" , name. display( db) ) ,
22- Function :: from ( id) . source ( db) . map ( |it| it. syntax ( ) . value . text_range ( ) ) . unwrap_or ( range) ,
23+ Function :: from ( id)
24+ . source ( db)
25+ . map ( |it| it. syntax ( ) . value . text_range ( ) )
26+ . unwrap_or ( default_range) ,
2327 ) ,
2428 hir:: AssocItem :: Const ( id) => (
2529 format ! ( "`const {}`" , name. display( db) ) ,
26- Const :: from ( id) . source ( db) . map ( |it| it. syntax ( ) . value . text_range ( ) ) . unwrap_or ( range) ,
30+ Const :: from ( id)
31+ . source ( db)
32+ . map ( |it| it. syntax ( ) . value . text_range ( ) )
33+ . unwrap_or ( default_range) ,
2734 ) ,
2835 hir:: AssocItem :: TypeAlias ( id) => (
2936 format ! ( "`type {}`" , name. display( db) ) ,
3037 TypeAlias :: from ( id)
3138 . source ( db)
3239 . map ( |it| it. syntax ( ) . value . text_range ( ) )
33- . unwrap_or ( range ) ,
40+ . unwrap_or ( default_range ) ,
3441 ) ,
3542 } ;
3643
3744 Diagnostic :: new (
3845 DiagnosticCode :: RustcHardError ( "E0407" ) ,
3946 format ! ( "{redundant_item_name} is not a member of trait `{trait_name}`" ) ,
40- diagnostic_range,
47+ FileRange { file_id : d . file_id . file_id ( ) . unwrap ( ) , range : diagnostic_range } ,
4148 )
4249}
4350
0 commit comments