From 6e24321e4579d25686982002ed18f321db23cb9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Dec 2020 19:01:15 +0300 Subject: Introduce anchored_path They allow to represent paths like `#[path = "C:\path.rs"] mod foo;` in a lossless cross-platform & network-transparent way. --- crates/hir_expand/src/builtin_macro.rs | 5 +++-- crates/hir_expand/src/test_db.rs | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'crates/hir_expand') diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 79b970850..f60666a54 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -4,7 +4,7 @@ use crate::{ MacroDefId, MacroDefKind, TextSize, }; -use base_db::FileId; +use base_db::{AnchoredPath, FileId}; use either::Either; use mbe::{parse_to_token_tree, ExpandResult}; use parser::FragmentKind; @@ -324,7 +324,8 @@ fn relative_file( allow_recursion: bool, ) -> Option { let call_site = call_id.as_file().original_file(db); - let res = db.resolve_path(call_site, path)?; + let path = AnchoredPath { anchor: call_site, path }; + let res = db.resolve_path(path)?; // Prevent include itself if res == call_site && !allow_recursion { None diff --git a/crates/hir_expand/src/test_db.rs b/crates/hir_expand/src/test_db.rs index fca501e1f..7168a9462 100644 --- a/crates/hir_expand/src/test_db.rs +++ b/crates/hir_expand/src/test_db.rs @@ -5,7 +5,7 @@ use std::{ sync::{Arc, Mutex}, }; -use base_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; +use base_db::{salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate}; use rustc_hash::FxHashSet; #[salsa::database( @@ -40,8 +40,8 @@ impl FileLoader for TestDB { fn file_text(&self, file_id: FileId) -> Arc { FileLoaderDelegate(self).file_text(file_id) } - fn resolve_path(&self, anchor: FileId, path: &str) -> Option { - FileLoaderDelegate(self).resolve_path(anchor, path) + fn resolve_path(&self, path: AnchoredPath) -> Option { + FileLoaderDelegate(self).resolve_path(path) } fn relevant_crates(&self, file_id: FileId) -> Arc> { FileLoaderDelegate(self).relevant_crates(file_id) -- cgit v1.2.3