mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 12:59:12 +00:00
fix: Do not show safety hints for extern items lacking semantics
This commit is contained in:
parent
8aa4ae5e69
commit
e0814742f0
10 changed files with 97 additions and 31 deletions
|
|
@ -49,6 +49,7 @@ from_id![
|
|||
(hir_def::LifetimeParamId, crate::LifetimeParam),
|
||||
(hir_def::MacroId, crate::Macro),
|
||||
(hir_def::ExternCrateId, crate::ExternCrateDecl),
|
||||
(hir_def::ExternBlockId, crate::ExternBlock),
|
||||
];
|
||||
|
||||
impl From<AdtId> for Adt {
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ use hir_def::{
|
|||
resolver::{HasResolver, Resolver},
|
||||
type_ref::TypesSourceMap,
|
||||
AdtId, AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId,
|
||||
CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FunctionId,
|
||||
GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstId, ItemContainerId,
|
||||
CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId,
|
||||
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstId, ItemContainerId,
|
||||
LifetimeParamId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId,
|
||||
SyntheticSyntax, TraitAliasId, TupleId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
|
||||
};
|
||||
|
|
@ -2327,6 +2327,13 @@ impl Function {
|
|||
db.function_data(self.id).is_async()
|
||||
}
|
||||
|
||||
pub fn extern_block(self, db: &dyn HirDatabase) -> Option<ExternBlock> {
|
||||
match self.id.lookup(db.upcast()).container {
|
||||
ItemContainerId::ExternBlockId(id) => Some(ExternBlock { id }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn returns_impl_future(self, db: &dyn HirDatabase) -> bool {
|
||||
if self.is_async(db) {
|
||||
return true;
|
||||
|
|
@ -2761,6 +2768,13 @@ impl Static {
|
|||
Type::from_value_def(db, self.id)
|
||||
}
|
||||
|
||||
pub fn extern_block(self, db: &dyn HirDatabase) -> Option<ExternBlock> {
|
||||
match self.id.lookup(db.upcast()).container {
|
||||
ItemContainerId::ExternBlockId(id) => Some(ExternBlock { id }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate the static initializer.
|
||||
pub fn eval(self, db: &dyn HirDatabase) -> Result<EvaluatedConst, ConstEvalError> {
|
||||
db.const_eval(self.id.into(), Substitution::empty(Interner), None)
|
||||
|
|
@ -2928,6 +2942,17 @@ impl HasVisibility for TypeAlias {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ExternBlock {
|
||||
pub(crate) id: ExternBlockId,
|
||||
}
|
||||
|
||||
impl ExternBlock {
|
||||
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||
Module { id: self.id.module(db.upcast()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct StaticLifetime;
|
||||
|
||||
|
|
@ -6180,9 +6205,15 @@ impl HasContainer for TraitAlias {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasContainer for ExternBlock {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
ItemContainer::Module(Module { id: self.id.lookup(db.upcast()).container })
|
||||
}
|
||||
}
|
||||
|
||||
fn container_id_to_hir(c: ItemContainerId) -> ItemContainer {
|
||||
match c {
|
||||
ItemContainerId::ExternBlockId(_id) => ItemContainer::ExternBlock(),
|
||||
ItemContainerId::ExternBlockId(id) => ItemContainer::ExternBlock(ExternBlock { id }),
|
||||
ItemContainerId::ModuleId(id) => ItemContainer::Module(Module { id }),
|
||||
ItemContainerId::ImplId(id) => ItemContainer::Impl(Impl { id }),
|
||||
ItemContainerId::TraitId(id) => ItemContainer::Trait(Trait { id }),
|
||||
|
|
@ -6194,7 +6225,7 @@ pub enum ItemContainer {
|
|||
Trait(Trait),
|
||||
Impl(Impl),
|
||||
Module(Module),
|
||||
ExternBlock(),
|
||||
ExternBlock(ExternBlock),
|
||||
Crate(CrateId),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1998,6 +1998,7 @@ to_def_impls![
|
|||
(crate::Adt, ast::Adt, adt_to_def),
|
||||
(crate::ExternCrateDecl, ast::ExternCrate, extern_crate_to_def),
|
||||
(crate::InlineAsmOperand, ast::AsmOperandNamed, asm_operand_to_def),
|
||||
(crate::ExternBlock, ast::ExternBlock, extern_block_to_def),
|
||||
(MacroCallId, ast::MacroCall, macro_call_to_macro_call),
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ impl ChildBySource for ItemScope {
|
|||
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
|
||||
self.declarations().for_each(|item| add_module_def(db, res, file_id, item));
|
||||
self.impls().for_each(|imp| insert_item_loc(db, res, file_id, imp, keys::IMPL));
|
||||
self.extern_blocks().for_each(|extern_block| {
|
||||
insert_item_loc(db, res, file_id, extern_block, keys::EXTERN_BLOCK)
|
||||
});
|
||||
self.extern_crate_decls()
|
||||
.for_each(|ext| insert_item_loc(db, res, file_id, ext, keys::EXTERN_CRATE));
|
||||
self.use_decls().for_each(|ext| insert_item_loc(db, res, file_id, ext, keys::USE));
|
||||
|
|
|
|||
|
|
@ -92,10 +92,10 @@ use hir_def::{
|
|||
DynMap,
|
||||
},
|
||||
hir::{BindingId, Expr, LabelId},
|
||||
AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId,
|
||||
FieldId, FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId, Lookup, MacroId,
|
||||
ModuleId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, UseId,
|
||||
VariantId,
|
||||
AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
|
||||
ExternCrateId, FieldId, FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId,
|
||||
Lookup, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId,
|
||||
UnionId, UseId, VariantId,
|
||||
};
|
||||
use hir_expand::{
|
||||
attrs::AttrId, name::AsName, ExpansionInfo, HirFileId, HirFileIdExt, InMacroFile, MacroCallId,
|
||||
|
|
@ -308,6 +308,12 @@ impl SourceToDefCtx<'_, '_> {
|
|||
) -> Option<ExternCrateId> {
|
||||
self.to_def(src, keys::EXTERN_CRATE)
|
||||
}
|
||||
pub(super) fn extern_block_to_def(
|
||||
&mut self,
|
||||
src: InFile<&ast::ExternBlock>,
|
||||
) -> Option<ExternBlockId> {
|
||||
self.to_def(src, keys::EXTERN_BLOCK)
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn use_to_def(&mut self, src: InFile<&ast::Use>) -> Option<UseId> {
|
||||
self.to_def(src, keys::USE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue