mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Merge #6935
6935: Don't look at attributes when lowering to ItemTree r=jonas-schievink a=jonas-schievink Resolves 2 `cfg_attr` FIXMEs bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
38b108c20e
3 changed files with 28 additions and 15 deletions
|
@ -12,7 +12,7 @@ use std::{
|
|||
};
|
||||
|
||||
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::{
|
||||
|
@ -495,7 +495,6 @@ pub struct Import {
|
|||
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>,
|
||||
|
@ -511,8 +510,6 @@ pub struct ExternCrate {
|
|||
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>,
|
||||
}
|
||||
|
||||
|
|
|
@ -485,8 +485,6 @@ impl Ctx {
|
|||
}
|
||||
|
||||
fn lower_use(&mut self, use_item: &ast::Use) -> Vec<FileItemTreeId<Import>> {
|
||||
// FIXME: cfg_attr
|
||||
let is_prelude = use_item.has_atom_attr("prelude_import");
|
||||
let visibility = self.lower_visibility(use_item);
|
||||
let ast_id = self.source_ast_id_map.ast_id(use_item);
|
||||
|
||||
|
@ -502,7 +500,6 @@ impl Ctx {
|
|||
alias,
|
||||
visibility,
|
||||
is_glob,
|
||||
is_prelude,
|
||||
ast_id,
|
||||
index: imports.len(),
|
||||
})));
|
||||
|
@ -522,10 +519,8 @@ impl Ctx {
|
|||
});
|
||||
let visibility = self.lower_visibility(extern_crate);
|
||||
let ast_id = self.source_ast_id_map.ast_id(extern_crate);
|
||||
// FIXME: cfg_attr
|
||||
let is_macro_use = extern_crate.has_atom_attr("macro_use");
|
||||
|
||||
let res = ExternCrate { name, alias, visibility, is_macro_use, ast_id };
|
||||
let res = ExternCrate { name, alias, visibility, ast_id };
|
||||
Some(id(self.data().extern_crates.alloc(res)))
|
||||
}
|
||||
|
||||
|
|
|
@ -136,23 +136,35 @@ struct Import {
|
|||
}
|
||||
|
||||
impl Import {
|
||||
fn from_use(tree: &ItemTree, id: ItemTreeId<item_tree::Import>) -> Self {
|
||||
fn from_use(
|
||||
db: &dyn DefDatabase,
|
||||
krate: CrateId,
|
||||
tree: &ItemTree,
|
||||
id: ItemTreeId<item_tree::Import>,
|
||||
) -> Self {
|
||||
let it = &tree[id.value];
|
||||
let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into());
|
||||
let visibility = &tree[it.visibility];
|
||||
Self {
|
||||
path: it.path.clone(),
|
||||
alias: it.alias.clone(),
|
||||
visibility: visibility.clone(),
|
||||
is_glob: it.is_glob,
|
||||
is_prelude: it.is_prelude,
|
||||
is_prelude: attrs.by_key("prelude_import").exists(),
|
||||
is_extern_crate: false,
|
||||
is_macro_use: false,
|
||||
source: ImportSource::Import(id),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_extern_crate(tree: &ItemTree, id: ItemTreeId<item_tree::ExternCrate>) -> Self {
|
||||
fn from_extern_crate(
|
||||
db: &dyn DefDatabase,
|
||||
krate: CrateId,
|
||||
tree: &ItemTree,
|
||||
id: ItemTreeId<item_tree::ExternCrate>,
|
||||
) -> Self {
|
||||
let it = &tree[id.value];
|
||||
let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into());
|
||||
let visibility = &tree[it.visibility];
|
||||
Self {
|
||||
path: ModPath::from_segments(PathKind::Plain, iter::once(it.name.clone())),
|
||||
|
@ -161,7 +173,7 @@ impl Import {
|
|||
is_glob: false,
|
||||
is_prelude: false,
|
||||
is_extern_crate: true,
|
||||
is_macro_use: it.is_macro_use,
|
||||
is_macro_use: attrs.by_key("macro_use").exists(),
|
||||
source: ImportSource::ExternCrate(id),
|
||||
}
|
||||
}
|
||||
|
@ -930,7 +942,12 @@ impl ModCollector<'_, '_> {
|
|||
if attrs.cfg().map_or(true, |cfg| self.is_cfg_enabled(&cfg)) {
|
||||
if let ModItem::ExternCrate(id) = item {
|
||||
let import = self.item_tree[*id].clone();
|
||||
if import.is_macro_use {
|
||||
let attrs = self.item_tree.attrs(
|
||||
self.def_collector.db,
|
||||
krate,
|
||||
ModItem::from(*id).into(),
|
||||
);
|
||||
if attrs.by_key("macro_use").exists() {
|
||||
self.def_collector.import_macros_from_extern_crate(self.module_id, &import);
|
||||
}
|
||||
}
|
||||
|
@ -956,6 +973,8 @@ impl ModCollector<'_, '_> {
|
|||
self.def_collector.unresolved_imports.push(ImportDirective {
|
||||
module_id: self.module_id,
|
||||
import: Import::from_use(
|
||||
self.def_collector.db,
|
||||
krate,
|
||||
&self.item_tree,
|
||||
InFile::new(self.file_id, import_id),
|
||||
),
|
||||
|
@ -966,6 +985,8 @@ impl ModCollector<'_, '_> {
|
|||
self.def_collector.unresolved_imports.push(ImportDirective {
|
||||
module_id: self.module_id,
|
||||
import: Import::from_extern_crate(
|
||||
self.def_collector.db,
|
||||
krate,
|
||||
&self.item_tree,
|
||||
InFile::new(self.file_id, import_id),
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue