From fa2ea8f494d8434da705dc0e0f047f3bd7503af9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Apr 2020 22:05:06 +0200 Subject: Fix goto definition for record patterns --- crates/ra_ide/src/goto_definition.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 8aed94d16..9998ca5a3 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -62,10 +62,9 @@ pub(crate) enum ReferenceResult { impl ReferenceResult { fn to_vec(self) -> Vec { - use self::ReferenceResult::*; match self { - Exact(target) => vec![target], - Approximate(vec) => vec, + ReferenceResult::Exact(target) => vec![target], + ReferenceResult::Approximate(vec) => vec, } } } @@ -74,8 +73,6 @@ pub(crate) fn reference_definition( sema: &Semantics, name_ref: &ast::NameRef, ) -> ReferenceResult { - use self::ReferenceResult::*; - let name_kind = classify_name_ref(sema, name_ref); if let Some(def) = name_kind { let def = def.definition(); @@ -91,7 +88,7 @@ pub(crate) fn reference_definition( .into_iter() .map(|s| s.to_nav(sema.db)) .collect(); - Approximate(navs) + ReferenceResult::Approximate(navs) } #[cfg(test)] @@ -398,6 +395,25 @@ mod tests { ); } + #[test] + fn goto_def_for_record_pat_fields() { + covers!(ra_ide_db::goto_def_for_record_field_pats); + check_goto( + r" + //- /lib.rs + struct Foo { + spam: u32, + } + + fn bar(foo: Foo) -> Foo { + let Foo { spam<|>: _, } = foo + } + ", + "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)", + "spam: u32|spam", + ); + } + #[test] fn goto_def_for_record_fields_macros() { check_goto( -- cgit v1.2.3