You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Rust 2018 the "crate namespace" now lives outside of the "crate root", yet the reference and the compiler still refer to it as the "crate root". So if you write ::foo::bar this looks up foo in the "crate namespace", but the compiler still calls this the "crate root" as can be seen here:
error[E0412]: cannot find type `Bar` in the crate root
--> src/lib.rs:4:16
|
4 | fn ok(_: ::Bar) {}
| ^^^ not found in the crate root
|
help: consider importing this struct
|
4 | use crate::Bar;
|
The help even implies that Bar is indeed in the "crate root".
Twitter kind of makes it unclear exactly what Cryze is linking there so to be clear: the thing that confused me, as a newbie, reading the reference is in 2.7 of the reference, it says:
for ::, "the segments of the path start being resolved from the crate root"
whereas crate "resolves the path relative to the current crate"
Until this was explained to me, it sounded to me like these two quotes were designing the same concept. The point of confusion for me was that "the crate root" could ambiguously be read as "the root of all crates" or "the root of the crate". I was reading the reference and maybe it is expected a reader of the reference realizes "the crate root" means something specific and special, but it did trip me up.
Yeah the "crate root" means a specific thing, whereas :: refers to some notion of "global path" which differs based on edition -- "crate root" in 2015, and "extern prelude" in 2018+. We should stop saying :: is the crate root. I already have a PR for the reference in rust-lang/reference#974 , fixing the Rust diagnostic might be trickier but I'm looking at it
Activity
Manishearth commentedon Mar 7, 2021
The reference is referring to Rust 2015 and needs to be updated.
I don't think we need a name for it, but rather we can specify that when you use
::then the thing after it must be a crate name.Manishearth commentedon Mar 7, 2021
Actually, it's called the "extern prelude" but nobody uses that term. The reference mentions this.
mcclure commentedon Mar 7, 2021
Twitter kind of makes it unclear exactly what Cryze is linking there so to be clear: the thing that confused me, as a newbie, reading the reference is in 2.7 of the reference, it says:
Until this was explained to me, it sounded to me like these two quotes were designing the same concept. The point of confusion for me was that "the crate root" could ambiguously be read as "the root of all crates" or "the root of the crate". I was reading the reference and maybe it is expected a reader of the reference realizes "the crate root" means something specific and special, but it did trip me up.
Manishearth commentedon Mar 7, 2021
Yeah the "crate root" means a specific thing, whereas
::refers to some notion of "global path" which differs based on edition -- "crate root" in 2015, and "extern prelude" in 2018+. We should stop saying::is the crate root. I already have a PR for the reference in rust-lang/reference#974 , fixing the Rust diagnostic might be trickier but I'm looking at itManishearth commentedon Mar 7, 2021
I have patches for this, just need to update test expectations
Manishearth commentedon Mar 7, 2021
#82881
Rollup merge of rust-lang#82881 - Manishearth:crate-root, r=estebank