Skip to content

#[path = ] directives are relative to #139602

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
Manishearth opened this issue Apr 9, 2025 · 1 comment
Closed

#[path = ] directives are relative to #139602

Manishearth opened this issue Apr 9, 2025 · 1 comment
Labels
A-ast Area: AST A-parser Area: The lexing & parsing of Rust source code to an AST

Comments

@Manishearth
Copy link
Member

I found an interesting quirk of how #[path = ] behaves.

In src/lib.rs:

pub mod inner {
    #[path = "foo.rs"] pub mod foo;
}

looks for src/inner/foo.rs. One would expect that the path would be relative to the file the code is in, but it appears to be relative to the module's directory.

This gets worse if you try to sidestep this behavior:

pub mod inner {
    #[path = "../foo.rs"] pub mod foo;
}

This looks for src/inner/../foo.rs. At first glance, that seems fine, but it doesn't work _until you have an inner folder, which is kind of silly.

I'm not sure if we can change the behavior of path to be file-relative rather than module-folder-relative (probably in an edition?), but the second thing might be fixable.

@Manishearth Manishearth added A-ast Area: AST A-parser Area: The lexing & parsing of Rust source code to an AST labels Apr 9, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 9, 2025
@fmease
Copy link
Member

fmease commented Apr 9, 2025

#35016

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area: AST A-parser Area: The lexing & parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

4 participants