Skip to content

Commit 159bf86

Browse files
committed
path-clarity: Terminology change to avoid misusing "relative" and "absolute"
Describe the new variant as "uniform paths", and the previous variant as "anchored use paths". These names both highlight the primary benefit of each variant, and avoid describing paths including "self" or "super" as "absolute".
1 parent 2076ce6 commit 159bf86

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

src/2018/transitioning/modules/path-clarity.md

+27-31
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ features, but they end up *simplifying* the module system, to make it more
1111
clear as to what is going on.
1212

1313
Note: During the 2018 edition preview, there are two variants of the module
14-
system under consideration, the "absolute use paths" variant and the "relative
14+
system under consideration, the "uniform paths" variant and the "anchored use
1515
paths" variant. Most of these changes apply to both variants; the two variant
1616
sections call out the differences between the two. We encourage testing of the
17-
new "relative paths" variant introduced in edition preview 2. The release of
17+
new "uniform paths" variant introduced in edition preview 2. The release of
1818
the 2018 edition will use one of these two variants.
1919

2020
Here's a brief summary:
2121

2222
* `extern crate` is no longer needed
2323
* The `crate` keyword refers to the current crate.
24-
* Relative paths variant: Paths work uniformly in both `use` declarations and
25-
in other code, both in the top-level module and in submodules, and may use
26-
either absolute paths or local names relative to the current module.
27-
* Absolute use paths variant: Paths in `use` declarations are always absolute
28-
and begin with a crate name (or `crate`); paths in other code may use
29-
absolute paths or local names relative to the current module.
24+
* Uniform paths variant: Paths work uniformly in both `use` declarations and in
25+
other code. Paths work uniformly both in the top-level module and in
26+
submodules. Any path may start with a crate, with `crate`, `super`, or
27+
`self`, or with a local name relative to the current module.
28+
* Anchored use paths variant: Paths in `use` declarations always start with a
29+
crate name, or with `crate`, `super`, or `self`. Paths in code other than
30+
`use` declarations may also start with names relative to the current module.
3031
* The `crate` keyword also acts as a visibility modifier, equivalent to today's `pub(crate)`.
3132
* A `foo.rs` and `foo/` subdirectory may coexist; `mod.rs` is no longer needed
3233
when placing submodules in a subdirectory.
@@ -82,21 +83,21 @@ The prefix `::` previously referred to either the crate root or an external
8283
crate; it now unambiguously refers to an external crate. For instance,
8384
`::foo::bar` always refers to the name `bar` inside the external crate `foo`.
8485

85-
### Relative paths variant
86+
### Uniform paths variant
8687

87-
The relative paths variant of Rust 2018 simplifies and unifies path handling
88+
The uniform paths variant of Rust 2018 simplifies and unifies path handling
8889
compared to Rust 2015. In Rust 2015, paths work differently in `use`
8990
declarations than they do elsewhere. In particular, paths in `use`
9091
declarations would always start from the crate root, while paths in other code
9192
implicitly started from the current module. Those differences didn't have any
9293
effect in the top-level module, which meant that everything would seem
9394
straightforward until working on a project large enough to have submodules.
9495

95-
In the relative paths variant of Rust 2018, paths in `use` declarations and in
96+
In the uniform paths variant of Rust 2018, paths in `use` declarations and in
9697
other code always work the same way, both in the top-level module and in any
97-
submodule. You can either use a relative path from the current module, an
98-
absolute path from the top of the current crate (starting with `crate::`), or
99-
an absolute path starting from an external crate name.
98+
submodule. You can always use a relative path from the current module, a path
99+
starting from an external crate name, or a path starting with `crate`, `super`,
100+
or `self`.
100101

101102
Code that looked like this:
102103

@@ -134,7 +135,7 @@ will look exactly the same in Rust 2018, except that you can delete the `extern
134135
crate` line:
135136

136137
```rust,ignore
137-
// Rust 2018 (relative paths variant)
138+
// Rust 2018 (uniform paths variant)
138139
139140
use futures::Future;
140141
@@ -165,7 +166,7 @@ With Rust 2018, however, the same code will also work completely unmodified in
165166
a submodule:
166167

167168
```rust,ignore
168-
// Rust 2018 (relative paths variant)
169+
// Rust 2018 (uniform paths variant)
169170
170171
mod submodule {
171172
use futures::Future;
@@ -203,15 +204,10 @@ either rename one of the conflicting names or explicitly disambiguate the path.
203204
To explicitly disambiguate a path, use `::name` for an external crate name, or
204205
`self::name` for a local module or item.
205206

206-
### Absolute use paths variant
207+
### Anchored use paths variant
207208

208-
In the absolute use paths variant of Rust 2018, paths in `use` declarations
209-
*must* begin with one of:
210-
211-
- A crate name
212-
- `crate` for the current crate's root
213-
- `self` for the current module's root
214-
- `super` for the current module's parent
209+
In the anchored use paths variant of Rust 2018, paths in `use` declarations
210+
*must* begin with a crate name, `crate`, `self`, or `super`.
215211

216212
Code that looked like this:
217213

@@ -232,7 +228,7 @@ use foo::Bar;
232228
Now looks like this:
233229

234230
```rust,ignore
235-
// Rust 2018 (absolute use paths variant)
231+
// Rust 2018 (anchored use paths variant)
236232
237233
// 'futures' is the name of a crate
238234
use futures::Future;
@@ -277,7 +273,7 @@ mod submodule {
277273

278274
In the `futures` example, the `my_poll` function signature is incorrect, because `submodule`
279275
contains no items named `futures`; that is, this path is considered relative. But because
280-
`use` is absolute, `use futures::` works even though a lone `futures::` doesn't! With `std`
276+
`use` is anchored, `use futures::` works even though a lone `futures::` doesn't! With `std`
281277
it can be even more confusing, as you never wrote the `extern crate std;` line at all. So
282278
why does it work in `main` but not in a submodule? Same thing: it's a relative path because
283279
it's not in a `use` declaration. `extern crate std;` is inserted at the crate root, so
@@ -286,26 +282,26 @@ it's fine in `main`, but it doesn't exist in the submodule at all.
286282
Let's look at how this change affects things:
287283

288284
```rust,ignore
289-
// Rust 2018 (absolute use paths variant)
285+
// Rust 2018 (anchored use paths variant)
290286
291287
// no more `extern crate futures;`
292288
293289
mod submodule {
294-
// 'futures' is the name of a crate, so this is absolute and works
290+
// 'futures' is the name of a crate, so this is anchored and works
295291
use futures::Future;
296292
297-
// 'futures' is the name of a crate, so this is absolute and works
293+
// 'futures' is the name of a crate, so this is anchored and works
298294
fn my_poll() -> futures::Poll { ... }
299295
}
300296
301297
fn main() {
302-
// 'std' is the name of a crate, so this is absolute and works
298+
// 'std' is the name of a crate, so this is anchored and works
303299
let five = std::sync::Arc::new(5);
304300
}
305301
306302
mod submodule {
307303
fn function() {
308-
// 'std' is the name of a crate, so this is absolute and works
304+
// 'std' is the name of a crate, so this is anchored and works
309305
let five = std::sync::Arc::new(5);
310306
}
311307
}

0 commit comments

Comments
 (0)