X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir_def%2Fsrc%2Fitem_tree.rs;h=9a433b61c8ee61084403e86057d1cb42bc6462c5;hb=1d103cf087c574f66279490ffef8c76178aea5cc;hp=b8e09e3af3138513977b95319b56074b34136d84;hpb=28b5334580e5814d102b006e310ca0d1f03cdd72;p=rust.git diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index b8e09e3af31..9a433b61c8e 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -11,8 +11,8 @@ sync::Arc, }; -use arena::{Arena, Idx, RawId}; -use ast::{AstNode, AttrsOwner, NameOwner, StructKind}; +use ast::{AstNode, NameOwner, StructKind}; +use base_db::CrateId; use either::Either; use hir_expand::{ ast_id_map::FileAstId, @@ -20,13 +20,14 @@ name::{name, AsName, Name}, HirFileId, InFile, }; +use la_arena::{Arena, Idx, RawIdx}; use rustc_hash::FxHashMap; use smallvec::SmallVec; use syntax::{ast, match_ast}; use test_utils::mark; use crate::{ - attr::Attrs, + attr::{Attrs, RawAttrs}, db::DefDatabase, generics::GenericParams, path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind}, @@ -67,7 +68,7 @@ impl GenericParamsId { #[derive(Debug, Eq, PartialEq)] pub struct ItemTree { top_level: SmallVec<[ModItem; 1]>, - attrs: FxHashMap, + attrs: FxHashMap, inner_items: FxHashMap, SmallVec<[ModItem; 1]>>, data: Option>, @@ -88,7 +89,7 @@ pub fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc { - top_attrs = Some(Attrs::new(&file, &hygiene)); + top_attrs = Some(RawAttrs::new(&file, &hygiene)); ctx.lower_module_items(&file) }, ast::MacroItems(items) => { @@ -180,12 +181,16 @@ pub fn top_level_items(&self) -> &[ModItem] { } /// Returns the inner attributes of the source file. - pub fn top_level_attrs(&self) -> &Attrs { - self.attrs.get(&AttrOwner::TopLevel).unwrap_or(&Attrs::EMPTY) + pub fn top_level_attrs(&self, db: &dyn DefDatabase, krate: CrateId) -> Attrs { + self.attrs.get(&AttrOwner::TopLevel).unwrap_or(&RawAttrs::EMPTY).clone().filter(db, krate) } - pub fn attrs(&self, of: AttrOwner) -> &Attrs { - self.attrs.get(&of).unwrap_or(&Attrs::EMPTY) + pub(crate) fn raw_attrs(&self, of: AttrOwner) -> &RawAttrs { + self.attrs.get(&of).unwrap_or(&RawAttrs::EMPTY) + } + + pub fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs { + self.raw_attrs(of).clone().filter(db, krate) } /// Returns the lowered inner items that `ast` corresponds to. @@ -255,6 +260,7 @@ impl GenericParamsStorage { fn alloc(&mut self, params: GenericParams) -> GenericParamsId { if params.types.is_empty() && params.lifetimes.is_empty() + && params.consts.is_empty() && params.where_predicates.is_empty() { return GenericParamsId::EMPTY; @@ -264,8 +270,12 @@ fn alloc(&mut self, params: GenericParams) -> GenericParamsId { } } -static EMPTY_GENERICS: GenericParams = - GenericParams { types: Arena::new(), lifetimes: Arena::new(), where_predicates: Vec::new() }; +static EMPTY_GENERICS: GenericParams = GenericParams { + types: Arena::new(), + lifetimes: Arena::new(), + consts: Arena::new(), + where_predicates: Vec::new(), +}; #[derive(Default, Debug, Eq, PartialEq)] struct ItemTreeData { @@ -490,7 +500,6 @@ pub struct Import { pub alias: Option, pub visibility: RawVisibilityId, pub is_glob: bool, - pub is_prelude: bool, /// AST ID of the `use` or `extern crate` item this import was derived from. Note that many /// `Import`s can map to the same `use` item. pub ast_id: FileAstId, @@ -506,8 +515,6 @@ pub struct ExternCrate { pub name: Name, pub alias: Option, pub visibility: RawVisibilityId, - /// Whether this is a `#[macro_use] extern crate ...`. - pub is_macro_use: bool, pub ast_id: FileAstId, }