Skip to content

Commit 43b711c

Browse files
authored
Clearer documentation for "No more mod.rs"
### No more `mod.rs` In Rust 2015, if you have a submodule: ```rust,ignore /// foo.rs /// or /// foo/mod.rs mod foo; ``` It can live in `foo.rs` or `foo/mod.rs`. If it has submodules of its own, it *must* be `foo/mod.rs`. So a `bar` submodule of `foo` would live at `foo/bar.rs`. In Rust 2018, `mod.rs` is no longer needed. ```rust,ignore /// foo.rs /// foo/bar.rs mod foo; /// in foo.rs mod bar; ``` `foo.rs` can just be `foo.rs`, and the submodule is still `foo/bar.rs`. This eliminates the special name, and if you have a bunch of files open in your editor, you can clearly see their names, instead of having a bunch of tabs named `mod.rs`.
1 parent 898e478 commit 43b711c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/rust-2018/module-system/path-clarity.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,37 @@ Much more straightforward.
212212
In Rust 2015, if you have a submodule:
213213

214214
```rust,ignore
215+
/// foo.rs
216+
/// or
217+
/// foo/mod.rs
218+
215219
mod foo;
216220
```
217221

218222
It can live in `foo.rs` or `foo/mod.rs`. If it has submodules of its own, it
219223
*must* be `foo/mod.rs`. So a `bar` submodule of `foo` would live at
220224
`foo/bar.rs`.
221225

222-
In Rust 2018, `mod.rs` is no longer needed. `foo.rs` can just be `foo.rs`,
226+
227+
In Rust 2018, `mod.rs` is no longer needed.
228+
229+
```rust,ignore
230+
/// foo.rs
231+
/// foo/bar.rs
232+
233+
mod foo;
234+
235+
/// in foo.rs
236+
mod bar;
237+
```
238+
239+
`foo.rs` can just be `foo.rs`,
223240
and the submodule is still `foo/bar.rs`. This eliminates the special
224241
name, and if you have a bunch of files open in your editor, you can clearly
225242
see their names, instead of having a bunch of tabs named `mod.rs`.
226243

244+
245+
227246
# Uniform paths
228247

229248
> Uniform paths are a nightly-only feature.

0 commit comments

Comments
 (0)