Skip to content

Commit c52425b

Browse files
committed
Idiomatic salsa use for extern block abi query
1 parent 4e392f8 commit c52425b

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

crates/hir-def/src/db.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use hir_expand::{
55
EditionedFileId, HirFileId, InFile, Lookup, MacroCallId, MacroDefId, MacroDefKind,
66
db::ExpandDatabase,
77
};
8-
use intern::{Symbol, sym};
8+
use intern::sym;
99
use la_arena::ArenaMap;
1010
use syntax::{AstPtr, ast};
1111
use triomphe::Arc;
@@ -238,9 +238,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase {
238238
e: TypeAliasId,
239239
) -> (Arc<TypeAliasSignature>, Arc<ExpressionStoreSourceMap>);
240240

241-
#[salsa::invoke(crate::signatures::extern_block_abi_query)]
242-
fn extern_block_abi(&self, extern_block: ExternBlockId) -> Option<Symbol>;
243-
244241
// endregion:data
245242

246243
#[salsa::invoke(Body::body_with_source_map_query)]

crates/hir-def/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub mod find_path;
4949
pub mod import_map;
5050
pub mod visibility;
5151

52-
use intern::{Interned, sym};
52+
use intern::{Interned, Symbol, sym};
5353
pub use rustc_abi as layout;
5454
use thin_vec::ThinVec;
5555
use triomphe::Arc;
@@ -311,6 +311,14 @@ impl_intern!(ExternCrateId, ExternCrateLoc, intern_extern_crate, lookup_intern_e
311311
type ExternBlockLoc = ItemLoc<ast::ExternBlock>;
312312
impl_intern!(ExternBlockId, ExternBlockLoc, intern_extern_block, lookup_intern_extern_block);
313313

314+
#[salsa::tracked]
315+
impl ExternBlockId {
316+
#[salsa::tracked]
317+
pub fn abi(self, db: &dyn DefDatabase) -> Option<Symbol> {
318+
signatures::extern_block_abi(db, self)
319+
}
320+
}
321+
314322
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
315323
pub struct EnumVariantLoc {
316324
pub id: AstId<ast::Variant>,

crates/hir-def/src/signatures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl EnumVariants {
965965
}
966966
}
967967

968-
pub(crate) fn extern_block_abi_query(
968+
pub(crate) fn extern_block_abi(
969969
db: &dyn DefDatabase,
970970
extern_block: ExternBlockId,
971971
) -> Option<Symbol> {

crates/hir-ty/src/mir/eval/shim.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Evaluator<'_> {
6565
Some(abi) => *abi == sym::rust_dash_intrinsic,
6666
None => match def.lookup(self.db).container {
6767
hir_def::ItemContainerId::ExternBlockId(block) => {
68-
self.db.extern_block_abi(block) == Some(sym::rust_dash_intrinsic)
68+
block.abi(self.db) == Some(sym::rust_dash_intrinsic)
6969
}
7070
_ => false,
7171
},
@@ -84,9 +84,7 @@ impl Evaluator<'_> {
8484
);
8585
}
8686
let is_extern_c = match def.lookup(self.db).container {
87-
hir_def::ItemContainerId::ExternBlockId(block) => {
88-
self.db.extern_block_abi(block) == Some(sym::C)
89-
}
87+
hir_def::ItemContainerId::ExternBlockId(block) => block.abi(self.db) == Some(sym::C),
9088
_ => false,
9189
};
9290
if is_extern_c {

crates/hir-ty/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn is_fn_unsafe_to_call(
293293
let loc = func.lookup(db);
294294
match loc.container {
295295
hir_def::ItemContainerId::ExternBlockId(block) => {
296-
let is_intrinsic_block = db.extern_block_abi(block) == Some(sym::rust_dash_intrinsic);
296+
let is_intrinsic_block = block.abi(db) == Some(sym::rust_dash_intrinsic);
297297
if is_intrinsic_block {
298298
// legacy intrinsics
299299
// extern "rust-intrinsic" intrinsics are unsafe unless they have the rustc_safe_intrinsic attribute

0 commit comments

Comments
 (0)