Skip to content
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

doctest builds have a different working directory in virtual workspaces that breaks proc-macros that read relative paths #101181

Closed
leighmcculloch opened this issue Aug 30, 2022 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@leighmcculloch
Copy link

I tried this code in a crate that is in a virtual workspace:

#[proc_macro]
pub fn mymacro(_metadata: TokenStream) -> TokenStream {
    _ = fs::read("relativefilepath").unwrap();
    // ...
}

I expected to see this happen:

  • When the relative file path is present relative to the root of the workspace, I expected to see builds, tests, and doctests for the crate to pass.

Instead, this happened:

  • Builds and tests both pass, as the file is found.
  • Doctests fail to compile, stating that the file cannot be found.

It appears that in a virtual workspace that:

  • In build, test: the current working directory is the root of the workspace.
  • In doctest: the current working directory is the root of the crate where the doctest lives.

The current working directory should be consistent between build, test, and doctest, otherwise proc-macros that load files cannot reliably and consistently load a relative path.

Meta

rustc --version --verbose:

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
@leighmcculloch leighmcculloch added the C-bug Category: This is a bug. label Aug 30, 2022
@ehuss
Copy link
Contributor

ehuss commented Aug 30, 2022

Thanks for the report! This is a known issue, with a fix available via -Z doctest-in-workspace. Closing as a duplicate of rust-lang/cargo#9427

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants