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,
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},
#[derive(Debug, Eq, PartialEq)]
pub struct ItemTree {
top_level: SmallVec<[ModItem; 1]>,
- attrs: FxHashMap<AttrOwner, Attrs>,
+ attrs: FxHashMap<AttrOwner, RawAttrs>,
inner_items: FxHashMap<FileAstId<ast::Item>, SmallVec<[ModItem; 1]>>,
data: Option<Box<ItemTreeData>>,
let mut item_tree = match_ast! {
match syntax {
ast::SourceFile(file) => {
- top_attrs = Some(Attrs::new(&file, &hygiene));
+ top_attrs = Some(RawAttrs::new(&file, &hygiene));
ctx.lower_module_items(&file)
},
ast::MacroItems(items) => {
}
/// 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.
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;
}
}
-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 {
pub alias: Option<ImportAlias>,
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<ast::Use>,
pub name: Name,
pub alias: Option<ImportAlias>,
pub visibility: RawVisibilityId,
- /// Whether this is a `#[macro_use] extern crate ...`.
- pub is_macro_use: bool,
pub ast_id: FileAstId<ast::ExternCrate>,
}