about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-11-25 00:03:48 +0100
committerLukas Wirth <lukastw97@gmail.com>2022-11-25 10:27:54 +0100
commitae0bdffcc9b9e25412f118dfe788cf112fb7e2ef (patch)
tree85e80c916b53b6ef62384ec6515d2088eeca5dd4
parent3c794a34da24398bfc3783966f14e21c59026cb6 (diff)
downloadrust-ae0bdffcc9b9e25412f118dfe788cf112fb7e2ef.tar.gz
rust-ae0bdffcc9b9e25412f118dfe788cf112fb7e2ef.zip
Go to declaration goes to field declaration in pattern and expression shorthands
-rw-r--r--crates/ide/src/goto_declaration.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/ide/src/goto_declaration.rs b/crates/ide/src/goto_declaration.rs
index 5c17b7f4158..c7130a2a4bb 100644
--- a/crates/ide/src/goto_declaration.rs
+++ b/crates/ide/src/goto_declaration.rs
@@ -36,11 +36,11 @@ pub(crate) fn goto_declaration(
                 match parent {
                     ast::NameRef(name_ref) => match NameRefClass::classify(&sema, &name_ref)? {
                         NameRefClass::Definition(it) => Some(it),
-                        _ => None
+                        NameRefClass::FieldShorthand { field_ref, .. } => return field_ref.try_to_nav(db),
                     },
                     ast::Name(name) => match NameClass::classify(&sema, &name)? {
-                        NameClass::Definition(it) => Some(it),
-                        _ => None
+                        NameClass::Definition(it) | NameClass::ConstReference(it) => Some(it),
+                        NameClass::PatFieldShorthand { field_ref, .. } => return field_ref.try_to_nav(db),
                     },
                     _ => None
                 }
@@ -183,4 +183,31 @@ impl Trait for () {
 "#,
         );
     }
+
+    #[test]
+    fn goto_decl_field_pat_shorthand() {
+        check(
+            r#"
+struct Foo { field: u32 }
+           //^^^^^
+fn main() {
+    let Foo { field$0 };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn goto_decl_constructor_shorthand() {
+        check(
+            r#"
+struct Foo { field: u32 }
+           //^^^^^
+fn main() {
+    let field = 0;
+    Foo { field$0 };
+}
+"#,
+        );
+    }
 }