1
- use hir:: { db:: ExpandDatabase , Const , Function , HasSource , TypeAlias } ;
1
+ use hir:: { Const , Function , HasSource , TypeAlias } ;
2
+ use ide_db:: base_db:: FileRange ;
2
3
3
4
use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
4
5
@@ -13,31 +14,37 @@ pub(crate) fn trait_impl_redundant_assoc_item(
13
14
let assoc_item = d. assoc_item . 1 ;
14
15
let db = ctx. sema . db ;
15
16
16
- let range = db . parse_or_expand ( d . file_id ) . text_range ( ) ;
17
+ let default_range = d . impl_ . syntax_node_ptr ( ) . text_range ( ) ;
17
18
let trait_name = d. trait_ . name ( db) . to_smol_str ( ) ;
18
19
19
20
let ( redundant_item_name, diagnostic_range) = match assoc_item {
20
21
hir:: AssocItem :: Function ( id) => (
21
22
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) ,
23
27
) ,
24
28
hir:: AssocItem :: Const ( id) => (
25
29
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) ,
27
34
) ,
28
35
hir:: AssocItem :: TypeAlias ( id) => (
29
36
format ! ( "`type {}`" , name. display( db) ) ,
30
37
TypeAlias :: from ( id)
31
38
. source ( db)
32
39
. map ( |it| it. syntax ( ) . value . text_range ( ) )
33
- . unwrap_or ( range ) ,
40
+ . unwrap_or ( default_range ) ,
34
41
) ,
35
42
} ;
36
43
37
44
Diagnostic :: new (
38
45
DiagnosticCode :: RustcHardError ( "E0407" ) ,
39
46
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 } ,
41
48
)
42
49
}
43
50
0 commit comments