@@ -8,7 +8,7 @@ use ide_db::{
88use syntax:: { ast, AstNode , AstPtr } ;
99use text_edit:: TextEdit ;
1010
11- use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
11+ use crate :: { adjusted_display_range_new , Diagnostic , DiagnosticCode , DiagnosticsContext } ;
1212
1313// Diagnostic: unresolved-field
1414//
@@ -22,15 +22,24 @@ pub(crate) fn unresolved_field(
2222 } else {
2323 ""
2424 } ;
25- Diagnostic :: new_with_syntax_node_ptr (
26- ctx,
25+ Diagnostic :: new (
2726 DiagnosticCode :: RustcHardError ( "E0559" ) ,
2827 format ! (
2928 "no field `{}` on type `{}`{method_suffix}" ,
3029 d. name. display( ctx. sema. db) ,
3130 d. receiver. display( ctx. sema. db)
3231 ) ,
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+ } ) ,
3443 )
3544 . with_fixes ( fixes ( ctx, d) )
3645 . experimental ( )
@@ -79,7 +88,7 @@ mod tests {
7988 r#"
8089fn main() {
8190 ().foo;
82- // ^^^ ^^^ error: no field `foo` on type `()`
91+ // ^^^ error: no field `foo` on type `()`
8392}
8493"# ,
8594 ) ;
@@ -95,7 +104,7 @@ impl Foo {
95104}
96105fn foo() {
97106 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
99108}
100109"# ,
101110 ) ;
@@ -112,7 +121,7 @@ trait Bar {
112121impl Bar for Foo {}
113122fn foo() {
114123 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
116125}
117126"# ,
118127 ) ;
@@ -131,7 +140,7 @@ impl Bar for Foo {
131140}
132141fn foo() {
133142 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
135144}
136145"# ,
137146 ) ;
0 commit comments