@@ -8,7 +8,7 @@ use ide_db::{
8
8
use syntax:: { ast, AstNode , AstPtr } ;
9
9
use text_edit:: TextEdit ;
10
10
11
- use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
11
+ use crate :: { adjusted_display_range_new , Diagnostic , DiagnosticCode , DiagnosticsContext } ;
12
12
13
13
// Diagnostic: unresolved-field
14
14
//
@@ -22,15 +22,24 @@ pub(crate) fn unresolved_field(
22
22
} else {
23
23
""
24
24
} ;
25
- Diagnostic :: new_with_syntax_node_ptr (
26
- ctx,
25
+ Diagnostic :: new (
27
26
DiagnosticCode :: RustcHardError ( "E0559" ) ,
28
27
format ! (
29
28
"no field `{}` on type `{}`{method_suffix}" ,
30
29
d. name. display( ctx. sema. db) ,
31
30
d. receiver. display( ctx. sema. db)
32
31
) ,
33
- d. expr . clone ( ) . map ( |it| it. into ( ) ) ,
32
+ adjusted_display_range_new ( ctx, d. expr , & |expr| {
33
+ Some (
34
+ match expr {
35
+ ast:: Expr :: MethodCallExpr ( it) => it. name_ref ( ) ,
36
+ ast:: Expr :: FieldExpr ( it) => it. name_ref ( ) ,
37
+ _ => None ,
38
+ } ?
39
+ . syntax ( )
40
+ . text_range ( ) ,
41
+ )
42
+ } ) ,
34
43
)
35
44
. with_fixes ( fixes ( ctx, d) )
36
45
. experimental ( )
@@ -79,7 +88,7 @@ mod tests {
79
88
r#"
80
89
fn main() {
81
90
().foo;
82
- // ^^^ ^^^ error: no field `foo` on type `()`
91
+ // ^^^ error: no field `foo` on type `()`
83
92
}
84
93
"# ,
85
94
) ;
@@ -95,7 +104,7 @@ impl Foo {
95
104
}
96
105
fn foo() {
97
106
Foo.bar;
98
- // ^^^^ ^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
107
+ // ^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
99
108
}
100
109
"# ,
101
110
) ;
@@ -112,7 +121,7 @@ trait Bar {
112
121
impl Bar for Foo {}
113
122
fn foo() {
114
123
Foo.bar;
115
- // ^^^^ ^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
124
+ // ^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
116
125
}
117
126
"# ,
118
127
) ;
@@ -131,7 +140,7 @@ impl Bar for Foo {
131
140
}
132
141
fn foo() {
133
142
Foo.bar;
134
- // ^^^^ ^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
143
+ // ^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
135
144
}
136
145
"# ,
137
146
) ;
0 commit comments