From e6fbb94edde4e3f9bdc7a41df67177f1d0d16951 Mon Sep 17 00:00:00 2001 From: Vlad Shcherbina Date: Wed, 14 Oct 2020 21:22:00 +0300 Subject: Fix hover over field pattern shorthand Instead of the information about the field, it now shows the information about the local. Fixes #6146 --- crates/ide/src/hover.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 6290b35bd..632eaf0a0 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -108,7 +108,7 @@ pub(crate) fn hover( let definition = match_ast! { match node { ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)), + ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.into_definition(sema.db)), _ => None, } }; @@ -3232,4 +3232,27 @@ fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); } "#]], ) } + + #[test] + fn hover_field_pat_shorthand_ref_match_ergonomics() { + check( + r#" +struct S { + f: i32, +} + +fn main() { + let s = S { f: 0 }; + let S { f<|> } = &s; +} +"#, + expect![[r#" + *f* + + ```rust + &i32 + ``` + "#]], + ); + } } -- cgit v1.2.3