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