2019-10-30 10:10:38 +00:00
|
|
|
//! Defines database & queries for name resolution.
|
2020-08-13 14:25:38 +00:00
|
|
|
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
|
2021-04-06 20:25:44 +00:00
|
|
|
use either::Either;
|
2023-12-21 08:18:06 +00:00
|
|
|
use hir_expand::{db::ExpandDatabase, HirFileId, MacroDefId};
|
2023-01-09 18:29:28 +00:00
|
|
|
use intern::Interned;
|
2021-01-15 00:11:07 +00:00
|
|
|
use la_arena::ArenaMap;
|
2023-01-21 16:29:07 +00:00
|
|
|
use syntax::{ast, AstPtr};
|
2023-05-02 14:12:22 +00:00
|
|
|
use triomphe::Arc;
|
2019-10-30 10:10:38 +00:00
|
|
|
|
2019-10-31 13:40:36 +00:00
|
|
|
use crate::{
|
2021-03-19 20:23:57 +00:00
|
|
|
attr::{Attrs, AttrsWithOwner},
|
2019-11-14 14:37:22 +00:00
|
|
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
2022-03-08 23:41:54 +00:00
|
|
|
data::{
|
2024-01-15 09:24:14 +00:00
|
|
|
adt::{EnumData, EnumVariantData, StructData},
|
2023-06-15 10:28:40 +00:00
|
|
|
ConstData, ExternCrateDeclData, FunctionData, ImplData, Macro2Data, MacroRulesData,
|
|
|
|
ProcMacroData, StaticData, TraitAliasData, TraitData, TypeAliasData,
|
2022-03-08 23:41:54 +00:00
|
|
|
},
|
2019-11-20 17:33:18 +00:00
|
|
|
generics::GenericParams,
|
2020-05-20 21:51:20 +00:00
|
|
|
import_map::ImportMap,
|
2022-04-20 12:07:40 +00:00
|
|
|
item_tree::{AttrOwner, ItemTree},
|
2023-07-07 11:37:29 +00:00
|
|
|
lang_item::{self, LangItem, LangItemTarget, LangItems},
|
2024-01-15 10:07:26 +00:00
|
|
|
nameres::{diagnostics::DefDiagnostics, DefMap},
|
2021-03-24 21:59:59 +00:00
|
|
|
visibility::{self, Visibility},
|
2023-06-12 16:21:17 +00:00
|
|
|
AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId,
|
2024-01-15 09:24:14 +00:00
|
|
|
EnumId, EnumLoc, EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId,
|
|
|
|
ExternCrateLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, InTypeConstId,
|
|
|
|
InTypeConstLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroId, MacroRulesId, MacroRulesLoc,
|
|
|
|
MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc,
|
|
|
|
TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
|
|
|
|
UseId, UseLoc, VariantId,
|
2019-10-31 13:40:36 +00:00
|
|
|
};
|
2019-10-30 13:12:55 +00:00
|
|
|
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::query_group(InternDatabaseStorage)]
|
|
|
|
pub trait InternDatabase: SourceDatabase {
|
2023-06-12 16:21:17 +00:00
|
|
|
// region: items
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::interned]
|
2023-08-02 12:19:38 +00:00
|
|
|
fn intern_use(&self, loc: UseLoc) -> UseId;
|
2023-06-15 10:28:03 +00:00
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_extern_crate(&self, loc: ExternCrateLoc) -> ExternCrateId;
|
|
|
|
#[salsa::interned]
|
2019-11-23 12:33:21 +00:00
|
|
|
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::interned]
|
2019-12-12 13:58:04 +00:00
|
|
|
fn intern_struct(&self, loc: StructLoc) -> StructId;
|
2019-11-25 14:30:50 +00:00
|
|
|
#[salsa::interned]
|
2019-12-12 14:11:57 +00:00
|
|
|
fn intern_union(&self, loc: UnionLoc) -> UnionId;
|
2019-10-30 13:12:55 +00:00
|
|
|
#[salsa::interned]
|
2019-12-12 14:11:57 +00:00
|
|
|
fn intern_enum(&self, loc: EnumLoc) -> EnumId;
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::interned]
|
2024-01-15 09:24:14 +00:00
|
|
|
fn intern_enum_variant(&self, loc: EnumVariantLoc) -> EnumVariantId;
|
|
|
|
#[salsa::interned]
|
2019-11-23 12:33:21 +00:00
|
|
|
fn intern_const(&self, loc: ConstLoc) -> ConstId;
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::interned]
|
2019-11-24 12:13:56 +00:00
|
|
|
fn intern_static(&self, loc: StaticLoc) -> StaticId;
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::interned]
|
2019-12-12 13:34:03 +00:00
|
|
|
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
|
2019-10-30 10:10:38 +00:00
|
|
|
#[salsa::interned]
|
2023-03-03 15:24:07 +00:00
|
|
|
fn intern_trait_alias(&self, loc: TraitAliasLoc) -> TraitAliasId;
|
|
|
|
#[salsa::interned]
|
2019-11-23 12:33:21 +00:00
|
|
|
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
|
2019-11-15 16:14:50 +00:00
|
|
|
#[salsa::interned]
|
2019-12-12 13:09:13 +00:00
|
|
|
fn intern_impl(&self, loc: ImplLoc) -> ImplId;
|
2021-01-25 18:02:05 +00:00
|
|
|
#[salsa::interned]
|
2021-12-07 16:31:26 +00:00
|
|
|
fn intern_extern_block(&self, loc: ExternBlockLoc) -> ExternBlockId;
|
|
|
|
#[salsa::interned]
|
2022-03-08 20:41:19 +00:00
|
|
|
fn intern_macro2(&self, loc: Macro2Loc) -> Macro2Id;
|
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_proc_macro(&self, loc: ProcMacroLoc) -> ProcMacroId;
|
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_macro_rules(&self, loc: MacroRulesLoc) -> MacroRulesId;
|
2023-06-12 16:21:17 +00:00
|
|
|
// endregion: items
|
|
|
|
|
|
|
|
#[salsa::interned]
|
|
|
|
fn intern_block(&self, loc: BlockLoc) -> BlockId;
|
2023-05-12 14:47:15 +00:00
|
|
|
#[salsa::interned]
|
2023-06-12 16:21:17 +00:00
|
|
|
fn intern_anonymous_const(&self, id: ConstBlockLoc) -> ConstBlockId;
|
2023-06-05 11:27:19 +00:00
|
|
|
#[salsa::interned]
|
2023-06-12 16:21:17 +00:00
|
|
|
fn intern_in_type_const(&self, id: InTypeConstLoc) -> InTypeConstId;
|
2019-10-30 10:10:38 +00:00
|
|
|
}
|
2019-10-30 13:12:55 +00:00
|
|
|
|
2019-11-23 11:44:43 +00:00
|
|
|
#[salsa::query_group(DefDatabaseStorage)]
|
2023-03-13 15:33:52 +00:00
|
|
|
pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
|
2021-06-03 14:11:20 +00:00
|
|
|
#[salsa::input]
|
2023-03-29 17:13:40 +00:00
|
|
|
fn expand_proc_attr_macros(&self) -> bool;
|
2021-06-03 14:11:20 +00:00
|
|
|
|
2021-03-13 01:24:26 +00:00
|
|
|
#[salsa::invoke(ItemTree::file_item_tree_query)]
|
|
|
|
fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
|
2020-06-11 17:46:56 +00:00
|
|
|
|
2023-08-10 16:52:27 +00:00
|
|
|
#[salsa::invoke(ItemTree::block_item_tree_query)]
|
|
|
|
fn block_item_tree_query(&self, block_id: BlockId) -> Arc<ItemTree>;
|
|
|
|
|
2020-03-06 23:11:52 +00:00
|
|
|
#[salsa::invoke(crate_def_map_wait)]
|
2020-03-25 17:41:46 +00:00
|
|
|
#[salsa::transparent]
|
2021-01-18 19:18:05 +00:00
|
|
|
fn crate_def_map(&self, krate: CrateId) -> Arc<DefMap>;
|
2019-10-31 15:45:10 +00:00
|
|
|
|
2021-01-18 19:18:05 +00:00
|
|
|
#[salsa::invoke(DefMap::crate_def_map_query)]
|
|
|
|
fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
|
2020-01-03 12:59:46 +00:00
|
|
|
|
2021-02-03 16:48:41 +00:00
|
|
|
/// Computes the block-level `DefMap`, returning `None` when `block` doesn't contain any inner
|
|
|
|
/// items directly.
|
|
|
|
///
|
|
|
|
/// For example:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// fn f() { // (0)
|
|
|
|
/// { // (1)
|
|
|
|
/// fn inner() {}
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// The `block_def_map` for block 0 would return `None`, while `block_def_map` of block 1 would
|
|
|
|
/// return a `DefMap` containing `inner`.
|
2021-01-21 14:22:17 +00:00
|
|
|
#[salsa::invoke(DefMap::block_def_map_query)]
|
2023-04-14 10:15:48 +00:00
|
|
|
fn block_def_map(&self, block: BlockId) -> Arc<DefMap>;
|
2021-01-21 14:22:17 +00:00
|
|
|
|
2023-12-21 08:18:06 +00:00
|
|
|
fn macro_def(&self, m: MacroId) -> MacroDefId;
|
|
|
|
|
2023-04-14 10:47:33 +00:00
|
|
|
// region:data
|
|
|
|
|
2024-01-16 09:47:54 +00:00
|
|
|
#[salsa::transparent]
|
2019-10-31 13:40:36 +00:00
|
|
|
#[salsa::invoke(StructData::struct_data_query)]
|
2019-11-25 14:30:50 +00:00
|
|
|
fn struct_data(&self, id: StructId) -> Arc<StructData>;
|
2022-03-08 23:19:53 +00:00
|
|
|
|
2022-09-21 22:05:30 +00:00
|
|
|
#[salsa::invoke(StructData::struct_data_with_diagnostics_query)]
|
2024-01-15 10:07:26 +00:00
|
|
|
fn struct_data_with_diagnostics(&self, id: StructId) -> (Arc<StructData>, DefDiagnostics);
|
2022-09-21 22:05:30 +00:00
|
|
|
|
2024-01-16 09:47:54 +00:00
|
|
|
#[salsa::transparent]
|
2019-11-25 14:30:50 +00:00
|
|
|
#[salsa::invoke(StructData::union_data_query)]
|
|
|
|
fn union_data(&self, id: UnionId) -> Arc<StructData>;
|
2019-10-31 15:45:10 +00:00
|
|
|
|
2022-09-21 22:05:30 +00:00
|
|
|
#[salsa::invoke(StructData::union_data_with_diagnostics_query)]
|
2024-01-15 10:07:26 +00:00
|
|
|
fn union_data_with_diagnostics(&self, id: UnionId) -> (Arc<StructData>, DefDiagnostics);
|
2022-09-21 22:05:30 +00:00
|
|
|
|
2019-10-31 13:40:36 +00:00
|
|
|
#[salsa::invoke(EnumData::enum_data_query)]
|
|
|
|
fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
|
2019-11-14 14:37:22 +00:00
|
|
|
|
2024-01-16 09:47:54 +00:00
|
|
|
#[salsa::transparent]
|
2024-01-15 09:24:14 +00:00
|
|
|
#[salsa::invoke(EnumVariantData::enum_variant_data_query)]
|
|
|
|
fn enum_variant_data(&self, id: EnumVariantId) -> Arc<EnumVariantData>;
|
|
|
|
|
|
|
|
#[salsa::invoke(EnumVariantData::enum_variant_data_with_diagnostics_query)]
|
|
|
|
fn enum_variant_data_with_diagnostics(
|
|
|
|
&self,
|
|
|
|
id: EnumVariantId,
|
2024-01-15 10:07:26 +00:00
|
|
|
) -> (Arc<EnumVariantData>, DefDiagnostics);
|
2022-09-21 22:05:30 +00:00
|
|
|
|
2024-01-16 09:47:54 +00:00
|
|
|
#[salsa::transparent]
|
2019-11-15 18:28:00 +00:00
|
|
|
#[salsa::invoke(ImplData::impl_data_query)]
|
|
|
|
fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
|
|
|
|
|
2022-08-20 07:58:43 +00:00
|
|
|
#[salsa::invoke(ImplData::impl_data_with_diagnostics_query)]
|
2024-01-15 10:07:26 +00:00
|
|
|
fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, DefDiagnostics);
|
2022-08-20 07:58:43 +00:00
|
|
|
|
2024-01-16 09:47:54 +00:00
|
|
|
#[salsa::transparent]
|
2019-11-20 11:22:06 +00:00
|
|
|
#[salsa::invoke(TraitData::trait_data_query)]
|
|
|
|
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
|
|
|
|
|
2022-08-20 07:58:43 +00:00
|
|
|
#[salsa::invoke(TraitData::trait_data_with_diagnostics_query)]
|
2024-01-15 10:07:26 +00:00
|
|
|
fn trait_data_with_diagnostics(&self, tr: TraitId) -> (Arc<TraitData>, DefDiagnostics);
|
2022-08-20 07:58:43 +00:00
|
|
|
|
2023-03-03 15:24:07 +00:00
|
|
|
#[salsa::invoke(TraitAliasData::trait_alias_query)]
|
|
|
|
fn trait_alias_data(&self, e: TraitAliasId) -> Arc<TraitAliasData>;
|
|
|
|
|
2019-11-22 09:57:40 +00:00
|
|
|
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
|
|
|
|
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
|
|
|
|
|
2019-11-22 14:10:51 +00:00
|
|
|
#[salsa::invoke(FunctionData::fn_data_query)]
|
|
|
|
fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
|
|
|
|
|
2019-11-22 15:46:39 +00:00
|
|
|
#[salsa::invoke(ConstData::const_data_query)]
|
|
|
|
fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
|
|
|
|
|
2020-05-10 15:08:28 +00:00
|
|
|
#[salsa::invoke(StaticData::static_data_query)]
|
|
|
|
fn static_data(&self, konst: StaticId) -> Arc<StaticData>;
|
2019-11-22 15:46:39 +00:00
|
|
|
|
2022-03-08 23:41:54 +00:00
|
|
|
#[salsa::invoke(Macro2Data::macro2_data_query)]
|
|
|
|
fn macro2_data(&self, makro: Macro2Id) -> Arc<Macro2Data>;
|
|
|
|
|
|
|
|
#[salsa::invoke(MacroRulesData::macro_rules_data_query)]
|
|
|
|
fn macro_rules_data(&self, makro: MacroRulesId) -> Arc<MacroRulesData>;
|
|
|
|
|
|
|
|
#[salsa::invoke(ProcMacroData::proc_macro_data_query)]
|
|
|
|
fn proc_macro_data(&self, makro: ProcMacroId) -> Arc<ProcMacroData>;
|
|
|
|
|
2023-06-15 10:28:40 +00:00
|
|
|
#[salsa::invoke(ExternCrateDeclData::extern_crate_decl_data_query)]
|
|
|
|
fn extern_crate_decl_data(&self, extern_crate: ExternCrateId) -> Arc<ExternCrateDeclData>;
|
|
|
|
|
2023-04-14 10:47:33 +00:00
|
|
|
// endregion:data
|
|
|
|
|
2019-11-14 14:37:22 +00:00
|
|
|
#[salsa::invoke(Body::body_with_source_map_query)]
|
|
|
|
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
|
|
|
|
|
|
|
|
#[salsa::invoke(Body::body_query)]
|
|
|
|
fn body(&self, def: DefWithBodyId) -> Arc<Body>;
|
|
|
|
|
|
|
|
#[salsa::invoke(ExprScopes::expr_scopes_query)]
|
|
|
|
fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
|
2019-11-20 17:33:18 +00:00
|
|
|
|
|
|
|
#[salsa::invoke(GenericParams::generic_params_query)]
|
2021-04-05 01:50:10 +00:00
|
|
|
fn generic_params(&self, def: GenericDefId) -> Interned<GenericParams>;
|
2019-11-23 08:14:10 +00:00
|
|
|
|
2023-04-14 10:47:33 +00:00
|
|
|
// region:attrs
|
|
|
|
|
2021-01-04 20:56:21 +00:00
|
|
|
#[salsa::invoke(Attrs::fields_attrs_query)]
|
|
|
|
fn fields_attrs(&self, def: VariantId) -> Arc<ArenaMap<LocalFieldId, Attrs>>;
|
|
|
|
|
2021-04-06 20:25:44 +00:00
|
|
|
#[salsa::invoke(crate::attr::fields_attrs_source_map)]
|
|
|
|
fn fields_attrs_source_map(
|
|
|
|
&self,
|
|
|
|
def: VariantId,
|
|
|
|
) -> Arc<ArenaMap<LocalFieldId, Either<AstPtr<ast::TupleField>, AstPtr<ast::RecordField>>>>;
|
|
|
|
|
2021-03-19 20:23:57 +00:00
|
|
|
#[salsa::invoke(AttrsWithOwner::attrs_query)]
|
2023-04-14 10:47:33 +00:00
|
|
|
fn attrs(&self, def: AttrDefId) -> Attrs;
|
|
|
|
|
2024-01-09 19:52:10 +00:00
|
|
|
#[salsa::transparent]
|
2023-07-07 11:37:29 +00:00
|
|
|
#[salsa::invoke(lang_item::lang_attr_query)]
|
|
|
|
fn lang_attr(&self, def: AttrDefId) -> Option<LangItem>;
|
|
|
|
|
2023-04-14 10:47:33 +00:00
|
|
|
// endregion:attrs
|
2019-11-23 09:58:01 +00:00
|
|
|
|
|
|
|
#[salsa::invoke(LangItems::lang_item_query)]
|
2023-01-21 16:29:07 +00:00
|
|
|
fn lang_item(&self, start_crate: CrateId, item: LangItem) -> Option<LangItemTarget>;
|
2019-11-23 11:43:38 +00:00
|
|
|
|
2020-05-20 21:51:20 +00:00
|
|
|
#[salsa::invoke(ImportMap::import_map_query)]
|
|
|
|
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
|
2021-03-24 21:59:59 +00:00
|
|
|
|
2023-06-01 12:46:36 +00:00
|
|
|
// region:visibilities
|
|
|
|
|
2021-03-24 21:59:59 +00:00
|
|
|
#[salsa::invoke(visibility::field_visibilities_query)]
|
|
|
|
fn field_visibilities(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Visibility>>;
|
|
|
|
|
2022-03-17 16:02:58 +00:00
|
|
|
// FIXME: unify function_visibility and const_visibility?
|
2021-03-24 21:59:59 +00:00
|
|
|
#[salsa::invoke(visibility::function_visibility_query)]
|
|
|
|
fn function_visibility(&self, def: FunctionId) -> Visibility;
|
2022-01-27 22:23:09 +00:00
|
|
|
|
2022-03-17 16:02:58 +00:00
|
|
|
#[salsa::invoke(visibility::const_visibility_query)]
|
|
|
|
fn const_visibility(&self, def: ConstId) -> Visibility;
|
|
|
|
|
2023-06-01 12:46:36 +00:00
|
|
|
// endregion:visibilities
|
|
|
|
|
|
|
|
#[salsa::invoke(LangItems::crate_lang_items_query)]
|
2024-01-09 20:06:21 +00:00
|
|
|
fn crate_lang_items(&self, krate: CrateId) -> Option<Arc<LangItems>>;
|
2023-06-01 12:46:36 +00:00
|
|
|
|
2022-04-20 12:07:40 +00:00
|
|
|
fn crate_supports_no_std(&self, crate_id: CrateId) -> bool;
|
2019-10-30 13:12:55 +00:00
|
|
|
}
|
2020-01-03 12:59:46 +00:00
|
|
|
|
2021-03-05 18:25:24 +00:00
|
|
|
fn crate_def_map_wait(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
|
2020-08-12 14:32:36 +00:00
|
|
|
let _p = profile::span("crate_def_map:wait");
|
2020-03-06 23:11:52 +00:00
|
|
|
db.crate_def_map_query(krate)
|
2020-01-03 12:59:46 +00:00
|
|
|
}
|
2022-01-27 22:23:09 +00:00
|
|
|
|
2022-04-20 12:07:40 +00:00
|
|
|
fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
|
|
|
|
let file = db.crate_graph()[crate_id].root_file_id;
|
|
|
|
let item_tree = db.file_item_tree(file.into());
|
|
|
|
let attrs = item_tree.raw_attrs(AttrOwner::TopLevel);
|
|
|
|
for attr in &**attrs {
|
|
|
|
match attr.path().as_ident().and_then(|id| id.as_text()) {
|
|
|
|
Some(ident) if ident == "no_std" => return true,
|
|
|
|
Some(ident) if ident == "cfg_attr" => {}
|
|
|
|
_ => continue,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a `cfg_attr`; check if it could possibly expand to `no_std`.
|
|
|
|
// Syntax is: `#[cfg_attr(condition(cfg, style), attr0, attr1, <...>)]`
|
|
|
|
let tt = match attr.token_tree_value() {
|
|
|
|
Some(tt) => &tt.token_trees,
|
|
|
|
None => continue,
|
|
|
|
};
|
|
|
|
|
|
|
|
let segments = tt.split(|tt| match tt {
|
|
|
|
tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => true,
|
|
|
|
_ => false,
|
|
|
|
});
|
|
|
|
for output in segments.skip(1) {
|
|
|
|
match output {
|
|
|
|
[tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "no_std" => {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
2023-12-21 08:18:06 +00:00
|
|
|
|
|
|
|
fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
|
|
|
|
use hir_expand::InFile;
|
|
|
|
|
|
|
|
use crate::{Lookup, MacroDefKind, MacroExpander};
|
|
|
|
|
|
|
|
let kind = |expander, file_id, m| {
|
|
|
|
let in_file = InFile::new(file_id, m);
|
|
|
|
match expander {
|
|
|
|
MacroExpander::Declarative => MacroDefKind::Declarative(in_file),
|
|
|
|
MacroExpander::BuiltIn(it) => MacroDefKind::BuiltIn(it, in_file),
|
|
|
|
MacroExpander::BuiltInAttr(it) => MacroDefKind::BuiltInAttr(it, in_file),
|
|
|
|
MacroExpander::BuiltInDerive(it) => MacroDefKind::BuiltInDerive(it, in_file),
|
|
|
|
MacroExpander::BuiltInEager(it) => MacroDefKind::BuiltInEager(it, in_file),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
match id {
|
|
|
|
MacroId::Macro2Id(it) => {
|
2023-12-21 08:54:47 +00:00
|
|
|
let loc: Macro2Loc = it.lookup(db);
|
2023-12-21 08:18:06 +00:00
|
|
|
|
|
|
|
let item_tree = loc.id.item_tree(db);
|
|
|
|
let makro = &item_tree[loc.id.value];
|
|
|
|
MacroDefId {
|
|
|
|
krate: loc.container.krate,
|
|
|
|
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
|
|
|
|
local_inner: false,
|
|
|
|
allow_internal_unsafe: loc.allow_internal_unsafe,
|
2023-12-21 09:51:54 +00:00
|
|
|
span: db
|
2023-12-21 08:54:47 +00:00
|
|
|
.span_map(loc.id.file_id())
|
|
|
|
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
|
2023-12-21 15:20:27 +00:00
|
|
|
edition: loc.edition,
|
2023-12-21 08:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-21 15:20:27 +00:00
|
|
|
|
2023-12-21 08:18:06 +00:00
|
|
|
MacroId::MacroRulesId(it) => {
|
2023-12-21 08:54:47 +00:00
|
|
|
let loc: MacroRulesLoc = it.lookup(db);
|
2023-12-21 08:18:06 +00:00
|
|
|
|
|
|
|
let item_tree = loc.id.item_tree(db);
|
|
|
|
let makro = &item_tree[loc.id.value];
|
|
|
|
MacroDefId {
|
|
|
|
krate: loc.container.krate,
|
|
|
|
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
|
2023-12-21 15:20:27 +00:00
|
|
|
local_inner: loc.flags.contains(MacroRulesLocFlags::LOCAL_INNER),
|
|
|
|
allow_internal_unsafe: loc
|
|
|
|
.flags
|
|
|
|
.contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE),
|
2023-12-21 09:51:54 +00:00
|
|
|
span: db
|
2023-12-21 08:54:47 +00:00
|
|
|
.span_map(loc.id.file_id())
|
|
|
|
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
|
2023-12-21 15:20:27 +00:00
|
|
|
edition: loc.edition,
|
2023-12-21 08:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MacroId::ProcMacroId(it) => {
|
|
|
|
let loc = it.lookup(db);
|
|
|
|
|
|
|
|
let item_tree = loc.id.item_tree(db);
|
|
|
|
let makro = &item_tree[loc.id.value];
|
|
|
|
MacroDefId {
|
|
|
|
krate: loc.container.krate,
|
|
|
|
kind: MacroDefKind::ProcMacro(
|
|
|
|
loc.expander,
|
|
|
|
loc.kind,
|
|
|
|
InFile::new(loc.id.file_id(), makro.ast_id),
|
|
|
|
),
|
|
|
|
local_inner: false,
|
|
|
|
allow_internal_unsafe: false,
|
2023-12-21 09:51:54 +00:00
|
|
|
span: db
|
2023-12-21 08:54:47 +00:00
|
|
|
.span_map(loc.id.file_id())
|
|
|
|
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
|
2023-12-21 15:20:27 +00:00
|
|
|
edition: loc.edition,
|
2023-12-21 08:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|