# The module scheme (\`./module.rs\` file + \`./module\` folder instead of just \`./module/mod.rs\`) introduced by the 2018 edition maybe a little bit (more) confusing

**URL:** <https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977>\
**Category:** language design\
**Created:** [December 5, 2024, 9:21am UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977 "2024-12-05T09:21:34Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![jmjoy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jmjoy/32/12891_2.png) [@jmjoy](https://internals.rust-lang.org/u/jmjoy)\
**Post date:** [December 11, 2024, 11:02am UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/21 "2024-12-11T11:02:20Z")

</div>

I also prefer the organization where `mod.rs` is placed inside the `module` folder. However, most editors sort files based on their names, which means `mod.rs` won’t be the first file! It will be mixed in with a bunch of other `mod` files! As a fellow Aquarius with a bit of OCD, this can be quite uncomfortable!

Personally, I’d love for `mod.rs` to be renamed to `_mod.rs`. That way, it would definitely be sorted to the top of the list (since the ASCII code for `_` comes before lowercase letters). If `_mod.rs` looks too much like a "hidden" file, maybe we could go with `$mod.rs` instead? 🙂

---

<div class="post-metadata">

**Author:** ![mpol](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mpol/32/4056_2.png) [@mpol](https://internals.rust-lang.org/u/mpol)\
**Post date:** [December 11, 2024, 11:40am UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/22 "2024-12-11T11:40:32Z")

</div>

Only if your editor sorts the filenames based on plain character code comparison. If it uses the locale-specified collation it is likely to put `_file` right next to `file`.

---

<div class="post-metadata">

**Author:** ![branpk](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/branpk/32/8221_2.png) [@branpk](https://internals.rust-lang.org/u/branpk)\
**Post date:** [December 11, 2024, 7:31pm UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/23 "2024-12-11T19:31:20Z")

</div>

I'm sympathetic to basically all points raised in this thread (except maybe the git rename issue, since for me I keep `mod.rs` very minimal, so the interesting functionality goes into a submodule anyway). I consistently use the `mod.rs` structure.

For me, the low hanging fruit improvement would be to allow other standard names for `mod.rs`. For example, `foo/mod.rs` -\> `foo/mod_foo.rs`.

---

<div class="post-metadata">

**Author:** ![drmason13](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/drmason13/32/8102_2.png) [@drmason13](https://internals.rust-lang.org/u/drmason13)\
**Post date:** [December 18, 2024, 7:02pm UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/24 "2024-12-18T19:02:46Z")

</div>

There's also the use/mention of `mod.rs` in tests/ (integration tests):

From [the docs](https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests):

> This is the older naming convention that Rust also understands that we mentioned in the [“Alternate File Paths”](https://doc.rust-lang.org/book/ch07-05-separating-modules-into-different-files.html#alternate-file-paths) section of Chapter 7. Naming the file this way tells Rust not to treat the `common` module as an integration test file.

There's a _semantic_ difference when using `tests/common/mod.rs` instead of `tests/common.rs`, just to complicate things even further!

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [December 18, 2024, 10:47pm UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/25 "2024-12-18T22:47:11Z")

</div>

Although to be fair, the practice of doing `mod common;` from multiple integration test files has its own issues; it ends up accidentally promoting mounting a `mod`ule multiple times instead of `use`ing it. Also, `tests/foo.rs` looks in `/tests/` for a `mod` (like a crate root `lib.rs`, since that's what it is) instead of `/tests/foo/` (like `/src/foo.rs` would).

If you have an involved testing harness, it can be a significant improvement to turn off automatic test discovery and use `mod` statements to mount all your integration tests into a single crate.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [December 18, 2024, 10:54pm UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/26 "2024-12-18T22:54:27Z")

</div>

Yeah, integration tests are one of the major cases that would motivate having a standard recommended design that _avoids_ hitting this problem.

---

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [December 21, 2024, 4:45pm UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/27 "2024-12-21T16:45:58Z")

</div>

I have made a PR to stop having the reference state a clear preference for one style:

> <https://github.com/rust-lang/reference/pull/1703>
>
> There's currently no clear consensus on which filename style to use for modules,… and many people have a style tha mixes both options. So let's make the reference just describe the facts, without saying which variant is preferred.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [June 14, 2026, 4:46pm UTC](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977/28 "2026-06-14T16:46:57Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/the-module-scheme-module-rs-file-module-folder-instead-of-just-module-mod-rs-introduced-by-the-2018-edition-maybe-a-little-bit-more-confusing/21977.md?page=1)
