Skip to content

Commit 395cb98

Browse files
authored
Merge pull request #187 from ehuss/no-more-mod-rs-clarity
Attempt to clarify "no more mod.rs".
2 parents fa7f4eb + fb53ec9 commit 395cb98

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

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

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,34 +169,52 @@ mod submodule {
169169
In Rust 2015, if you have a submodule:
170170

171171
```rust,ignore
172-
/// foo.rs
173-
/// or
174-
/// foo/mod.rs
175-
172+
// This `mod` declaration looks for the `foo` module in
173+
// `foo.rs` or `foo/mod.rs`.
176174
mod foo;
177175
```
178176

179177
It can live in `foo.rs` or `foo/mod.rs`. If it has submodules of its own, it
180178
*must* be `foo/mod.rs`. So a `bar` submodule of `foo` would live at
181179
`foo/bar.rs`.
182180

183-
In Rust 2018, `mod.rs` is no longer needed.
184-
185-
```rust,ignore
186-
/// foo.rs
187-
/// foo/bar.rs
188-
189-
mod foo;
190-
191-
/// in foo.rs
192-
mod bar;
193-
```
194-
195-
`foo.rs` can just be `foo.rs`,
181+
In Rust 2018 the restriction that a module with submodules must be named
182+
`mod.rs` is lifted. `foo.rs` can just be `foo.rs`,
196183
and the submodule is still `foo/bar.rs`. This eliminates the special
197184
name, and if you have a bunch of files open in your editor, you can clearly
198185
see their names, instead of having a bunch of tabs named `mod.rs`.
199186

187+
<table>
188+
<thead>
189+
<tr>
190+
<th>Rust 2015</th>
191+
<th>Rust 2018</th>
192+
</tr>
193+
</thead>
194+
<tbody>
195+
<tr>
196+
<td>
197+
<pre>
198+
.
199+
├── lib.rs
200+
└── foo/
201+
   ├── mod.rs
202+
   └── bar.rs
203+
</pre>
204+
</td>
205+
<td>
206+
<pre>
207+
.
208+
├── lib.rs
209+
├── foo.rs
210+
└── foo/
211+
   └── bar.rs
212+
</pre>
213+
</td>
214+
</tr>
215+
</tbody>
216+
</table>
217+
200218
### `use` paths
201219

202220
![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg)

0 commit comments

Comments
 (0)