diff --git a/stageleft/src/rewrite_paths.rs b/stageleft/src/rewrite_paths.rs index f9229b5..f7369f7 100644 --- a/stageleft/src/rewrite_paths.rs +++ b/stageleft/src/rewrite_paths.rs @@ -18,7 +18,7 @@ impl VisitMut for RewritePaths { .chain(path_tail) .cloned() .collect(); - } else if let Some(module_path) = &self.module_path { + } else { let mut path_skip_count = 0; let mut module_skip_end_count = 0; @@ -34,6 +34,7 @@ impl VisitMut for RewritePaths { } if path_skip_count > 0 { + let module_path = self.module_path.as_ref().unwrap_or(&self.crate_root_path); let path_tail = path.segments.iter().skip(path_skip_count); path.segments = module_path .segments diff --git a/stageleft_test/src/lib.rs b/stageleft_test/src/lib.rs index f80defe..7fa83ad 100644 --- a/stageleft_test/src/lib.rs +++ b/stageleft_test/src/lib.rs @@ -77,6 +77,11 @@ pub fn crate_paths<'a>(_ctx: BorrowBounds<'a>) -> impl Quoted<'a, bool> { q!(crate::my_top_level_function()) } +#[stageleft::entry] +pub fn self_path_at_root<'a>(_ctx: BorrowBounds<'a>) -> impl Quoted<'a, bool> { + q!(self::my_top_level_function()) +} + #[stageleft::entry] fn captured_closure<'a>(_ctx: BorrowBounds<'a>) -> impl Quoted<'a, bool> { let closure = q!(|| true); @@ -114,6 +119,11 @@ mod tests { assert!(crate_paths!()); } + #[test] + fn test_self_path_at_root() { + assert!(self_path_at_root!()); + } + #[test] fn test_local_paths() { assert!(submodule::self_path!());