Skip to content

rust-analyzer does not see the path of a Span's source_file #19458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sadeli413 opened this issue Mar 27, 2025 · 2 comments
Closed

rust-analyzer does not see the path of a Span's source_file #19458

sadeli413 opened this issue Mar 27, 2025 · 2 comments
Labels
C-feature Category: feature request

Comments

@sadeli413
Copy link

I'd like rust-analyzer to be able to detect the source-file's path of a span.

I have a proc-macro that simply panics and shows the caller's source path:

#![feature(proc_macro_span)]
use proc_macro::{Span, TokenStream};

#[proc_macro]
pub fn file_test(_input: TokenStream) -> TokenStream {
    let span = Span::call_site();
    let path = span.source_file().path();
    panic!("test: `{}`", path.display());
}

rustc sees that the filename is src/main.rs just fine, but rust-analyzer thinks the filename is blank.

use macro_hell::file_test;

fn main() {
    // rustc: test: `src/main.rs`
    // rust-analyzer: test: ``
    let _ = file_test!();
}

Image

@sadeli413 sadeli413 added the C-feature Category: feature request label Mar 27, 2025
@ChayimFriedman2
Copy link
Contributor

Generally we don't properly support the span APIs, and doing it will be difficult for us. Although maybe the file name is not that problematic.

@Veykril
Copy link
Member

Veykril commented Mar 27, 2025

#15950

@Veykril Veykril closed this as completed Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

3 participants