Skip to content

Commit bd6e4a9

Browse files
authored
Merge pull request #217 from rust-lang/rust-1.36-37
update guide for 1.36 and 1.37
2 parents 2e2a8f3 + ba43bb4 commit bd6e4a9

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

src/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@
9999
- [Pinning](rust-next/pin.md)
100100
- [No more FnBox](rust-next/no-more-fnbox.md)
101101
- [Alternative Cargo Registries](rust-next/alternative-cargo-registries.md)
102-
- [TryFrom and TryInto](rust-next/tryfrom-and-tryinto.md)
102+
- [TryFrom and TryInto](rust-next/tryfrom-and-tryinto.md)
103+
- [The Future trait](rust-next/future.md)
104+
- [The alloc crate](rust-next/alloc.md)
105+
- [MaybeUninit<T>](rust-next/maybe-uninit.md)
106+
- [cargo vendor](rust-next/cargo-vendor.md)

src/rust-next/alloc.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# The alloc crate
2+
3+
Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg)
4+
5+
Before 1.36.0, the standard library consisted of the crates `std`, `core`, and `proc_macro`.
6+
The `core` crate provided core functionality such as `Iterator` and `Copy`
7+
and could be used in `#![no_std]` environments since it did not impose any requirements.
8+
Meanwhile, the `std` crate provided types like `Box<T>` and OS functionality
9+
but required a global allocator and other OS capabilities in return.
10+
11+
Starting with Rust 1.36.0, the parts of `std` that depend on a global allocator, e.g. `Vec<T>`,
12+
are now available in the `alloc` crate. The `std` crate then re-exports these parts.
13+
While `#![no_std]` *binaries* using `alloc` still require nightly Rust,
14+
`#![no_std]` *library* crates can use the `alloc` crate in stable Rust.
15+
Meanwhile, normal binaries, without `#![no_std]`, can depend on such library crates.
16+
We hope this will facilitate the development of a `#![no_std]` compatible ecosystem of libraries
17+
prior to stabilizing support for `#![no_std]` binaries using `alloc`.
18+
19+
If you are the maintainer of a library that only relies on some allocation primitives to function,
20+
consider making your library `#[no_std]` compatible by using the following at the top of your `lib.rs` file:
21+
22+
```rust,ignore
23+
#![no_std]
24+
25+
extern crate alloc;
26+
27+
use alloc::vec::Vec;
28+
```

src/rust-next/cargo-vendor.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# cargo vendor
2+
3+
Initially added: ![Minimum Rust version: 1.37](https://img.shields.io/badge/Minimum%20Rust%20Version-1.37-brightgreen.svg)
4+
5+
After being available [as a separate crate][vendor-crate] for years, the `cargo vendor` command is now integrated directly into Cargo. The command fetches all your project's dependencies unpacking them into the `vendor/` directory, and shows the configuration snippet required to use the vendored code during builds.
6+
7+
There are multiple cases where `cargo vendor` is already used in production: the Rust compiler `rustc` uses it to ship all its dependencies in release tarballs, and projects with monorepos use it to commit the dependencies' code in source control.
8+
9+
[vendor-crate]: https://crates.io/crates/cargo-vendor

src/rust-next/future.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The Future trait
2+
3+
Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg)
4+
5+
In Rust 1.36.0 the long awaited [`Future`] trait has been stabilized!
6+
7+
TODO: this will probably be folded into a larger async section once we're
8+
closer to the next edition.
9+
10+
[`Future`]: https://doc.rust-lang.org/std/future/trait.Future.html

src/rust-next/maybe-uninit.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# MaybeUninit
2+
3+
Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg)
4+
5+
In previous releases of Rust, the [`mem::uninitialized`] function has allowed
6+
you to bypass Rust's initialization checks by pretending that you've
7+
initialized a value at type `T` without doing anything. One of the main uses
8+
of this function has been to lazily allocate arrays.
9+
10+
However, [`mem::uninitialized`] is an incredibly dangerous operation that
11+
essentially cannot be used correctly as the Rust compiler assumes that values
12+
are properly initialized. For example, calling `mem::uninitialized::<bool>()`
13+
causes *instantaneous __undefined behavior__* as, from Rust's point of view,
14+
the uninitialized bits are neither `0` (for `false`) nor `1` (for `true`) -
15+
the only two allowed bit patterns for `bool`.
16+
17+
To remedy this situation, in Rust 1.36.0, the type [`MaybeUninit<T>`] has
18+
been stabilized. The Rust compiler will understand that it should not assume
19+
that a [`MaybeUninit<T>`] is a properly initialized `T`. Therefore, you can
20+
do gradual initialization more safely and eventually use `.assume_init()`
21+
once you are certain that `maybe_t: MaybeUninit<T>` contains an initialized
22+
`T`.
23+
24+
As [`MaybeUninit<T>`] is the safer alternative, starting with Rust 1.39, the
25+
function [`mem::uninitialized`] will be deprecated.
26+
27+
[`MaybeUninit<T>`]: https://doc.rust-lang.org/std/mem/union.MaybeUninit.html
28+
[`mem::uninitialized`]: https://doc.rust-lang.org/std/mem/fn.uninitialized.html

0 commit comments

Comments
 (0)