Skip to content

transpile: handle module name collisions#1858

Merged
thedataking merged 1 commit into
masterfrom
legare/module-name-collision
Jul 9, 2026
Merged

transpile: handle module name collisions#1858
thedataking merged 1 commit into
masterfrom
legare/module-name-collision

Conversation

@randomPoison

@randomPoison randomPoison commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

In testing against libgit2, we ran into a case where module names could collide, leading to a generated Rust file not being included in the build. The situation is that we have both a hash.c file and some files in a hash directory, e.g. hash/sha1.c. C2rust then wants to generate both

mod src {
    mod hash;
}

and

mod src {
    mod hash {
        mod sha1;
    }
}

In this case, the latter is what gets generated, effectively dropping src/hash.rs from the Rust build.

This PR has c2rust detect these collisions and rename the colliding module, so we'd generate something like

mod src {
    #[path = "hash.rs"]
    mod hash_;
    mod hash {
        mod sha1;
    }
}

Comment thread c2rust-transpile/src/build_files/mod.rs Outdated
Comment thread c2rust-transpile/src/build_files/mod.rs Outdated
Comment thread c2rust-transpile/src/build_files/mod.rs Outdated
Comment thread c2rust-transpile/src/build_files/mod.rs
Comment thread c2rust-transpile/src/build_files/mod.rs Outdated
Comment thread c2rust-transpile/src/build_files/mod.rs Outdated
@thedataking thedataking changed the title Attempt to handle module name collisions transpile: Handle module name collisions Jun 17, 2026
Comment thread c2rust-transpile/src/build_files/mod.rs
@thedataking thedataking changed the base branch from master to perl/test-libgit2 June 18, 2026 09:31
@thedataking thedataking added the bug Something isn't working label Jun 18, 2026
@thedataking thedataking force-pushed the perl/test-libgit2 branch 3 times, most recently from ba11e5f to 13f3c26 Compare June 24, 2026 07:58
@thedataking thedataking force-pushed the perl/test-libgit2 branch 3 times, most recently from ab98f77 to f61af1c Compare July 3, 2026 02:27
@thedataking thedataking force-pushed the legare/module-name-collision branch from ca4d90d to a9f3037 Compare July 3, 2026 02:37
@thedataking thedataking changed the base branch from perl/test-libgit2 to perl/const-block-unsafe-transmute July 3, 2026 02:37
@thedataking thedataking force-pushed the legare/module-name-collision branch from a9f3037 to 1aec978 Compare July 3, 2026 02:40
@thedataking thedataking changed the base branch from perl/const-block-unsafe-transmute to master July 3, 2026 02:40
@thedataking thedataking self-assigned this Jul 3, 2026
@thedataking thedataking force-pushed the legare/module-name-collision branch 2 times, most recently from 9cb12d3 to 9f1dd8e Compare July 5, 2026 07:18
@thedataking thedataking marked this pull request as ready for review July 5, 2026 08:20
@thedataking thedataking changed the title transpile: Handle module name collisions Handle module name collisions Jul 8, 2026
@thedataking thedataking changed the title Handle module name collisions transpile: handle module name collisions Jul 8, 2026
Comment thread c2rust-refactor/src/ast_manip/load_modules.rs Outdated
Comment thread c2rust-refactor/src/ast_manip/load_modules.rs
@thedataking thedataking merged commit 2e6a903 into master Jul 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants