Skip to content

Incorrect cwd during macro expansion #17748

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
max-sixty opened this issue Jul 30, 2024 · 1 comment · Fixed by #17973 or #18080
Closed

Incorrect cwd during macro expansion #17748

max-sixty opened this issue Jul 30, 2024 · 1 comment · Fixed by #17973 or #18080
Assignees
Labels
A-proc-macro proc macro C-bug Category: bug

Comments

@max-sixty
Copy link

max-sixty commented Jul 30, 2024

rust-analyzer version: 0.3.2053-standalone (fd74511 2024-07-28)

rustc version: 1.80.0

editor or extension: VSCode

repository link (if public, optional): https://github.com/binary-banter/test-each-file/tree/repro

code snippet to reproduce:

Given this code:

use std::path::Path;

use test_macro::test_each_file;

fn main() {
    test_each_file!();
    
    assert!(Path::new("./ROOT.txt").is_file());
    println!("Hello, world!");
}

...referencing this macro:

use std::path::Path;

#[proc_macro]
pub fn test_each_file(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    assert!(Path::new("./ROOT.txt").is_file());

    proc_macro::TokenStream::new()
}

...rustc finds ROOT.txt at the root of the workspace. But rust-analyzer instead looks for ROOT.txt at the root of the crate. This means that rust-analyzer shows errors for this path despite it compiling with rustc fine.

ref binary-banter/test-each-file#6. Repo with a repro linked above.

@max-sixty max-sixty added the C-bug Category: bug label Jul 30, 2024
@Veykril Veykril added the A-proc-macro proc macro label Jul 31, 2024
@bors bors closed this as completed in 06a40a6 Aug 27, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
Expand proc-macros in workspace root, not package root

Should fix rust-lang/rust-analyzer#17748. The approach is generally not perfect though as rust-project.json projects don't benefit from this (still, nothing changes in that regard)
@Veykril Veykril reopened this Sep 9, 2024
@Veykril
Copy link
Member

Veykril commented Sep 9, 2024

Okay so turns out with this we will have to discard our crate graph deduplication logic as crates are now always unique wrt to their workspace. Unfortunate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-bug Category: bug
Projects
None yet
2 participants