From 561d393a4d4039b408fe7180d80a8ecd162e06b5 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 16 Jan 2019 13:47:41 -0500 Subject: [PATCH 1/7] Announcing Rust 1.32.0 --- posts/2019-01-17-Rust-1.32.0.md | 274 ++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 posts/2019-01-17-Rust-1.32.0.md diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md new file mode 100644 index 000000000..4840b52dc --- /dev/null +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -0,0 +1,274 @@ +--- +layout: post +title: "Announcing Rust 1.32.0" +author: The Rust Release Team +--- + +The Rust team is happy to announce a new version of Rust, 1.32.0. Rust is a +programming language that is empowering everyone to build reliable and +efficient software. + +If you have a previous version of Rust installed via rustup, getting Rust +1.32.0 is as easy as: + +``` +$ rustup update stable +``` + +If you don't have it already, you can [get `rustup`][install] from the +appropriate page on our website, and check out the [detailed release notes for +1.32.0][notes] on GitHub. + +[install]: https://www.rust-lang.org/install.html +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1320-2019-01-17 + +## What's in 1.32.0 stable + +Rust 1.32.0 has a few quality of life improvements, switches the default +allocator, and makes additional functions `const`. Read on for a few +highlights, or see the [detailed release notes][notes] for additional +information. + +#### The `dbg` macro + +First up, a small quality of life improvement. Are you a "printf debugger"? If you are, and +you've wanted to print out some value while working on some code, you have to do this: + +```rust +let x = 5; + +println!("{:?}", x); + +// or maybe even this +println!("{:#?}", x); +``` + +This isn't the *largest* speed bump, but it is a lot of stuff to simply show the value of `x`. +Additionally, there's no context here. If you have several of these `println!`s, it can be hard +to tell which is which, unless you add your own context to each invocation, causing even more work. + +In Rust 1.32.0, [we've added a new macro, +`dbg!`](https://github.com/rust-lang/rust/pull/56395/), for this purpose: + +```rust +fn main() { + let x = 5; + + dbg!(x); +} +``` + +If you run this program, you'll see: + +```text +[src/main.rs:4] x = 5 +``` + +You get the file and line number of where this was invoked, as well as the +name and value. Additionally, `println!` prints to the standard output, so +you really should be using `eprintln!` to print to standard error. `dbg!` +does the right thing and goes to `stderr` by default. + +It even works in more complex circumstances. Consider this factorial example: + +```rust +fn factorial(n: u32) -> u32 { + if n <= 1 { + n + } else { + n * factorial(n - 1) + } +} +``` + +If we wanted to debug this, we might write it like this with `eprintln!`: + +```rust +fn factorial(n: u32) -> u32 { + eprintln!("n: {}", n); + + if n <= 1 { + eprintln!("n <= 1"); + + n + } else { + let n = n * factorial(n - 1); + + eprintln!("n: {}", n); + + n + } +} +``` + +We want to log `n` on each iteration, as well as have some kind of context +for each of the branches. We see this output for `factorial(4)`: + +```text +n: 4 +n: 3 +n: 2 +n: 1 +n <= 1 +n: 2 +n: 6 +n: 24 +``` + +This is servicable, but not particularly great. Maybe we could work on how we +print out the context to make it more clear, but now we're not debugging our code, +we're figuring out how to make our debugging code better. + +Consider this version using `dbg!`: + +```rust +fn factorial(n: u32) -> u32 { + if dbg!(n <= 1) { + dbg!(1) + } else { + dbg!(n * factorial(n - 1)) + } +} +``` + +We simply wrap each of the various expressions we want to print with the macro. We +get this output instead: + +```text +[src/main.rs:3] n <= 1 = false +[src/main.rs:3] n <= 1 = false +[src/main.rs:3] n <= 1 = false +[src/main.rs:3] n <= 1 = true +[src/main.rs:4] 1 = 1 +[src/main.rs:5] n * factorial(n - 1) = 2 +[src/main.rs:5] n * factorial(n - 1) = 6 +[src/main.rs:5] n * factorial(n - 1) = 24 +[src/main.rs:11] factorial(4) = 24 +``` + +Because the `dbg!` macro returns the value of what it's debugging, instead of +`eprintln!` which returns `()`, we need to make *no* changes to the structure +of our code. Additionally, we have *vastly* more useful output. + +That's a lot to say about a little macro, but we hope it improves your +debugging experience! We are contining to work on support for `gdb` and +friends as well, of course. + +#### `jemalloc` is removed by default + +Long, long ago, Rust had a large, Erlang-like runtime. We chose to use +[jemalloc] instead of the system allocator, because it often improved +performance over the default system one. Over time, we shed more and more of +this runtime, and eventually almost all of it was removed, but jemalloc +didn't. We didn't have a way to choose a custom allocator, and so we couldn't +really remove it without causing a regression for people who do need +jemalloc. + +Also, saying that `jemalloc` was always the default is a bit UNIX-centric, +as it was only the default on *some* platforms. Notably, the MSVC target on +Windows has shipped the system allocator for a long time. + +Finally, while jemalloc *usually* has great performance, that's not always +the case. Additionally, it adds about 300kb to every Rust binary. We've also +had a host of [other +issues](https://github.com/rust-lang/rust/issues/36963#issuecomment-252029017) +with jemalloc in the past. It has also felt a little strange that a systems +language does not default to the system's allocator. + +For all of these reasons, once [Rust 1.28 shipped a way to choose a global +allocator](https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#whats-in-1.28.0-stable), +we started making plans to switch the default to the system allocator, and +allow you to use `jemalloc` via a crate. In Rust 1.32, we've finally finished +this work, and by default, you will get the system allocator for your +programs. + +If you'd like to continue to use jemalloc, use [the jemallocator crate]. In +your `Cargo.toml`: + +```toml +jemallocator = "0.1.8" +``` + +And in your crate root: + +```rust +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; +``` + +That's it! If you don't need jemalloc, it's not forced upon you, and if +you do need it, it's a few lines of code away. + +[jemalloc]: http://jemalloc.net/ +[the jemallocator crate]: https://crates.io/crates/jemallocator + +#### Macro improvements + +A few improvements to macros have landed in Rust 1.32.0. First, [a new +`literal` matcher](https://github.com/rust-lang/rust/pull/56072/) was added: + +```rust +macro_rules! m { + ($lt:literal) => {}; +} + +fn main() { + m!("some string literal"); +} +``` + +`literal` mactches against literals of any type; string literals, numeric literals, `char` literals. + +In the 2018 edition, `macro_rules` macros can also use `?`, like this: + +```rust +macro_rules! bar { + ($(a)?) => {} +} +``` + +The `?` will match zero or one repitions of the pattern, similar to the +already-existing `*` for "zero or more" and `+` for "one or more." + +#### Final module improvements + +In Rust 1.30.0, [we announced several improvements to the module +system](https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#module-system-changes). +We have one last tweak landing in 1.32.0 and the 2018 edition. Nicknamed +["uniform paths"](https://github.com/rust-lang/rust/pull/56759/), the simplest way to explain +it is to show you this code: + +```rust +enum Color { Red, Green, Blue } + +use Color::*; +``` + +This code did *not* previously compile, as `use` statements had to start with +`super`, `self`, or `crate`. With this change, this code will work, and do +what you probably expect: import the variants of the `Color` enum defined +above the `use` statement. + +With this change in place, we've completed our efforts at revising the module +system. We hope you've been enjoying the simplified system so far! + +### Library stabilizations + +We talked above about the `dbg!` macro, which is a big library addition. +Beyond that, 19 functions were made `const fn`s, and all 72 combinations of +the `to_*_bytes` and `from_*_bytes` methods, where `*` is one of `{be, le, +ne}`, were added to `{usize,isize,i8,i16,i32,i64,i128,u8,u16,u32,u64,u128}`. +See the [detailed release notes][notes] for more details. + +### Cargo features + +Cargo gained [`cargo c` as an alias for `cargo +check`](https://github.com/rust-lang/cargo/pull/6218/), and now [allows +usernames in registry URLs](https://github.com/rust-lang/cargo/pull/6242/). + +See the [detailed release notes][notes] for more. + +## Contributors to 1.32.0 + +Many people came together to create Rust 1.32.0. We couldn't have done it +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.32.0) \ No newline at end of file From e7c8bf50396f23a8812b99ed017735f9a47e40e5 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 16 Jan 2019 14:43:45 -0500 Subject: [PATCH 2/7] Update posts/2019-01-17-Rust-1.32.0.md Co-Authored-By: steveklabnik --- posts/2019-01-17-Rust-1.32.0.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md index 4840b52dc..44cbfdd88 100644 --- a/posts/2019-01-17-Rust-1.32.0.md +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -227,7 +227,7 @@ macro_rules! bar { } ``` -The `?` will match zero or one repitions of the pattern, similar to the +The `?` will match zero or one repetitions of the pattern, similar to the already-existing `*` for "zero or more" and `+` for "one or more." #### Final module improvements @@ -271,4 +271,4 @@ See the [detailed release notes][notes] for more. ## Contributors to 1.32.0 Many people came together to create Rust 1.32.0. We couldn't have done it -without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.32.0) \ No newline at end of file +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.32.0) From 538dac70cac74af8178b7a0ac619b4a47cde3a52 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 17 Jan 2019 10:54:19 -0500 Subject: [PATCH 3/7] Update posts/2019-01-17-Rust-1.32.0.md Co-Authored-By: steveklabnik --- posts/2019-01-17-Rust-1.32.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md index 44cbfdd88..42c342a0d 100644 --- a/posts/2019-01-17-Rust-1.32.0.md +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -31,7 +31,7 @@ information. #### The `dbg` macro -First up, a small quality of life improvement. Are you a "printf debugger"? If you are, and +First up, a quality of life improvement. Are you a "printf debugger"? If you are, and you've wanted to print out some value while working on some code, you have to do this: ```rust From 3ee85e37a05ff21f726a647842631f18c88ee475 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 17 Jan 2019 10:54:35 -0500 Subject: [PATCH 4/7] Update posts/2019-01-17-Rust-1.32.0.md Co-Authored-By: steveklabnik --- posts/2019-01-17-Rust-1.32.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md index 42c342a0d..706c97e59 100644 --- a/posts/2019-01-17-Rust-1.32.0.md +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -45,7 +45,7 @@ println!("{:#?}", x); This isn't the *largest* speed bump, but it is a lot of stuff to simply show the value of `x`. Additionally, there's no context here. If you have several of these `println!`s, it can be hard -to tell which is which, unless you add your own context to each invocation, causing even more work. +to tell which is which, unless you add your own context to each invocation, requiring even more work. In Rust 1.32.0, [we've added a new macro, `dbg!`](https://github.com/rust-lang/rust/pull/56395/), for this purpose: From eb897dd26bead1148dc3c161f3710e74c16116bb Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 17 Jan 2019 10:55:53 -0500 Subject: [PATCH 5/7] review fixes --- posts/2019-01-17-Rust-1.32.0.md | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md index 706c97e59..907f31124 100644 --- a/posts/2019-01-17-Rust-1.32.0.md +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -31,7 +31,7 @@ information. #### The `dbg` macro -First up, a quality of life improvement. Are you a "printf debugger"? If you are, and +First up, a quality of life improvement. Are you a "print debugger"? If you are, and you've wanted to print out some value while working on some code, you have to do this: ```rust @@ -67,7 +67,7 @@ If you run this program, you'll see: You get the file and line number of where this was invoked, as well as the name and value. Additionally, `println!` prints to the standard output, so you really should be using `eprintln!` to print to standard error. `dbg!` -does the right thing and goes to `stderr` by default. +does the right thing and goes to `stderr`. It even works in more complex circumstances. Consider this factorial example: @@ -160,8 +160,8 @@ Long, long ago, Rust had a large, Erlang-like runtime. We chose to use [jemalloc] instead of the system allocator, because it often improved performance over the default system one. Over time, we shed more and more of this runtime, and eventually almost all of it was removed, but jemalloc -didn't. We didn't have a way to choose a custom allocator, and so we couldn't -really remove it without causing a regression for people who do need +was not. We didn't have a way to choose a custom allocator, and so we +couldn't really remove it without causing a regression for people who do need jemalloc. Also, saying that `jemalloc` was always the default is a bit UNIX-centric, @@ -232,11 +232,12 @@ already-existing `*` for "zero or more" and `+` for "one or more." #### Final module improvements -In Rust 1.30.0, [we announced several improvements to the module -system](https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#module-system-changes). -We have one last tweak landing in 1.32.0 and the 2018 edition. Nicknamed -["uniform paths"](https://github.com/rust-lang/rust/pull/56759/), the simplest way to explain -it is to show you this code: +In the past two releases, we announced several improvements to the module +system. We have one last tweak landing in 1.32.0 and the 2018 edition. +Nicknamed ["uniform +paths"](https://github.com/rust-lang/rust/pull/56759#issuecomment-450051210), +it permits previously invalid import path statements to be resolved exactly +the same way as non-import paths. For example: ```rust enum Color { Red, Green, Blue } @@ -245,9 +246,9 @@ use Color::*; ``` This code did *not* previously compile, as `use` statements had to start with -`super`, `self`, or `crate`. With this change, this code will work, and do -what you probably expect: import the variants of the `Color` enum defined -above the `use` statement. +`super`, `self`, or `crate`. Now that the compiler supports uniform paths, +this code will work, and do what you probably expect: import the variants of +the `Color` enum defined above the `use` statement. With this change in place, we've completed our efforts at revising the module system. We hope you've been enjoying the simplified system so far! @@ -255,9 +256,15 @@ system. We hope you've been enjoying the simplified system so far! ### Library stabilizations We talked above about the `dbg!` macro, which is a big library addition. -Beyond that, 19 functions were made `const fn`s, and all 72 combinations of -the `to_*_bytes` and `from_*_bytes` methods, where `*` is one of `{be, le, -ne}`, were added to `{usize,isize,i8,i16,i32,i64,i128,u8,u16,u32,u64,u128}`. +Beyond that, 19 functions were made `const fn`s, and all integral numeric +primitives now provide conversion functions to and from byte-arrays with +specified edianness. These six functions are named `to__bytes` and +`from__bytes`, where `` is one of: + +* `ne` - native endianness +* `le` - little endian +* `be` - big endian + See the [detailed release notes][notes] for more details. ### Cargo features From 3771e7a826736f93025282a275023b7cc53ce331 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 17 Jan 2019 10:57:17 -0500 Subject: [PATCH 6/7] move this section up a bit --- posts/2019-01-17-Rust-1.32.0.md | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md index 907f31124..9e33ce7ac 100644 --- a/posts/2019-01-17-Rust-1.32.0.md +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -202,6 +202,30 @@ you do need it, it's a few lines of code away. [jemalloc]: http://jemalloc.net/ [the jemallocator crate]: https://crates.io/crates/jemallocator +#### Final module improvements + +In the past two releases, we announced several improvements to the module +system. We have one last tweak landing in 1.32.0 and the 2018 edition. +Nicknamed ["uniform +paths"](https://github.com/rust-lang/rust/pull/56759#issuecomment-450051210), +it permits previously invalid import path statements to be resolved exactly +the same way as non-import paths. For example: + +```rust +enum Color { Red, Green, Blue } + +use Color::*; +``` + +This code did *not* previously compile, as `use` statements had to start with +`super`, `self`, or `crate`. Now that the compiler supports uniform paths, +this code will work, and do what you probably expect: import the variants of +the `Color` enum defined above the `use` statement. + +With this change in place, we've completed our efforts at revising the module +system. We hope you've been enjoying the simplified system so far! + + #### Macro improvements A few improvements to macros have landed in Rust 1.32.0. First, [a new @@ -230,29 +254,6 @@ macro_rules! bar { The `?` will match zero or one repetitions of the pattern, similar to the already-existing `*` for "zero or more" and `+` for "one or more." -#### Final module improvements - -In the past two releases, we announced several improvements to the module -system. We have one last tweak landing in 1.32.0 and the 2018 edition. -Nicknamed ["uniform -paths"](https://github.com/rust-lang/rust/pull/56759#issuecomment-450051210), -it permits previously invalid import path statements to be resolved exactly -the same way as non-import paths. For example: - -```rust -enum Color { Red, Green, Blue } - -use Color::*; -``` - -This code did *not* previously compile, as `use` statements had to start with -`super`, `self`, or `crate`. Now that the compiler supports uniform paths, -this code will work, and do what you probably expect: import the variants of -the `Color` enum defined above the `use` statement. - -With this change in place, we've completed our efforts at revising the module -system. We hope you've been enjoying the simplified system so far! - ### Library stabilizations We talked above about the `dbg!` macro, which is a big library addition. From 532af66179ac0c88a66beda804eb37e5291d717d Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 17 Jan 2019 11:05:24 -0500 Subject: [PATCH 7/7] rustup update notice --- posts/2019-01-17-Rust-1.32.0.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/posts/2019-01-17-Rust-1.32.0.md b/posts/2019-01-17-Rust-1.32.0.md index 9e33ce7ac..4a19f2e77 100644 --- a/posts/2019-01-17-Rust-1.32.0.md +++ b/posts/2019-01-17-Rust-1.32.0.md @@ -19,6 +19,9 @@ If you don't have it already, you can [get `rustup`][install] from the appropriate page on our website, and check out the [detailed release notes for 1.32.0][notes] on GitHub. +> As a small side note, `rustup` has seen some new releases lately! To update +> `rustup` itself, run `rustup self update`. + [install]: https://www.rust-lang.org/install.html [notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1320-2019-01-17