]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/language-features/crate-in-paths.md
Auto merge of #54334 - steveklabnik:update-cargo, r=alexcrichton
[rust.git] / src / doc / unstable-book / src / language-features / crate-in-paths.md
1 # `crate_in_paths`
2
3 The tracking issue for this feature is: [#44660]
4
5 [#44660]: https://github.com/rust-lang/rust/issues/44660
6
7 ------------------------
8
9 The `crate_in_paths` feature allows to explicitly refer to the crate root in absolute paths
10 using keyword `crate`.
11
12 This feature is required in `feature(extern_absolute_paths)` mode to refer to any absolute path
13 in the local crate (absolute paths refer to extern crates by default in that mode), but can be
14 used without `feature(extern_absolute_paths)` as well.
15
16 ```rust
17 #![feature(crate_in_paths)]
18
19 // Imports, `::` is added implicitly
20 use crate::m::f;
21 use crate as root;
22
23 mod m {
24     pub fn f() -> u8 { 1 }
25     pub fn g() -> u8 { 2 }
26     pub fn h() -> u8 { 3 }
27
28     // OK, visibilities implicitly add starting `::` as well, like imports
29     pub(in crate::m) struct S;
30 }
31
32 mod n
33 {
34     use crate::m::f;
35     use crate as root;
36     pub fn check() {
37         assert_eq!(f(), 1);
38         assert_eq!(crate::m::g(), 2);
39         assert_eq!(root::m::h(), 3);
40     }
41 }
42
43 fn main() {
44     assert_eq!(f(), 1);
45     assert_eq!(crate::m::g(), 2);
46     assert_eq!(root::m::h(), 3);
47     n::check();
48 }
49 ```