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
> When one of [`core::panic!`] or [`std::panic!`] is brought into scope due to the [standard library prelude], and a user-written [glob import] brings the other into scope, `rustc` currently allows use of `panic!`, even though it is ambiguous. The user-written glob import takes precedence to resolve this ambiguity.
235
+
>
236
+
> In Rust 2021 and later, [`core::panic!`] and [`std::panic!`] operate identically. But in earlier editions, they differ; only [`std::panic!`] accepts a [`String`] as the format argument.
237
+
>
238
+
> E.g., this is an error:
239
+
>
240
+
> ```rust,edition2018,compile_fail,E0308
241
+
> extern crate core;
242
+
> use ::core::prelude::v1::*;
243
+
> fn main() {
244
+
> panic!(std::string::String::new()); // ERROR.
245
+
> }
246
+
> ```
247
+
>
248
+
> And this is accepted:
249
+
>
250
+
> <!-- ignore: Can't test with `no_std`. -->
251
+
> ```rust,edition2018,ignore
252
+
> #![no_std]
253
+
> extern crate std;
254
+
> use ::std::prelude::v1::*;
255
+
> fn main() {
256
+
> panic!(std::string::String::new()); // OK.
257
+
> }
258
+
> ```
259
+
>
260
+
> Don't rely on this behavior; the plan is to remove it.
261
+
>
262
+
> For details, see [Rust issue #147319](https://github.com/rust-lang/rust/issues/147319).
> [`core::prelude::rust_2015`] and [`core::prelude::rust_2018`] have the same contents as [`core::prelude::v1`].
42
42
43
+
> [!NOTE]
44
+
> When one of [`core::panic!`] or [`std::panic!`] is brought into scope due to the [standard library prelude], and a user-written [glob import] brings the other into scope, `rustc` currently allows use of `panic!`, even though it is ambiguous. The user-written glob import takes precedence to resolve this ambiguity.
45
+
>
46
+
> For details, see [names.resolution.expansion.imports.ambiguity.panic-hack].
47
+
43
48
r[names.preludes.extern]
44
49
## Extern prelude
45
50
@@ -81,7 +86,7 @@ r[names.preludes.extern.no_std]
81
86
### The `no_std` attribute
82
87
83
88
r[names.preludes.extern.no_std.intro]
84
-
The*`no_std` [attribute][attributes]*causesthe [`std`] cratetonotbelinkedautomatically, the [standardlibraryprelude] toinsteaduse the `core` prelude, and the [`macro_use` prelude] to instead use the macros exported from the `core` crate.
89
+
The*`no_std` [attribute][attributes]*causesthe [`std`] cratetonotbelinkedautomaticallyandthe [standardlibraryprelude] toinsteaduse the `core` prelude.
85
90
86
91
> [!EXAMPLE]
87
92
> <!-- ignore: test infrastructure can't handle no_std -->
@@ -110,9 +115,6 @@ The `no_std` attribute may be used any number of times on a form.
110
115
r[names.preludes.extern.no_std.module]
111
116
The `no_std` attribute changes the [standard library prelude] to use the `core` prelude instead of the `std` prelude.
112
117
113
-
r[names.preludes.extern.no_std.macro_use]
114
-
By default, all macros exported from the `std` crate are added to the [`macro_use` prelude].If the `no_std` attribute is specified, then all macros exported from the `core` crate are placed into the [`macro_use` prelude] instead.
115
-
116
118
r[names.preludes.extern.no_std.edition2018]
117
119
> [!EDITION-2018]
118
120
> Before the 2018 edition, `std` is injected into the crate root by default.If `no_std` is specified, `core` is injected instead.Starting with the 2018 edition, regardless of `no_std` being specified, neither is injected into the crate root.
@@ -190,6 +192,41 @@ The `no_implicit_prelude` attribute may be used any number of times on a form.
The `no_implicit_prelude` attribute prevents the [standard library prelude], [extern prelude], [`macro_use` prelude], and the [tool prelude] from being brought into scope for the module and its descendants.
0 commit comments