Re-implement InFile wrappers as type aliases over generic InFileWrapper

This commit is contained in:
Lukas Wirth 2023-11-25 14:39:55 +01:00
parent 30093a6d81
commit c43078f99d
13 changed files with 151 additions and 107 deletions

View file

@ -59,7 +59,7 @@ use hir_def::{
Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId,
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
};
use hir_expand::{name::name, InMacroFile, MacroCallKind};
use hir_expand::{name::name, MacroCallKind};
use hir_ty::{
all_super_traits, autoderef, check_orphan_rules,
consteval::{try_const_usize, unknown_const_as_generic, ConstEvalError, ConstExt},
@ -124,7 +124,7 @@ pub use {
hir_expand::{
attrs::{Attr, AttrId},
name::{known, Name},
tt, ExpandResult, HirFileId, HirFileIdExt, InFile, MacroFile,
tt, ExpandResult, HirFileId, HirFileIdExt, InFile, InMacroFile, InRealFile, MacroFileId,
},
hir_ty::{
display::{ClosureStyle, HirDisplay, HirDisplayError, HirWrite},
@ -3505,7 +3505,7 @@ impl Impl {
}
_ => return None,
};
let file_id = MacroFile { macro_call_id: derive_attr };
let file_id = MacroFileId { macro_call_id: derive_attr };
let path = db
.parse_macro_expansion(file_id)
.value

View file

@ -15,7 +15,9 @@ use hir_def::{
type_ref::Mutability,
AsMacroCall, DefWithBodyId, FieldId, FunctionId, MacroId, TraitId, VariantId,
};
use hir_expand::{db::ExpandDatabase, name::AsName, ExpansionInfo, HirFileIdExt, MacroCallId};
use hir_expand::{
db::ExpandDatabase, files::InRealFile, name::AsName, ExpansionInfo, HirFileIdExt, MacroCallId,
};
use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::{smallvec, SmallVec};
@ -756,8 +758,8 @@ impl<'db> SemanticsImpl<'db> {
/// This only work for attribute expansions, as other ones do not have nodes as input.
pub fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(
|InFile { file_id, value }| {
self.cache(find_root(value.syntax()), file_id);
|InRealFile { file_id, value }| {
self.cache(find_root(value.syntax()), file_id.into());
value
},
)
@ -768,8 +770,8 @@ impl<'db> SemanticsImpl<'db> {
pub fn original_syntax_node(&self, node: &SyntaxNode) -> Option<SyntaxNode> {
let InFile { file_id, .. } = self.find_file(node);
InFile::new(file_id, node).original_syntax_node(self.db.upcast()).map(
|InFile { file_id, value }| {
self.cache(find_root(&value), file_id);
|InRealFile { file_id, value }| {
self.cache(find_root(&value), file_id.into());
value
},
)

View file

@ -7,7 +7,7 @@ use hir_def::{
AdtId, AssocItemId, DefWithBodyId, HasModule, ImplId, Lookup, MacroId, ModuleDefId, ModuleId,
TraitId,
};
use hir_expand::{files::ascend_range_up_macros, HirFileId, InFile};
use hir_expand::{HirFileId, InFile};
use hir_ty::db::HirDatabase;
use syntax::{ast::HasName, AstNode, SmolStr, SyntaxNode, SyntaxNodePtr};
@ -51,8 +51,7 @@ impl DeclarationLocation {
}
pub fn original_name_range(&self, db: &dyn HirDatabase) -> FileRange {
let mapping = InFile::new(self.hir_file_id, self.name_ptr.text_range());
ascend_range_up_macros(db.upcast(), mapping).0
InFile::new(self.hir_file_id, self.name_ptr.text_range()).original_file_range(db.upcast())
}
}