Skip to content

Module Resolution Fixes - #7043

Open
ytmimi wants to merge 3 commits into
rust-lang:mainfrom
ytmimi:issue_7038
Open

Module Resolution Fixes#7043
ytmimi wants to merge 3 commits into
rust-lang:mainfrom
ytmimi:issue_7038

Conversation

@ytmimi

@ytmimi ytmimi commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #7038

This mostly addresses #7038, but I've added a mod resolution test to more exhaustively check resolution with path attributes as mentioned in the reference, and I've updated the doc comments on SubModKind.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Aug 22, 2026
@purplesyringa

Copy link
Copy Markdown

Just to make sure, does this construct paths with the cartesian product? i.e.

#[cfg_attr(unix, path = "a")]
#[cfg_attr(not(unix), path = "b")]
mod outer1 {
    #[cfg_attr(unix, path = "c")]
    #[cfg_attr(not(unix), path = "d")]
    mod outer2 {
        #[cfg_attr(unix, path = "e.rs")]
        #[cfg_attr(not(unix), path = "f.rs")]
        mod inner;
    }
}

should format each of {a,b}/{c,d}/{e,f}.rs.

@ytmimi

ytmimi commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

Just to make sure, does this construct paths with the cartesian product? i.e.

#[cfg_attr(unix, path = "a")]
#[cfg_attr(not(unix), path = "b")]
mod outer1 {
    #[cfg_attr(unix, path = "c")]
    #[cfg_attr(not(unix), path = "d")]
    mod outer2 {
        #[cfg_attr(unix, path = "e.rs")]
        #[cfg_attr(not(unix), path = "f.rs")]
        mod inner;
    }
}

should format each of {a,b}/{c,d}/{e,f}.rs.

@purplesyringa yes, as currently implemented this would construct paths for each of these:

  • a/c/e.rs (all unix)
  • a/c/f.rs
  • a/d/e/rs
  • a/d/f.rs
  • b/c/e.rs
  • b/c/f.rs
  • b/d/e.rs
  • b/df.rs (all not(unix))

Having written that all out it feels like only a/c/e.rs (all unix) and b/d/f.rs (all not(unix)) are valid since any other path can't be constructed because you can't have #[cfg_attr(unix)] and #[cfg_attr(not(unix))] at the same time.

@jieyouxu jieyouxu self-assigned this Aug 23, 2026
Comment thread src/modules.rs
#[derive(Clone)]
enum SubModKind<'a, 'ast> {
/// `mod foo;`
///

@matthewhughes934 matthewhughes934 Aug 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments make this enum much clearer!

View changes since the review

@ytmimi

ytmimi commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Just to make sure, does this construct paths with the cartesian product? i.e.

#[cfg_attr(unix, path = "a")]

#[cfg_attr(not(unix), path = "b")]

mod outer1 {

#[cfg_attr(unix, path = "c")]
#[cfg_attr(not(unix), path = "d")]
mod outer2 {
    #[cfg_attr(unix, path = "e.rs")]
    #[cfg_attr(not(unix), path = "f.rs")]
    mod inner;
}

}

should format each of {a,b}/{c,d}/{e,f}.rs.

@purplesyringa yes, as currently implemented this would construct paths for each of these:

  • a/c/e.rs (all unix)

  • a/c/f.rs

  • a/d/e/rs

  • a/d/f.rs

  • b/c/e.rs

  • b/c/f.rs

  • b/d/e.rs

  • b/df.rs (all not(unix))

Having written that all out it feels like only a/c/e.rs (all unix) and b/d/f.rs (all not(unix)) are valid since any other path can't be constructed because you can't have #[cfg_attr(unix)] and #[cfg_attr(not(unix))] at the same time.

We should probably add a test case for this before merging.

@ytmimi ytmimi added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[cfg_attr(..., path = ...)] on inline modules is not recognized

5 participants