From e78286c8e88d31045d354320a1d29bbd75405027 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Thu, 10 Jan 2019 02:07:42 +0100 Subject: Save variant names in EnumData to reduce needless queries We already have their names when anyway, and when in all (current) situations where we're interested in an Enum's variants, we want their names. --- crates/ra_hir/src/code_model_impl/module.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl/module.rs') diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index d7d62e863..878dc37c8 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -142,20 +142,10 @@ impl Module { Def::Enum(e) => { if segments.len() == idx + 1 { // enum variant - let matching_variant = e.variants(db)?.map(|variants| { - variants - .into_iter() - // FIXME: replace by match lol - .find(|variant| { - variant - .name(db) - .map(|o| o.map(|ref n| n == name)) - .unwrap_or(Some(false)) - .unwrap_or(false) - }) - }); - - if let Some(Some(variant)) = matching_variant { + let matching_variant = + e.variants(db)?.into_iter().find(|(n, _variant)| n == name); + + if let Some((_n, variant)) = matching_variant { return Ok(PerNs::both(variant.def_id(), e.def_id())); } else { return Ok(PerNs::none()); -- cgit v1.2.3