mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
simplify a bit
This commit is contained in:
parent
8bcf40115f
commit
b36b8970cc
2 changed files with 13 additions and 10 deletions
|
@ -7,6 +7,7 @@ use rustc_hash::FxHashMap;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
attr::Attr,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
|
ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
|
||||||
name::MACRO_RULES,
|
name::MACRO_RULES,
|
||||||
|
@ -532,7 +533,7 @@ where
|
||||||
// `#[macro_use] extern crate` is hoisted to imports macros before collecting
|
// `#[macro_use] extern crate` is hoisted to imports macros before collecting
|
||||||
// any other items.
|
// any other items.
|
||||||
for item in 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 {
|
if let raw::RawItemKind::Import(import_id) = item.kind {
|
||||||
let import = self.raw_items[import_id].clone();
|
let import = self.raw_items[import_id].clone();
|
||||||
if import.is_extern_crate && import.is_macro_use {
|
if import.is_extern_crate && import.is_macro_use {
|
||||||
|
@ -543,7 +544,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
for item in items {
|
for item in items {
|
||||||
if self.is_cfg_enabled(&item.attrs) {
|
if self.is_cfg_enabled(item.attrs()) {
|
||||||
match item.kind {
|
match item.kind {
|
||||||
raw::RawItemKind::Module(m) => self.collect_module(&self.raw_items[m]),
|
raw::RawItemKind::Module(m) => self.collect_module(&self.raw_items[m]),
|
||||||
raw::RawItemKind::Import(import_id) => self
|
raw::RawItemKind::Import(import_id) => self
|
||||||
|
@ -709,12 +710,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_cfg_enabled(&self, attrs: &raw::Attrs) -> bool {
|
fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool {
|
||||||
attrs.as_ref().map_or(true, |attrs| {
|
attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
|
||||||
attrs
|
|
||||||
.iter()
|
|
||||||
.all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,14 +121,20 @@ impl Index<Macro> for RawItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid heap allocation on items without attributes.
|
// Avoid heap allocation on items without attributes.
|
||||||
pub(super) type Attrs = Option<Arc<[Attr]>>;
|
type Attrs = Option<Arc<[Attr]>>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub(super) struct RawItem {
|
pub(super) struct RawItem {
|
||||||
pub(super) attrs: Attrs,
|
attrs: Attrs,
|
||||||
pub(super) kind: RawItemKind,
|
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)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub(super) enum RawItemKind {
|
pub(super) enum RawItemKind {
|
||||||
Module(Module),
|
Module(Module),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue