mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
Merge pull request #19109 from Veykril/push-nzpuuqommpnq
fix: Do not show safety hints for extern items lacking semantics
This commit is contained in:
commit
8e81cc0772
10 changed files with 97 additions and 31 deletions
|
|
@ -31,9 +31,9 @@ pub mod keys {
|
|||
|
||||
use crate::{
|
||||
dyn_map::{DynMap, Policy},
|
||||
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
|
||||
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
|
||||
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
|
||||
BlockId, ConstId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, FieldId, FunctionId,
|
||||
ImplId, LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId,
|
||||
TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
|
||||
};
|
||||
|
||||
pub type Key<K, V> = crate::dyn_map::Key<AstPtr<K>, V, AstPtrPolicy<K, V>>;
|
||||
|
|
@ -44,6 +44,7 @@ pub mod keys {
|
|||
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
|
||||
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
|
||||
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
|
||||
pub const EXTERN_BLOCK: Key<ast::ExternBlock, ExternBlockId> = Key::new();
|
||||
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
|
||||
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
|
||||
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ use crate::{
|
|||
db::DefDatabase,
|
||||
per_ns::{Item, MacrosItem, PerNs, TypesItem, ValuesItem},
|
||||
visibility::{Visibility, VisibilityExplicitness},
|
||||
AdtId, BuiltinType, ConstId, ExternCrateId, FxIndexMap, HasModule, ImplId, LocalModuleId,
|
||||
Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
|
||||
AdtId, BuiltinType, ConstId, ExternBlockId, ExternCrateId, FxIndexMap, HasModule, ImplId,
|
||||
LocalModuleId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
@ -158,6 +158,8 @@ pub struct ItemScope {
|
|||
declarations: Vec<ModuleDefId>,
|
||||
|
||||
impls: Vec<ImplId>,
|
||||
#[allow(clippy::box_collection)]
|
||||
extern_blocks: Option<Box<Vec<ExternBlockId>>>,
|
||||
unnamed_consts: Vec<ConstId>,
|
||||
/// Traits imported via `use Trait as _;`.
|
||||
unnamed_trait_imports: FxHashMap<TraitId, Item<()>>,
|
||||
|
|
@ -319,6 +321,10 @@ impl ItemScope {
|
|||
self.extern_crate_decls.iter().copied()
|
||||
}
|
||||
|
||||
pub fn extern_blocks(&self) -> impl Iterator<Item = ExternBlockId> + '_ {
|
||||
self.extern_blocks.iter().flat_map(|it| it.iter()).copied()
|
||||
}
|
||||
|
||||
pub fn use_decls(&self) -> impl ExactSizeIterator<Item = UseId> + '_ {
|
||||
self.use_decls.iter().copied()
|
||||
}
|
||||
|
|
@ -469,6 +475,10 @@ impl ItemScope {
|
|||
self.impls.push(imp);
|
||||
}
|
||||
|
||||
pub(crate) fn define_extern_block(&mut self, extern_block: ExternBlockId) {
|
||||
self.extern_blocks.get_or_insert_default().push(extern_block);
|
||||
}
|
||||
|
||||
pub(crate) fn define_extern_crate_decl(&mut self, extern_crate: ExternCrateId) {
|
||||
self.extern_crate_decls.push(extern_crate);
|
||||
}
|
||||
|
|
@ -806,7 +816,11 @@ impl ItemScope {
|
|||
use_imports_types,
|
||||
use_imports_macros,
|
||||
macro_invocations,
|
||||
extern_blocks,
|
||||
} = self;
|
||||
if let Some(it) = extern_blocks {
|
||||
it.shrink_to_fit();
|
||||
}
|
||||
types.shrink_to_fit();
|
||||
values.shrink_to_fit();
|
||||
macros.shrink_to_fit();
|
||||
|
|
|
|||
|
|
@ -1759,16 +1759,20 @@ impl ModCollector<'_, '_> {
|
|||
);
|
||||
}
|
||||
}
|
||||
ModItem::ExternBlock(block) => self.collect(
|
||||
&self.item_tree[block].children,
|
||||
ItemContainerId::ExternBlockId(
|
||||
ExternBlockLoc {
|
||||
container: module,
|
||||
id: ItemTreeId::new(self.tree_id, block),
|
||||
}
|
||||
.intern(db),
|
||||
),
|
||||
),
|
||||
ModItem::ExternBlock(block) => {
|
||||
let extern_block_id = ExternBlockLoc {
|
||||
container: module,
|
||||
id: ItemTreeId::new(self.tree_id, block),
|
||||
}
|
||||
.intern(db);
|
||||
self.def_collector.def_map.modules[self.module_id]
|
||||
.scope
|
||||
.define_extern_block(extern_block_id);
|
||||
self.collect(
|
||||
&self.item_tree[block].children,
|
||||
ItemContainerId::ExternBlockId(extern_block_id),
|
||||
)
|
||||
}
|
||||
ModItem::MacroCall(mac) => self.collect_macro_call(&self.item_tree[mac], container),
|
||||
ModItem::MacroRules(id) => self.collect_macro_rules(id, module),
|
||||
ModItem::Macro2(id) => self.collect_macro_def(id, module),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue