Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/files.rs')
-rw-r--r--crates/hir-expand/src/files.rs50
1 files changed, 32 insertions, 18 deletions
diff --git a/crates/hir-expand/src/files.rs b/crates/hir-expand/src/files.rs
index 71da560b15..a4c206156d 100644
--- a/crates/hir-expand/src/files.rs
+++ b/crates/hir-expand/src/files.rs
@@ -128,6 +128,16 @@ impl ErasedAstId {
}
}
+impl<FileKind, N: AstNode> InFileWrapper<FileKind, AstPtr<N>> {
+ #[inline]
+ pub fn upcast<M: AstNode>(self) -> InFileWrapper<FileKind, AstPtr<M>>
+ where
+ N: Into<M>,
+ {
+ self.map(|it| it.upcast())
+ }
+}
+
impl<FileKind, T> InFileWrapper<FileKind, T> {
pub fn new(file_id: FileKind, value: T) -> Self {
Self { file_id, value }
@@ -256,8 +266,10 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> {
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() {
Some(parent) => Some(node.with_value(parent)),
- None => db
- .lookup_intern_macro_call(node.file_id.macro_file()?)
+ None => node
+ .file_id
+ .macro_file()?
+ .loc(db)
.to_node_item(db)
.syntax()
.cloned()
@@ -273,8 +285,10 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> {
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() {
Some(parent) => Some(node.with_value(parent)),
- None => db
- .lookup_intern_macro_call(node.file_id.macro_file()?)
+ None => node
+ .file_id
+ .macro_file()?
+ .loc(db)
.to_node_item(db)
.syntax()
.cloned()
@@ -328,7 +342,7 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> {
let FileRange { file_id: editioned_file_id, range } = map_node_range_up_rooted(
db,
- &db.expansion_span_map(file_id),
+ db.expansion_span_map(file_id),
self.value.borrow().text_range(),
)?;
@@ -371,7 +385,7 @@ impl InFile<SyntaxToken> {
HirFileId::MacroFile(mac_file) => {
let (range, ctxt) = span_for_offset(
db,
- &db.expansion_span_map(mac_file),
+ db.expansion_span_map(mac_file),
self.value.text_range().start(),
);
@@ -382,7 +396,7 @@ impl InFile<SyntaxToken> {
}
// Fall back to whole macro call.
- let loc = db.lookup_intern_macro_call(mac_file);
+ let loc = mac_file.loc(db);
loc.kind.original_call_range(db, loc.krate)
}
}
@@ -397,7 +411,7 @@ impl InFile<SyntaxToken> {
HirFileId::MacroFile(mac_file) => {
let (range, ctxt) = span_for_offset(
db,
- &db.expansion_span_map(mac_file),
+ db.expansion_span_map(mac_file),
self.value.text_range().start(),
);
@@ -411,7 +425,7 @@ impl InFile<SyntaxToken> {
impl InMacroFile<TextSize> {
pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> (FileRange, SyntaxContext) {
- span_for_offset(db, &db.expansion_span_map(self.file_id), self.value)
+ span_for_offset(db, db.expansion_span_map(self.file_id), self.value)
}
}
@@ -425,10 +439,10 @@ impl InFile<TextRange> {
(FileRange { file_id, range: self.value }, SyntaxContext::root(file_id.edition(db)))
}
HirFileId::MacroFile(mac_file) => {
- match map_node_range_up(db, &db.expansion_span_map(mac_file), self.value) {
+ match map_node_range_up(db, db.expansion_span_map(mac_file), self.value) {
Some(it) => it,
None => {
- let loc = db.lookup_intern_macro_call(mac_file);
+ let loc = mac_file.loc(db);
(
loc.kind.original_call_range(db, loc.krate),
SyntaxContext::root(loc.def.edition),
@@ -443,10 +457,10 @@ impl InFile<TextRange> {
match self.file_id {
HirFileId::FileId(file_id) => FileRange { file_id, range: self.value },
HirFileId::MacroFile(mac_file) => {
- match map_node_range_up_rooted(db, &db.expansion_span_map(mac_file), self.value) {
+ match map_node_range_up_rooted(db, db.expansion_span_map(mac_file), self.value) {
Some(it) => it,
_ => {
- let loc = db.lookup_intern_macro_call(mac_file);
+ let loc = mac_file.loc(db);
loc.kind.original_call_range(db, loc.krate)
}
}
@@ -461,10 +475,10 @@ impl InFile<TextRange> {
match self.file_id {
HirFileId::FileId(file_id) => FileRange { file_id, range: self.value },
HirFileId::MacroFile(mac_file) => {
- match map_node_range_up_rooted(db, &db.expansion_span_map(mac_file), self.value) {
+ match map_node_range_up_rooted(db, db.expansion_span_map(mac_file), self.value) {
Some(it) => it,
_ => {
- let loc = db.lookup_intern_macro_call(mac_file);
+ let loc = mac_file.loc(db);
loc.kind.original_call_range_with_input(db)
}
}
@@ -482,7 +496,7 @@ impl InFile<TextRange> {
SyntaxContext::root(file_id.edition(db)),
)),
HirFileId::MacroFile(mac_file) => {
- map_node_range_up(db, &db.expansion_span_map(mac_file), self.value)
+ map_node_range_up(db, db.expansion_span_map(mac_file), self.value)
}
}
}
@@ -494,7 +508,7 @@ impl InFile<TextRange> {
match self.file_id {
HirFileId::FileId(file_id) => Some(FileRange { file_id, range: self.value }),
HirFileId::MacroFile(mac_file) => {
- map_node_range_up_rooted(db, &db.expansion_span_map(mac_file), self.value)
+ map_node_range_up_rooted(db, db.expansion_span_map(mac_file), self.value)
}
}
}
@@ -516,7 +530,7 @@ impl<N: AstNode> InFile<N> {
let FileRange { file_id: editioned_file_id, range } = map_node_range_up_rooted(
db,
- &db.expansion_span_map(file_id),
+ db.expansion_span_map(file_id),
self.value.syntax().text_range(),
)?;