Closed
Description
The following two snippets:
#![crate_type = "lib"]
use core::option::Option;
#![crate_type = "lib"]
const _: core::option::Option<u32> = None;
I expected both of them to either compile, or not.
Instead, only the const
one compiles, while the use
one doesn't:
error[E0433]: failed to resolve: maybe a missing crate `core`?
--> ./x.rs:2:5
|
2 | use core::option::Option;
| ^^^^ maybe a missing crate `core`?
|
= help: consider adding `extern crate core` to use the `core` crate
Note that the core
crate is not defined in either test, as can be seen by using -Zunpretty=hir
:
#![crate_type = "lib"]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
use core::option::Option;
#![crate_type = "lib"]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
const _: core::option::Option<()> = None;
Similarly to a const
, impl core::iter::Iterator for ... { ... }
, fn f() { core::option::Option::Some(()) }
, fn f() -> core::option::Option<()> { None }
and others work. The only thing I could find to issue an error is a use
.
Edition note:
- non-
use
- On 2015
core::option::Option
will work, but both::core::...
andcrate::core::...
will error - On 2018 and 2021
core::option::Option
and::core::...
will work, butcrate::
will error
- On 2015
use
- On 2015 none of
core::...
,::core::...
andcrate::core
work - On 2018 and 2021 only
core::...
and::core::....
works, whilecrate::core
doesn't
- On 2015 none of
Given all of that it seems that
core
is in the extern prelude (as documented), butcore
is not present at the crate root, but- Everything that is not a
use
can access stuff from extern prelude
This is very confusing to say the least.
I'd expect any of the following outcomes:
core
is both in the extern prelude and crate root, anything can refer to it (IMO the best option)core
is neither in the extern prelude nor in the crate root, nothing can refer to it
But not what we currently have...
Meta
rustc --version --verbose
:
rustc 1.72.0-nightly (065a1f5df 2023-06-21)
binary: rustc
commit-hash: 065a1f5df9c2f1d93269e4d25a2acabbddb0db8d
commit-date: 2023-06-21
host: aarch64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5