Skip to content

#[path = ] directives are relative to #139602

@Manishearth

Description

@Manishearth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ASTArea: ASTA-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions