mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Move Intern and Lookup traits to hir-expand
This commit is contained in:
parent
f211a40f1f
commit
071fe4e4e9
6 changed files with 152 additions and 117 deletions
|
@ -637,9 +637,12 @@ impl<'attr> AttrQuery<'attr> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn any_has_attrs(
|
fn any_has_attrs<'db>(
|
||||||
db: &dyn DefDatabase,
|
db: &(dyn DefDatabase + 'db),
|
||||||
id: impl Lookup<Data = impl HasSource<Value = impl ast::HasAttrs>>,
|
id: impl Lookup<
|
||||||
|
Database<'db> = dyn DefDatabase + 'db,
|
||||||
|
Data = impl HasSource<Value = impl ast::HasAttrs>,
|
||||||
|
>,
|
||||||
) -> InFile<ast::AnyHasAttrs> {
|
) -> InFile<ast::AnyHasAttrs> {
|
||||||
id.lookup(db).source(db).map(ast::AnyHasAttrs::new)
|
id.lookup(db).source(db).map(ast::AnyHasAttrs::new)
|
||||||
}
|
}
|
||||||
|
@ -650,17 +653,17 @@ fn attrs_from_item_tree<N: ItemTreeNode>(db: &dyn DefDatabase, id: ItemTreeId<N>
|
||||||
tree.raw_attrs(mod_item.into()).clone()
|
tree.raw_attrs(mod_item.into()).clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attrs_from_item_tree_loc<N: ItemTreeNode>(
|
fn attrs_from_item_tree_loc<'db, N: ItemTreeNode>(
|
||||||
db: &dyn DefDatabase,
|
db: &(dyn DefDatabase + 'db),
|
||||||
lookup: impl Lookup<Data = ItemLoc<N>>,
|
lookup: impl Lookup<Database<'db> = dyn DefDatabase + 'db, Data = ItemLoc<N>>,
|
||||||
) -> RawAttrs {
|
) -> RawAttrs {
|
||||||
let id = lookup.lookup(db).id;
|
let id = lookup.lookup(db).id;
|
||||||
attrs_from_item_tree(db, id)
|
attrs_from_item_tree(db, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attrs_from_item_tree_assoc<N: ItemTreeNode>(
|
fn attrs_from_item_tree_assoc<'db, N: ItemTreeNode>(
|
||||||
db: &dyn DefDatabase,
|
db: &(dyn DefDatabase + 'db),
|
||||||
lookup: impl Lookup<Data = AssocItemLoc<N>>,
|
lookup: impl Lookup<Database<'db> = dyn DefDatabase + 'db, Data = AssocItemLoc<N>>,
|
||||||
) -> RawAttrs {
|
) -> RawAttrs {
|
||||||
let id = lookup.lookup(db).id;
|
let id = lookup.lookup(db).id;
|
||||||
attrs_from_item_tree(db, id)
|
attrs_from_item_tree(db, id)
|
||||||
|
|
|
@ -72,6 +72,7 @@ use hir_expand::{
|
||||||
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
|
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
|
||||||
db::ExpandDatabase,
|
db::ExpandDatabase,
|
||||||
eager::expand_eager_macro_input,
|
eager::expand_eager_macro_input,
|
||||||
|
impl_intern_lookup,
|
||||||
name::Name,
|
name::Name,
|
||||||
proc_macro::{CustomProcMacroExpander, ProcMacroKind},
|
proc_macro::{CustomProcMacroExpander, ProcMacroKind},
|
||||||
AstId, ExpandError, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind,
|
AstId, ExpandError, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind,
|
||||||
|
@ -84,11 +85,12 @@ use span::Span;
|
||||||
use stdx::impl_from;
|
use stdx::impl_from;
|
||||||
use syntax::{ast, AstNode};
|
use syntax::{ast, AstNode};
|
||||||
|
|
||||||
pub use hir_expand::tt;
|
pub use hir_expand::{tt, Intern, Lookup};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
data::adt::VariantData,
|
data::adt::VariantData,
|
||||||
|
db::DefDatabase,
|
||||||
item_tree::{
|
item_tree::{
|
||||||
Const, Enum, ExternCrate, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules,
|
Const, Enum, ExternCrate, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules,
|
||||||
Static, Struct, Trait, TraitAlias, TypeAlias, Union, Use,
|
Static, Struct, Trait, TraitAlias, TypeAlias, Union, Use,
|
||||||
|
@ -102,7 +104,7 @@ pub struct CrateRootModuleId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CrateRootModuleId {
|
impl CrateRootModuleId {
|
||||||
pub fn def_map(&self, db: &dyn db::DefDatabase) -> Arc<DefMap> {
|
pub fn def_map(&self, db: &dyn DefDatabase) -> Arc<DefMap> {
|
||||||
db.crate_def_map(self.krate)
|
db.crate_def_map(self.krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +166,7 @@ pub struct ModuleId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleId {
|
impl ModuleId {
|
||||||
pub fn def_map(self, db: &dyn db::DefDatabase) -> Arc<DefMap> {
|
pub fn def_map(self, db: &dyn DefDatabase) -> Arc<DefMap> {
|
||||||
match self.block {
|
match self.block {
|
||||||
Some(block) => db.block_def_map(block),
|
Some(block) => db.block_def_map(block),
|
||||||
None => db.crate_def_map(self.krate),
|
None => db.crate_def_map(self.krate),
|
||||||
|
@ -175,7 +177,7 @@ impl ModuleId {
|
||||||
self.krate
|
self.krate
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(self, db: &dyn db::DefDatabase) -> Option<Name> {
|
pub fn name(self, db: &dyn DefDatabase) -> Option<Name> {
|
||||||
let def_map = self.def_map(db);
|
let def_map = self.def_map(db);
|
||||||
let parent = def_map[self.local_id].parent?;
|
let parent = def_map[self.local_id].parent?;
|
||||||
def_map[parent].children.iter().find_map(|(name, module_id)| {
|
def_map[parent].children.iter().find_map(|(name, module_id)| {
|
||||||
|
@ -187,7 +189,7 @@ impl ModuleId {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn containing_module(self, db: &dyn db::DefDatabase) -> Option<ModuleId> {
|
pub fn containing_module(self, db: &dyn DefDatabase) -> Option<ModuleId> {
|
||||||
self.def_map(db).containing_module(self.local_id)
|
self.def_map(db).containing_module(self.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,20 +266,7 @@ impl<N: ItemTreeNode> Hash for AssocItemLoc<N> {
|
||||||
macro_rules! impl_intern {
|
macro_rules! impl_intern {
|
||||||
($id:ident, $loc:ident, $intern:ident, $lookup:ident) => {
|
($id:ident, $loc:ident, $intern:ident, $lookup:ident) => {
|
||||||
impl_intern_key!($id);
|
impl_intern_key!($id);
|
||||||
|
impl_intern_lookup!(DefDatabase, $id, $loc, $intern, $lookup);
|
||||||
impl Intern for $loc {
|
|
||||||
type ID = $id;
|
|
||||||
fn intern(self, db: &dyn db::DefDatabase) -> $id {
|
|
||||||
db.$intern(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Lookup for $id {
|
|
||||||
type Data = $loc;
|
|
||||||
fn lookup(&self, db: &dyn db::DefDatabase) -> $loc {
|
|
||||||
db.$lookup(*self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,7 +500,7 @@ pub enum MacroId {
|
||||||
impl_from!(Macro2Id, MacroRulesId, ProcMacroId for MacroId);
|
impl_from!(Macro2Id, MacroRulesId, ProcMacroId for MacroId);
|
||||||
|
|
||||||
impl MacroId {
|
impl MacroId {
|
||||||
pub fn is_attribute(self, db: &dyn db::DefDatabase) -> bool {
|
pub fn is_attribute(self, db: &dyn DefDatabase) -> bool {
|
||||||
matches!(self, MacroId::ProcMacroId(it) if it.lookup(db).kind == ProcMacroKind::Attr)
|
matches!(self, MacroId::ProcMacroId(it) if it.lookup(db).kind == ProcMacroKind::Attr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -723,7 +712,7 @@ impl PartialEq for InTypeConstLoc {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InTypeConstId {
|
impl InTypeConstId {
|
||||||
pub fn source(&self, db: &dyn db::DefDatabase) -> ast::ConstArg {
|
pub fn source(&self, db: &dyn DefDatabase) -> ast::ConstArg {
|
||||||
let src = self.lookup(db).id;
|
let src = self.lookup(db).id;
|
||||||
let file_id = src.file_id;
|
let file_id = src.file_id;
|
||||||
let root = &db.parse_or_expand(file_id);
|
let root = &db.parse_or_expand(file_id);
|
||||||
|
@ -743,7 +732,7 @@ pub enum GeneralConstId {
|
||||||
impl_from!(ConstId, ConstBlockId, InTypeConstId for GeneralConstId);
|
impl_from!(ConstId, ConstBlockId, InTypeConstId for GeneralConstId);
|
||||||
|
|
||||||
impl GeneralConstId {
|
impl GeneralConstId {
|
||||||
pub fn generic_def(self, db: &dyn db::DefDatabase) -> Option<GenericDefId> {
|
pub fn generic_def(self, db: &dyn DefDatabase) -> Option<GenericDefId> {
|
||||||
match self {
|
match self {
|
||||||
GeneralConstId::ConstId(it) => Some(it.into()),
|
GeneralConstId::ConstId(it) => Some(it.into()),
|
||||||
GeneralConstId::ConstBlockId(it) => it.lookup(db).parent.as_generic_def_id(),
|
GeneralConstId::ConstBlockId(it) => it.lookup(db).parent.as_generic_def_id(),
|
||||||
|
@ -751,7 +740,7 @@ impl GeneralConstId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(self, db: &dyn db::DefDatabase) -> String {
|
pub fn name(self, db: &dyn DefDatabase) -> String {
|
||||||
match self {
|
match self {
|
||||||
GeneralConstId::ConstId(const_id) => db
|
GeneralConstId::ConstId(const_id) => db
|
||||||
.const_data(const_id)
|
.const_data(const_id)
|
||||||
|
@ -934,7 +923,7 @@ pub enum VariantId {
|
||||||
impl_from!(EnumVariantId, StructId, UnionId for VariantId);
|
impl_from!(EnumVariantId, StructId, UnionId for VariantId);
|
||||||
|
|
||||||
impl VariantId {
|
impl VariantId {
|
||||||
pub fn variant_data(self, db: &dyn db::DefDatabase) -> Arc<VariantData> {
|
pub fn variant_data(self, db: &dyn DefDatabase) -> Arc<VariantData> {
|
||||||
match self {
|
match self {
|
||||||
VariantId::StructId(it) => db.struct_data(it).variant_data.clone(),
|
VariantId::StructId(it) => db.struct_data(it).variant_data.clone(),
|
||||||
VariantId::UnionId(it) => db.union_data(it).variant_data.clone(),
|
VariantId::UnionId(it) => db.union_data(it).variant_data.clone(),
|
||||||
|
@ -944,7 +933,7 @@ impl VariantId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_id(self, db: &dyn db::DefDatabase) -> HirFileId {
|
pub fn file_id(self, db: &dyn DefDatabase) -> HirFileId {
|
||||||
match self {
|
match self {
|
||||||
VariantId::EnumVariantId(it) => it.parent.lookup(db).id.file_id(),
|
VariantId::EnumVariantId(it) => it.parent.lookup(db).id.file_id(),
|
||||||
VariantId::StructId(it) => it.lookup(db).id.file_id(),
|
VariantId::StructId(it) => it.lookup(db).id.file_id(),
|
||||||
|
@ -961,22 +950,12 @@ impl VariantId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Intern {
|
|
||||||
type ID;
|
|
||||||
fn intern(self, db: &dyn db::DefDatabase) -> Self::ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Lookup {
|
|
||||||
type Data;
|
|
||||||
fn lookup(&self, db: &dyn db::DefDatabase) -> Self::Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait HasModule {
|
pub trait HasModule {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId;
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for ItemContainerId {
|
impl HasModule for ItemContainerId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match *self {
|
match *self {
|
||||||
ItemContainerId::ModuleId(it) => it,
|
ItemContainerId::ModuleId(it) => it,
|
||||||
ItemContainerId::ImplId(it) => it.lookup(db).container,
|
ItemContainerId::ImplId(it) => it.lookup(db).container,
|
||||||
|
@ -987,13 +966,13 @@ impl HasModule for ItemContainerId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: ItemTreeNode> HasModule for AssocItemLoc<N> {
|
impl<N: ItemTreeNode> HasModule for AssocItemLoc<N> {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
self.container.module(db)
|
self.container.module(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for AdtId {
|
impl HasModule for AdtId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
AdtId::StructId(it) => it.lookup(db).container,
|
AdtId::StructId(it) => it.lookup(db).container,
|
||||||
AdtId::UnionId(it) => it.lookup(db).container,
|
AdtId::UnionId(it) => it.lookup(db).container,
|
||||||
|
@ -1003,13 +982,13 @@ impl HasModule for AdtId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for ExternCrateId {
|
impl HasModule for ExternCrateId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
self.lookup(db).container
|
self.lookup(db).container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for VariantId {
|
impl HasModule for VariantId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
VariantId::EnumVariantId(it) => it.parent.lookup(db).container,
|
VariantId::EnumVariantId(it) => it.parent.lookup(db).container,
|
||||||
VariantId::StructId(it) => it.lookup(db).container,
|
VariantId::StructId(it) => it.lookup(db).container,
|
||||||
|
@ -1019,7 +998,7 @@ impl HasModule for VariantId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for MacroId {
|
impl HasModule for MacroId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
MacroId::MacroRulesId(it) => it.lookup(db).container,
|
MacroId::MacroRulesId(it) => it.lookup(db).container,
|
||||||
MacroId::Macro2Id(it) => it.lookup(db).container,
|
MacroId::Macro2Id(it) => it.lookup(db).container,
|
||||||
|
@ -1029,7 +1008,7 @@ impl HasModule for MacroId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for TypeOwnerId {
|
impl HasModule for TypeOwnerId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
TypeOwnerId::FunctionId(it) => it.lookup(db).module(db),
|
TypeOwnerId::FunctionId(it) => it.lookup(db).module(db),
|
||||||
TypeOwnerId::StaticId(it) => it.lookup(db).module(db),
|
TypeOwnerId::StaticId(it) => it.lookup(db).module(db),
|
||||||
|
@ -1046,7 +1025,7 @@ impl HasModule for TypeOwnerId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for DefWithBodyId {
|
impl HasModule for DefWithBodyId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
|
DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
|
||||||
DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
|
DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
|
||||||
|
@ -1058,7 +1037,7 @@ impl HasModule for DefWithBodyId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for GenericDefId {
|
impl HasModule for GenericDefId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
|
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
|
||||||
GenericDefId::AdtId(it) => it.module(db),
|
GenericDefId::AdtId(it) => it.module(db),
|
||||||
|
@ -1073,13 +1052,13 @@ impl HasModule for GenericDefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for TypeAliasId {
|
impl HasModule for TypeAliasId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
self.lookup(db).module(db)
|
self.lookup(db).module(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for TraitId {
|
impl HasModule for TraitId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||||
self.lookup(db).container
|
self.lookup(db).container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1088,7 +1067,7 @@ impl ModuleDefId {
|
||||||
/// Returns the module containing `self` (or `self`, if `self` is itself a module).
|
/// Returns the module containing `self` (or `self`, if `self` is itself a module).
|
||||||
///
|
///
|
||||||
/// Returns `None` if `self` refers to a primitive type.
|
/// Returns `None` if `self` refers to a primitive type.
|
||||||
pub fn module(&self, db: &dyn db::DefDatabase) -> Option<ModuleId> {
|
pub fn module(&self, db: &dyn DefDatabase) -> Option<ModuleId> {
|
||||||
Some(match self {
|
Some(match self {
|
||||||
ModuleDefId::ModuleId(id) => *id,
|
ModuleDefId::ModuleId(id) => *id,
|
||||||
ModuleDefId::FunctionId(id) => id.lookup(db).module(db),
|
ModuleDefId::FunctionId(id) => id.lookup(db).module(db),
|
||||||
|
@ -1106,7 +1085,7 @@ impl ModuleDefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AttrDefId {
|
impl AttrDefId {
|
||||||
pub fn krate(&self, db: &dyn db::DefDatabase) -> CrateId {
|
pub fn krate(&self, db: &dyn DefDatabase) -> CrateId {
|
||||||
match self {
|
match self {
|
||||||
AttrDefId::ModuleId(it) => it.krate,
|
AttrDefId::ModuleId(it) => it.krate,
|
||||||
AttrDefId::FieldId(it) => it.parent.module(db).krate,
|
AttrDefId::FieldId(it) => it.parent.module(db).krate,
|
||||||
|
@ -1244,7 +1223,7 @@ fn macro_call_as_call_id_with_eager(
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macro_id_to_def_id(db: &dyn db::DefDatabase, id: MacroId) -> MacroDefId {
|
pub fn macro_id_to_def_id(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
|
||||||
match id {
|
match id {
|
||||||
MacroId::Macro2Id(it) => {
|
MacroId::Macro2Id(it) => {
|
||||||
let loc = it.lookup(db);
|
let loc = it.lookup(db);
|
||||||
|
@ -1316,7 +1295,7 @@ pub fn macro_id_to_def_id(db: &dyn db::DefDatabase, id: MacroId) -> MacroDefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn derive_macro_as_call_id(
|
fn derive_macro_as_call_id(
|
||||||
db: &dyn db::DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item_attr: &AstIdWithPath<ast::Adt>,
|
item_attr: &AstIdWithPath<ast::Adt>,
|
||||||
derive_attr_index: AttrId,
|
derive_attr_index: AttrId,
|
||||||
derive_pos: u32,
|
derive_pos: u32,
|
||||||
|
@ -1341,7 +1320,7 @@ fn derive_macro_as_call_id(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attr_macro_as_call_id(
|
fn attr_macro_as_call_id(
|
||||||
db: &dyn db::DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item_attr: &AstIdWithPath<ast::Item>,
|
item_attr: &AstIdWithPath<ast::Item>,
|
||||||
macro_attr: &Attr,
|
macro_attr: &Attr,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
|
|
|
@ -28,8 +28,8 @@ use crate::{
|
||||||
db::ExpandDatabase,
|
db::ExpandDatabase,
|
||||||
mod_path::ModPath,
|
mod_path::ModPath,
|
||||||
span_map::SpanMapRef,
|
span_map::SpanMapRef,
|
||||||
EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, MacroCallId,
|
EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, Intern,
|
||||||
MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind,
|
MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn expand_eager_macro_input(
|
pub fn expand_eager_macro_input(
|
||||||
|
@ -49,13 +49,14 @@ pub fn expand_eager_macro_input(
|
||||||
// When `lazy_expand` is called, its *parent* file must already exist.
|
// When `lazy_expand` is called, its *parent* file must already exist.
|
||||||
// Here we store an eager macro id for the argument expanded subtree
|
// Here we store an eager macro id for the argument expanded subtree
|
||||||
// for that purpose.
|
// for that purpose.
|
||||||
let arg_id = db.intern_macro_call(MacroCallLoc {
|
let arg_id = MacroCallLoc {
|
||||||
def,
|
def,
|
||||||
krate,
|
krate,
|
||||||
eager: None,
|
eager: None,
|
||||||
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to: ExpandTo::Expr },
|
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to: ExpandTo::Expr },
|
||||||
call_site,
|
call_site,
|
||||||
});
|
}
|
||||||
|
.intern(db);
|
||||||
let ExpandResult { value: (arg_exp, arg_exp_map), err: parse_err } =
|
let ExpandResult { value: (arg_exp, arg_exp_map), err: parse_err } =
|
||||||
db.parse_macro_expansion(arg_id.as_macro_file());
|
db.parse_macro_expansion(arg_id.as_macro_file());
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ pub fn expand_eager_macro_input(
|
||||||
call_site,
|
call_site,
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpandResult { value: Some(db.intern_macro_call(loc)), err }
|
ExpandResult { value: Some(loc.intern(db)), err }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lazy_expand(
|
fn lazy_expand(
|
||||||
|
|
|
@ -41,8 +41,9 @@ use crate::{
|
||||||
builtin_attr_macro::BuiltinAttrExpander,
|
builtin_attr_macro::BuiltinAttrExpander,
|
||||||
builtin_derive_macro::BuiltinDeriveExpander,
|
builtin_derive_macro::BuiltinDeriveExpander,
|
||||||
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
|
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
|
||||||
db::TokenExpander,
|
db::{ExpandDatabase, TokenExpander},
|
||||||
fixup::SyntaxFixupUndoInfo,
|
fixup::SyntaxFixupUndoInfo,
|
||||||
|
hygiene::SyntaxContextData,
|
||||||
mod_path::ModPath,
|
mod_path::ModPath,
|
||||||
proc_macro::{CustomProcMacroExpander, ProcMacroKind},
|
proc_macro::{CustomProcMacroExpander, ProcMacroKind},
|
||||||
span_map::{ExpansionSpanMap, SpanMap},
|
span_map::{ExpansionSpanMap, SpanMap},
|
||||||
|
@ -70,6 +71,56 @@ pub mod tt {
|
||||||
pub type TokenTree = ::tt::TokenTree<Span>;
|
pub type TokenTree = ::tt::TokenTree<Span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! impl_intern_lookup {
|
||||||
|
($db:ident, $id:ident, $loc:ident, $intern:ident, $lookup:ident) => {
|
||||||
|
impl $crate::Intern for $loc {
|
||||||
|
type Database<'db> = dyn $db + 'db;
|
||||||
|
type ID = $id;
|
||||||
|
fn intern<'db>(self, db: &Self::Database<'db>) -> $id {
|
||||||
|
db.$intern(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::Lookup for $id {
|
||||||
|
type Database<'db> = dyn $db + 'db;
|
||||||
|
type Data = $loc;
|
||||||
|
fn lookup<'db>(&self, db: &Self::Database<'db>) -> $loc {
|
||||||
|
db.$lookup(*self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ideally these would be defined in base-db, but the orphan rule doesn't let us
|
||||||
|
pub trait Intern {
|
||||||
|
type Database<'db>: ?Sized;
|
||||||
|
type ID;
|
||||||
|
fn intern<'db>(self, db: &Self::Database<'db>) -> Self::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Lookup {
|
||||||
|
type Database<'db>: ?Sized;
|
||||||
|
type Data;
|
||||||
|
fn lookup<'db>(&self, db: &Self::Database<'db>) -> Self::Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_intern_lookup!(
|
||||||
|
ExpandDatabase,
|
||||||
|
MacroCallId,
|
||||||
|
MacroCallLoc,
|
||||||
|
intern_macro_call,
|
||||||
|
lookup_intern_macro_call
|
||||||
|
);
|
||||||
|
|
||||||
|
impl_intern_lookup!(
|
||||||
|
ExpandDatabase,
|
||||||
|
SyntaxContextId,
|
||||||
|
SyntaxContextData,
|
||||||
|
intern_syntax_context,
|
||||||
|
lookup_intern_syntax_context
|
||||||
|
);
|
||||||
|
|
||||||
pub type ExpandResult<T> = ValueResult<T, ExpandError>;
|
pub type ExpandResult<T> = ValueResult<T, ExpandError>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||||
|
@ -180,36 +231,35 @@ pub enum MacroCallKind {
|
||||||
|
|
||||||
pub trait HirFileIdExt {
|
pub trait HirFileIdExt {
|
||||||
/// Returns the original file of this macro call hierarchy.
|
/// Returns the original file of this macro call hierarchy.
|
||||||
fn original_file(self, db: &dyn db::ExpandDatabase) -> FileId;
|
fn original_file(self, db: &dyn ExpandDatabase) -> FileId;
|
||||||
|
|
||||||
/// Returns the original file of this macro call hierarchy while going into the included file if
|
/// Returns the original file of this macro call hierarchy while going into the included file if
|
||||||
/// one of the calls comes from an `include!``.
|
/// one of the calls comes from an `include!``.
|
||||||
fn original_file_respecting_includes(self, db: &dyn db::ExpandDatabase) -> FileId;
|
fn original_file_respecting_includes(self, db: &dyn ExpandDatabase) -> FileId;
|
||||||
|
|
||||||
/// If this is a macro call, returns the syntax node of the very first macro call this file resides in.
|
/// If this is a macro call, returns the syntax node of the very first macro call this file resides in.
|
||||||
fn original_call_node(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<SyntaxNode>>;
|
fn original_call_node(self, db: &dyn ExpandDatabase) -> Option<InRealFile<SyntaxNode>>;
|
||||||
|
|
||||||
/// Return expansion information if it is a macro-expansion file
|
/// Return expansion information if it is a macro-expansion file
|
||||||
fn expansion_info(self, db: &dyn db::ExpandDatabase) -> Option<ExpansionInfo>;
|
fn expansion_info(self, db: &dyn ExpandDatabase) -> Option<ExpansionInfo>;
|
||||||
|
|
||||||
fn as_builtin_derive_attr_node(&self, db: &dyn db::ExpandDatabase)
|
fn as_builtin_derive_attr_node(&self, db: &dyn ExpandDatabase) -> Option<InFile<ast::Attr>>;
|
||||||
-> Option<InFile<ast::Attr>>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HirFileIdExt for HirFileId {
|
impl HirFileIdExt for HirFileId {
|
||||||
fn original_file(self, db: &dyn db::ExpandDatabase) -> FileId {
|
fn original_file(self, db: &dyn ExpandDatabase) -> FileId {
|
||||||
let mut file_id = self;
|
let mut file_id = self;
|
||||||
loop {
|
loop {
|
||||||
match file_id.repr() {
|
match file_id.repr() {
|
||||||
HirFileIdRepr::FileId(id) => break id,
|
HirFileIdRepr::FileId(id) => break id,
|
||||||
HirFileIdRepr::MacroFile(MacroFileId { macro_call_id }) => {
|
HirFileIdRepr::MacroFile(MacroFileId { macro_call_id }) => {
|
||||||
file_id = db.lookup_intern_macro_call(macro_call_id).kind.file_id();
|
file_id = macro_call_id.lookup(db).kind.file_id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn original_file_respecting_includes(mut self, db: &dyn db::ExpandDatabase) -> FileId {
|
fn original_file_respecting_includes(mut self, db: &dyn ExpandDatabase) -> FileId {
|
||||||
loop {
|
loop {
|
||||||
match self.repr() {
|
match self.repr() {
|
||||||
HirFileIdRepr::FileId(id) => break id,
|
HirFileIdRepr::FileId(id) => break id,
|
||||||
|
@ -232,7 +282,7 @@ impl HirFileIdExt for HirFileId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn original_call_node(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<SyntaxNode>> {
|
fn original_call_node(self, db: &dyn ExpandDatabase) -> Option<InRealFile<SyntaxNode>> {
|
||||||
let mut call = db.lookup_intern_macro_call(self.macro_file()?.macro_call_id).to_node(db);
|
let mut call = db.lookup_intern_macro_call(self.macro_file()?.macro_call_id).to_node(db);
|
||||||
loop {
|
loop {
|
||||||
match call.file_id.repr() {
|
match call.file_id.repr() {
|
||||||
|
@ -247,14 +297,11 @@ impl HirFileIdExt for HirFileId {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return expansion information if it is a macro-expansion file
|
/// Return expansion information if it is a macro-expansion file
|
||||||
fn expansion_info(self, db: &dyn db::ExpandDatabase) -> Option<ExpansionInfo> {
|
fn expansion_info(self, db: &dyn ExpandDatabase) -> Option<ExpansionInfo> {
|
||||||
Some(ExpansionInfo::new(db, self.macro_file()?))
|
Some(ExpansionInfo::new(db, self.macro_file()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_builtin_derive_attr_node(
|
fn as_builtin_derive_attr_node(&self, db: &dyn ExpandDatabase) -> Option<InFile<ast::Attr>> {
|
||||||
&self,
|
|
||||||
db: &dyn db::ExpandDatabase,
|
|
||||||
) -> Option<InFile<ast::Attr>> {
|
|
||||||
let macro_file = self.macro_file()?;
|
let macro_file = self.macro_file()?;
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
let attr = match loc.def.kind {
|
let attr = match loc.def.kind {
|
||||||
|
@ -266,32 +313,32 @@ impl HirFileIdExt for HirFileId {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MacroFileIdExt {
|
pub trait MacroFileIdExt {
|
||||||
fn expansion_level(self, db: &dyn db::ExpandDatabase) -> u32;
|
fn expansion_level(self, db: &dyn ExpandDatabase) -> u32;
|
||||||
/// If this is a macro call, returns the syntax node of the call.
|
/// If this is a macro call, returns the syntax node of the call.
|
||||||
fn call_node(self, db: &dyn db::ExpandDatabase) -> InFile<SyntaxNode>;
|
fn call_node(self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode>;
|
||||||
|
|
||||||
fn expansion_info(self, db: &dyn db::ExpandDatabase) -> ExpansionInfo;
|
fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo;
|
||||||
|
|
||||||
fn is_builtin_derive(&self, db: &dyn db::ExpandDatabase) -> bool;
|
fn is_builtin_derive(&self, db: &dyn ExpandDatabase) -> bool;
|
||||||
fn is_custom_derive(&self, db: &dyn db::ExpandDatabase) -> bool;
|
fn is_custom_derive(&self, db: &dyn ExpandDatabase) -> bool;
|
||||||
|
|
||||||
/// Return whether this file is an include macro
|
/// Return whether this file is an include macro
|
||||||
fn is_include_macro(&self, db: &dyn db::ExpandDatabase) -> bool;
|
fn is_include_macro(&self, db: &dyn ExpandDatabase) -> bool;
|
||||||
|
|
||||||
fn is_eager(&self, db: &dyn db::ExpandDatabase) -> bool;
|
fn is_eager(&self, db: &dyn ExpandDatabase) -> bool;
|
||||||
/// Return whether this file is an attr macro
|
/// Return whether this file is an attr macro
|
||||||
fn is_attr_macro(&self, db: &dyn db::ExpandDatabase) -> bool;
|
fn is_attr_macro(&self, db: &dyn ExpandDatabase) -> bool;
|
||||||
|
|
||||||
/// Return whether this file is the pseudo expansion of the derive attribute.
|
/// Return whether this file is the pseudo expansion of the derive attribute.
|
||||||
/// See [`crate::builtin_attr_macro::derive_attr_expand`].
|
/// See [`crate::builtin_attr_macro::derive_attr_expand`].
|
||||||
fn is_derive_attr_pseudo_expansion(&self, db: &dyn db::ExpandDatabase) -> bool;
|
fn is_derive_attr_pseudo_expansion(&self, db: &dyn ExpandDatabase) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MacroFileIdExt for MacroFileId {
|
impl MacroFileIdExt for MacroFileId {
|
||||||
fn call_node(self, db: &dyn db::ExpandDatabase) -> InFile<SyntaxNode> {
|
fn call_node(self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode> {
|
||||||
db.lookup_intern_macro_call(self.macro_call_id).to_node(db)
|
db.lookup_intern_macro_call(self.macro_call_id).to_node(db)
|
||||||
}
|
}
|
||||||
fn expansion_level(self, db: &dyn db::ExpandDatabase) -> u32 {
|
fn expansion_level(self, db: &dyn ExpandDatabase) -> u32 {
|
||||||
let mut level = 0;
|
let mut level = 0;
|
||||||
let mut macro_file = self;
|
let mut macro_file = self;
|
||||||
loop {
|
loop {
|
||||||
|
@ -306,39 +353,39 @@ impl MacroFileIdExt for MacroFileId {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return expansion information if it is a macro-expansion file
|
/// Return expansion information if it is a macro-expansion file
|
||||||
fn expansion_info(self, db: &dyn db::ExpandDatabase) -> ExpansionInfo {
|
fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo {
|
||||||
ExpansionInfo::new(db, self)
|
ExpansionInfo::new(db, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_custom_derive(&self, db: &dyn db::ExpandDatabase) -> bool {
|
fn is_custom_derive(&self, db: &dyn ExpandDatabase) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
db.lookup_intern_macro_call(self.macro_call_id).def.kind,
|
db.lookup_intern_macro_call(self.macro_call_id).def.kind,
|
||||||
MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _)
|
MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_builtin_derive(&self, db: &dyn db::ExpandDatabase) -> bool {
|
fn is_builtin_derive(&self, db: &dyn ExpandDatabase) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
db.lookup_intern_macro_call(self.macro_call_id).def.kind,
|
db.lookup_intern_macro_call(self.macro_call_id).def.kind,
|
||||||
MacroDefKind::BuiltInDerive(..)
|
MacroDefKind::BuiltInDerive(..)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_include_macro(&self, db: &dyn db::ExpandDatabase) -> bool {
|
fn is_include_macro(&self, db: &dyn ExpandDatabase) -> bool {
|
||||||
db.lookup_intern_macro_call(self.macro_call_id).def.is_include()
|
db.lookup_intern_macro_call(self.macro_call_id).def.is_include()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_eager(&self, db: &dyn db::ExpandDatabase) -> bool {
|
fn is_eager(&self, db: &dyn ExpandDatabase) -> bool {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id);
|
||||||
matches!(loc.def.kind, MacroDefKind::BuiltInEager(..))
|
matches!(loc.def.kind, MacroDefKind::BuiltInEager(..))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_attr_macro(&self, db: &dyn db::ExpandDatabase) -> bool {
|
fn is_attr_macro(&self, db: &dyn ExpandDatabase) -> bool {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id);
|
||||||
matches!(loc.kind, MacroCallKind::Attr { .. })
|
matches!(loc.kind, MacroCallKind::Attr { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_derive_attr_pseudo_expansion(&self, db: &dyn db::ExpandDatabase) -> bool {
|
fn is_derive_attr_pseudo_expansion(&self, db: &dyn ExpandDatabase) -> bool {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id);
|
||||||
loc.def.is_attribute_derive()
|
loc.def.is_attribute_derive()
|
||||||
}
|
}
|
||||||
|
@ -347,15 +394,15 @@ impl MacroFileIdExt for MacroFileId {
|
||||||
impl MacroDefId {
|
impl MacroDefId {
|
||||||
pub fn as_lazy_macro(
|
pub fn as_lazy_macro(
|
||||||
self,
|
self,
|
||||||
db: &dyn db::ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
kind: MacroCallKind,
|
kind: MacroCallKind,
|
||||||
call_site: Span,
|
call_site: Span,
|
||||||
) -> MacroCallId {
|
) -> MacroCallId {
|
||||||
db.intern_macro_call(MacroCallLoc { def: self, krate, eager: None, kind, call_site })
|
MacroCallLoc { def: self, krate, eager: None, kind, call_site }.intern(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn definition_range(&self, db: &dyn db::ExpandDatabase) -> InFile<TextRange> {
|
pub fn definition_range(&self, db: &dyn ExpandDatabase) -> InFile<TextRange> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
MacroDefKind::Declarative(id)
|
MacroDefKind::Declarative(id)
|
||||||
| MacroDefKind::BuiltIn(_, id)
|
| MacroDefKind::BuiltIn(_, id)
|
||||||
|
@ -420,7 +467,7 @@ impl MacroDefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MacroCallLoc {
|
impl MacroCallLoc {
|
||||||
pub fn span(&self, db: &dyn db::ExpandDatabase) -> Span {
|
pub fn span(&self, db: &dyn ExpandDatabase) -> Span {
|
||||||
let ast_id = self.kind.erased_ast_id();
|
let ast_id = self.kind.erased_ast_id();
|
||||||
let file_id = self.kind.file_id();
|
let file_id = self.kind.file_id();
|
||||||
let range = db.ast_id_map(file_id).get_erased(ast_id).text_range();
|
let range = db.ast_id_map(file_id).get_erased(ast_id).text_range();
|
||||||
|
@ -432,7 +479,7 @@ impl MacroCallLoc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> InFile<SyntaxNode> {
|
pub fn to_node(&self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
MacroCallKind::FnLike { ast_id, .. } => {
|
MacroCallKind::FnLike { ast_id, .. } => {
|
||||||
ast_id.with_value(ast_id.to_node(db).syntax().clone())
|
ast_id.with_value(ast_id.to_node(db).syntax().clone())
|
||||||
|
@ -510,7 +557,7 @@ impl MacroCallKind {
|
||||||
/// Returns the original file range that best describes the location of this macro call.
|
/// Returns the original file range that best describes the location of this macro call.
|
||||||
///
|
///
|
||||||
/// Unlike `MacroCallKind::original_call_range`, this also spans the item of attributes and derives.
|
/// Unlike `MacroCallKind::original_call_range`, this also spans the item of attributes and derives.
|
||||||
pub fn original_call_range_with_body(self, db: &dyn db::ExpandDatabase) -> FileRange {
|
pub fn original_call_range_with_body(self, db: &dyn ExpandDatabase) -> FileRange {
|
||||||
let mut kind = self;
|
let mut kind = self;
|
||||||
let file_id = loop {
|
let file_id = loop {
|
||||||
match kind.file_id().repr() {
|
match kind.file_id().repr() {
|
||||||
|
@ -535,7 +582,7 @@ impl MacroCallKind {
|
||||||
/// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros
|
/// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros
|
||||||
/// get the whole `ast::MacroCall`, attribute macros get the attribute's range, and derives
|
/// get the whole `ast::MacroCall`, attribute macros get the attribute's range, and derives
|
||||||
/// get only the specific derive that is being referred to.
|
/// get only the specific derive that is being referred to.
|
||||||
pub fn original_call_range(self, db: &dyn db::ExpandDatabase) -> FileRange {
|
pub fn original_call_range(self, db: &dyn ExpandDatabase) -> FileRange {
|
||||||
let mut kind = self;
|
let mut kind = self;
|
||||||
let file_id = loop {
|
let file_id = loop {
|
||||||
match kind.file_id().repr() {
|
match kind.file_id().repr() {
|
||||||
|
@ -574,7 +621,7 @@ impl MacroCallKind {
|
||||||
FileRange { range, file_id }
|
FileRange { range, file_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arg(&self, db: &dyn db::ExpandDatabase) -> InFile<Option<SyntaxNode>> {
|
fn arg(&self, db: &dyn ExpandDatabase) -> InFile<Option<SyntaxNode>> {
|
||||||
match self {
|
match self {
|
||||||
MacroCallKind::FnLike { ast_id, .. } => {
|
MacroCallKind::FnLike { ast_id, .. } => {
|
||||||
ast_id.to_in_file_node(db).map(|it| Some(it.token_tree()?.syntax().clone()))
|
ast_id.to_in_file_node(db).map(|it| Some(it.token_tree()?.syntax().clone()))
|
||||||
|
@ -631,7 +678,7 @@ impl ExpansionInfo {
|
||||||
/// Looks up the span at the given offset.
|
/// Looks up the span at the given offset.
|
||||||
pub fn span_for_offset(
|
pub fn span_for_offset(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn db::ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> (FileRange, SyntaxContextId) {
|
) -> (FileRange, SyntaxContextId) {
|
||||||
debug_assert!(self.expanded.value.text_range().contains(offset));
|
debug_assert!(self.expanded.value.text_range().contains(offset));
|
||||||
|
@ -647,7 +694,7 @@ impl ExpansionInfo {
|
||||||
/// Maps up the text range out of the expansion hierarchy back into the original file its from.
|
/// Maps up the text range out of the expansion hierarchy back into the original file its from.
|
||||||
pub fn map_node_range_up(
|
pub fn map_node_range_up(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn db::ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
) -> Option<(FileRange, SyntaxContextId)> {
|
) -> Option<(FileRange, SyntaxContextId)> {
|
||||||
debug_assert!(self.expanded.value.text_range().contains_range(range));
|
debug_assert!(self.expanded.value.text_range().contains_range(range));
|
||||||
|
@ -677,7 +724,7 @@ impl ExpansionInfo {
|
||||||
/// Maps up the text range out of the expansion into is macro call.
|
/// Maps up the text range out of the expansion into is macro call.
|
||||||
pub fn map_range_up_once(
|
pub fn map_range_up_once(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn db::ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
token: TextRange,
|
token: TextRange,
|
||||||
) -> InFile<smallvec::SmallVec<[TextRange; 1]>> {
|
) -> InFile<smallvec::SmallVec<[TextRange; 1]>> {
|
||||||
debug_assert!(self.expanded.value.text_range().contains_range(token));
|
debug_assert!(self.expanded.value.text_range().contains_range(token));
|
||||||
|
@ -706,7 +753,7 @@ impl ExpansionInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(db: &dyn db::ExpandDatabase, macro_file: MacroFileId) -> ExpansionInfo {
|
pub fn new(db: &dyn ExpandDatabase, macro_file: MacroFileId) -> ExpansionInfo {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
|
|
||||||
let arg_tt = loc.kind.arg(db);
|
let arg_tt = loc.kind.arg(db);
|
||||||
|
|
|
@ -2786,9 +2786,13 @@ impl AsAssocItem for DefWithBody {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_assoc_item<ID, DEF, CTOR, AST>(db: &dyn HirDatabase, ctor: CTOR, id: ID) -> Option<AssocItem>
|
fn as_assoc_item<'db, ID, DEF, CTOR, AST>(
|
||||||
|
db: &(dyn HirDatabase + 'db),
|
||||||
|
ctor: CTOR,
|
||||||
|
id: ID,
|
||||||
|
) -> Option<AssocItem>
|
||||||
where
|
where
|
||||||
ID: Lookup<Data = AssocItemLoc<AST>>,
|
ID: Lookup<Database<'db> = dyn DefDatabase + 'db, Data = AssocItemLoc<AST>>,
|
||||||
DEF: From<ID>,
|
DEF: From<ID>,
|
||||||
CTOR: FnOnce(DEF) -> AssocItem,
|
CTOR: FnOnce(DEF) -> AssocItem,
|
||||||
AST: ItemTreeNode,
|
AST: ItemTreeNode,
|
||||||
|
@ -3522,7 +3526,7 @@ impl Impl {
|
||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
|
|
||||||
let macro_file = src.file_id.macro_file()?;
|
let macro_file = src.file_id.macro_file()?;
|
||||||
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc = macro_file.macro_call_id.lookup(db.upcast());
|
||||||
let (derive_attr, derive_index) = match loc.kind {
|
let (derive_attr, derive_index) = match loc.kind {
|
||||||
MacroCallKind::Derive { ast_id, derive_attr_index, derive_index } => {
|
MacroCallKind::Derive { ast_id, derive_attr_index, derive_index } => {
|
||||||
let module_id = self.id.lookup(db.upcast()).container;
|
let module_id = self.id.lookup(db.upcast()).container;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use base_db::FileRange;
|
use base_db::FileRange;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
db::DefDatabase,
|
||||||
item_scope::ItemInNs,
|
item_scope::ItemInNs,
|
||||||
src::{HasChildSource, HasSource},
|
src::{HasChildSource, HasSource},
|
||||||
AdtId, AssocItemId, DefWithBodyId, HasModule, ImplId, Lookup, MacroId, ModuleDefId, ModuleId,
|
AdtId, AssocItemId, DefWithBodyId, HasModule, ImplId, Lookup, MacroId, ModuleDefId, ModuleId,
|
||||||
|
@ -274,9 +275,9 @@ impl<'a> SymbolCollector<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_decl<L>(&mut self, id: L, is_assoc: bool)
|
fn push_decl<'db, L>(&mut self, id: L, is_assoc: bool)
|
||||||
where
|
where
|
||||||
L: Lookup + Into<ModuleDefId>,
|
L: Lookup<Database<'db> = dyn DefDatabase + 'db> + Into<ModuleDefId>,
|
||||||
<L as Lookup>::Data: HasSource,
|
<L as Lookup>::Data: HasSource,
|
||||||
<<L as Lookup>::Data as HasSource>::Value: HasName,
|
<<L as Lookup>::Data as HasSource>::Value: HasName,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue