From b36b8970ccefa7c98f827caebf6dda71ff3d99c4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 10 Oct 2019 17:16:02 +0300 Subject: simplify a bit --- crates/ra_hir/src/nameres/collector.rs | 13 +++++-------- crates/ra_hir/src/nameres/raw.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 88aee7437..5dacdb0d9 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -7,6 +7,7 @@ use rustc_hash::FxHashMap; use test_utils::tested_by; use crate::{ + attr::Attr, db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, name::MACRO_RULES, @@ -532,7 +533,7 @@ where // `#[macro_use] extern crate` is hoisted to imports macros before collecting // any other items. for item in items { - if self.is_cfg_enabled(&item.attrs) { + if self.is_cfg_enabled(item.attrs()) { if let raw::RawItemKind::Import(import_id) = item.kind { let import = self.raw_items[import_id].clone(); if import.is_extern_crate && import.is_macro_use { @@ -543,7 +544,7 @@ where } for item in items { - if self.is_cfg_enabled(&item.attrs) { + if self.is_cfg_enabled(item.attrs()) { match item.kind { raw::RawItemKind::Module(m) => self.collect_module(&self.raw_items[m]), raw::RawItemKind::Import(import_id) => self @@ -709,12 +710,8 @@ where } } - fn is_cfg_enabled(&self, attrs: &raw::Attrs) -> bool { - attrs.as_ref().map_or(true, |attrs| { - attrs - .iter() - .all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) - }) + fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool { + attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) } } diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 623b343c4..5f93f920f 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -121,14 +121,20 @@ impl Index for RawItems { } // Avoid heap allocation on items without attributes. -pub(super) type Attrs = Option>; +type Attrs = Option>; #[derive(Debug, PartialEq, Eq, Clone)] pub(super) struct RawItem { - pub(super) attrs: Attrs, + attrs: Attrs, pub(super) kind: RawItemKind, } +impl RawItem { + pub(super) fn attrs(&self) -> &[Attr] { + self.attrs.as_ref().map_or(&[], |it| &*it) + } +} + #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub(super) enum RawItemKind { Module(Module), -- cgit v1.2.3