mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Idiomatic salsa use for extern block abi query
This commit is contained in:
parent
4e392f82cb
commit
bceeb6a3c7
@ -5,7 +5,7 @@ use hir_expand::{
|
||||
EditionedFileId, HirFileId, InFile, Lookup, MacroCallId, MacroDefId, MacroDefKind,
|
||||
db::ExpandDatabase,
|
||||
};
|
||||
use intern::{Symbol, sym};
|
||||
use intern::sym;
|
||||
use la_arena::ArenaMap;
|
||||
use syntax::{AstPtr, ast};
|
||||
use triomphe::Arc;
|
||||
@ -238,9 +238,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase {
|
||||
e: TypeAliasId,
|
||||
) -> (Arc<TypeAliasSignature>, Arc<ExpressionStoreSourceMap>);
|
||||
|
||||
#[salsa::invoke(crate::signatures::extern_block_abi_query)]
|
||||
fn extern_block_abi(&self, extern_block: ExternBlockId) -> Option<Symbol>;
|
||||
|
||||
// endregion:data
|
||||
|
||||
#[salsa::invoke(Body::body_with_source_map_query)]
|
||||
|
@ -49,7 +49,7 @@ pub mod find_path;
|
||||
pub mod import_map;
|
||||
pub mod visibility;
|
||||
|
||||
use intern::{Interned, sym};
|
||||
use intern::{Interned, Symbol, sym};
|
||||
pub use rustc_abi as layout;
|
||||
use thin_vec::ThinVec;
|
||||
use triomphe::Arc;
|
||||
@ -311,6 +311,14 @@ impl_intern!(ExternCrateId, ExternCrateLoc, intern_extern_crate, lookup_intern_e
|
||||
type ExternBlockLoc = ItemLoc<ast::ExternBlock>;
|
||||
impl_intern!(ExternBlockId, ExternBlockLoc, intern_extern_block, lookup_intern_extern_block);
|
||||
|
||||
#[salsa::tracked]
|
||||
impl ExternBlockId {
|
||||
#[salsa::tracked]
|
||||
pub fn abi(self, db: &dyn DefDatabase) -> Option<Symbol> {
|
||||
signatures::extern_block_abi(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct EnumVariantLoc {
|
||||
pub id: AstId<ast::Variant>,
|
||||
|
@ -965,7 +965,7 @@ impl EnumVariants {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn extern_block_abi_query(
|
||||
pub(crate) fn extern_block_abi(
|
||||
db: &dyn DefDatabase,
|
||||
extern_block: ExternBlockId,
|
||||
) -> Option<Symbol> {
|
||||
|
@ -65,7 +65,7 @@ impl Evaluator<'_> {
|
||||
Some(abi) => *abi == sym::rust_dash_intrinsic,
|
||||
None => match def.lookup(self.db).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
self.db.extern_block_abi(block) == Some(sym::rust_dash_intrinsic)
|
||||
block.abi(self.db) == Some(sym::rust_dash_intrinsic)
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
@ -84,9 +84,7 @@ impl Evaluator<'_> {
|
||||
);
|
||||
}
|
||||
let is_extern_c = match def.lookup(self.db).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
self.db.extern_block_abi(block) == Some(sym::C)
|
||||
}
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => block.abi(self.db) == Some(sym::C),
|
||||
_ => false,
|
||||
};
|
||||
if is_extern_c {
|
||||
|
@ -571,7 +571,7 @@ fn main() {
|
||||
"body_shim",
|
||||
"body_with_source_map_shim",
|
||||
"attrs_shim",
|
||||
"impl_items_with_diagnostics_shim",
|
||||
"of_",
|
||||
"infer_shim",
|
||||
"trait_signature_shim",
|
||||
"trait_signature_with_source_map_shim",
|
||||
@ -678,7 +678,7 @@ fn main() {
|
||||
"body_with_source_map_shim",
|
||||
"attrs_shim",
|
||||
"body_shim",
|
||||
"impl_items_with_diagnostics_shim",
|
||||
"of_",
|
||||
"infer_shim",
|
||||
"attrs_shim",
|
||||
"trait_signature_with_source_map_shim",
|
||||
|
@ -293,7 +293,7 @@ pub fn is_fn_unsafe_to_call(
|
||||
let loc = func.lookup(db);
|
||||
match loc.container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let is_intrinsic_block = db.extern_block_abi(block) == Some(sym::rust_dash_intrinsic);
|
||||
let is_intrinsic_block = block.abi(db) == Some(sym::rust_dash_intrinsic);
|
||||
if is_intrinsic_block {
|
||||
// legacy intrinsics
|
||||
// extern "rust-intrinsic" intrinsics are unsafe unless they have the rustc_safe_intrinsic attribute
|
||||
|
Loading…
x
Reference in New Issue
Block a user