Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/hir-def/src/find_path.rs | 10 | ||||
| -rw-r--r-- | crates/hir-def/src/macro_expansion_tests/mod.rs | 3 | ||||
| -rw-r--r-- | crates/hir-expand/src/lib.rs | 5 | ||||
| -rw-r--r-- | crates/hir-expand/src/span_map.rs | 6 |
4 files changed, 12 insertions, 12 deletions
diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs index 6aaf8a674e..945deb8b52 100644 --- a/crates/hir-def/src/find_path.rs +++ b/crates/hir-def/src/find_path.rs @@ -641,6 +641,8 @@ fn find_local_import_locations( #[cfg(test)] mod tests { + use std::cell::LazyCell; + use expect_test::{Expect, expect}; use hir_expand::db::ExpandDatabase; use itertools::Itertools; @@ -672,10 +674,10 @@ mod tests { syntax::SourceFile::parse(&format!("use {path};"), span::Edition::CURRENT); let ast_path = parsed_path_file.syntax_node().descendants().find_map(syntax::ast::Path::cast).unwrap(); - let mod_path = ModPath::from_src(&db, ast_path, &mut |range| { - db.span_map(pos.file_id.into()).span_for_range(range).ctx - }) - .unwrap(); + let span_map = LazyCell::new(|| db.span_map(pos.file_id.into())); + let mod_path = + ModPath::from_src(&db, ast_path, &mut |range| span_map.span_for_range(range).ctx) + .unwrap(); let (def_map, local_def_map) = module.local_def_map(&db); let resolved = def_map diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs index c53a7321e8..2266286652 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -465,11 +465,12 @@ m!(g); ModuleSource::SourceFile(it) => it, ModuleSource::Module(_) | ModuleSource::BlockExpr(_) => panic!(), }; + let span_map = db.real_span_map(file_id); let no_downmap_spans: Vec<_> = source_file .syntax() .descendants() .map(|node| { - let mut span = db.real_span_map(file_id).span_for_range(node.text_range()); + let mut span = span_map.span_for_range(node.text_range()); span.anchor.ast_id = NO_DOWNMAP_ERASED_FILE_AST_ID_MARKER; span }) diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index 719a38edf4..c30f386a34 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -28,7 +28,6 @@ mod fixup; mod prettify_macro_expansion_; use salsa::plumbing::{AsId, FromId}; -use stdx::TupleExt; use thin_vec::ThinVec; use triomphe::Arc; @@ -1216,8 +1215,8 @@ impl<'db> ExpansionInfo<'db> { self.arg.file_id, arg_map .ranges_with_span_exact(span) - .filter(|(range, _)| range.intersect(arg_range).is_some()) - .map(TupleExt::head) + .map(|(range, _)| range) + .filter(|range| range.intersect(arg_range).is_some()) .collect(), ) } diff --git a/crates/hir-expand/src/span_map.rs b/crates/hir-expand/src/span_map.rs index 1b588a8425..0880d5f8fe 100644 --- a/crates/hir-expand/src/span_map.rs +++ b/crates/hir-expand/src/span_map.rs @@ -30,7 +30,7 @@ impl<'db> SpanMap<'db> { // FIXME: Is it correct for us to only take the span at the start? This feels somewhat // wrong. The context will be right, but the range could be considered wrong. See // https://github.com/rust-lang/rust/issues/23480, we probably want to fetch the span at - // the start and end, then merge them like rustc does in `Span::to + // the start and end, then merge them like rustc does in `Span::to` Self::ExpansionSpanMap(span_map) => span_map.span_at(range.start()), Self::RealSpanMap(span_map) => span_map.span_for_range(range), } @@ -40,9 +40,7 @@ impl<'db> SpanMap<'db> { pub(crate) fn new(db: &'db dyn ExpandDatabase, file_id: HirFileId) -> SpanMap<'db> { match file_id { HirFileId::FileId(file_id) => SpanMap::RealSpanMap(db.real_span_map(file_id)), - HirFileId::MacroFile(m) => { - SpanMap::ExpansionSpanMap(&m.parse_macro_expansion(db).value.1) - } + HirFileId::MacroFile(m) => SpanMap::ExpansionSpanMap(db.expansion_span_map(m)), } } } |