From 8f8dfbdbda58ec0cd8ac0887718b7dc2a9bfe204 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 29 Nov 2018 11:16:26 -0500 Subject: [PATCH 01/16] start post --- _posts/2018-12-06.Rust-1.31.md | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 _posts/2018-12-06.Rust-1.31.md diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md new file mode 100644 index 000000000..a79607979 --- /dev/null +++ b/_posts/2018-12-06.Rust-1.31.md @@ -0,0 +1,45 @@ +--- +layout: post +title: "Announcing Rust 1.31" +author: The Rust Core Team +--- + +The Rust team is happy to announce a new version of Rust, 1.31.0. Rust is a +systems programming language focused on safety, speed, and concurrency. + +If you have a previous version of Rust installed via rustup, getting Rust +1.31.0 is as easy as: + +```bash +$ 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.31.0][notes] on GitHub. + +[install]: https://www.rust-lang.org/install.html +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1310-2018-12-06 + +## What's in 1.31.0 stable + + +### Library stabilizations + +Three APIs were stabilized this release: + +* [`Arc::downcast`](https://doc.rust-lang.org/std/sync/struct.Arc.html#method.downcast) + +Additionally, you can [now compare `&str` and +`OsString`](https://github.com/rust-lang/rust/pull/51178/). + +See the [detailed release notes][notes] for more. + +### Cargo features + +See the [detailed release notes][notes] for more. + +## Contributors to 1.31.0 + +Many people came together to create Rust 1.31. We couldn't have done it +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) From 3f2abeac1264abc878ec40dc054374d2d70d6da6 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 4 Dec 2018 14:08:32 -0500 Subject: [PATCH 02/16] Rust 1.31 announcement --- _posts/2018-12-06.Rust-1.31.md | 303 ++++++++++++++++++++++++++++++++- 1 file changed, 298 insertions(+), 5 deletions(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index a79607979..620052686 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -23,23 +23,316 @@ appropriate page on our website, and check out the [detailed release notes for ## What's in 1.31.0 stable +Rust 1.31 may be the most exciting release since Rust 1.0! Included in this release is the +first iteration of "Rust 2018," but there's more than just that! This is going to be a long +post, so here's a table of contents: + +* [Rust 2018](#rust-2018) + * [Non-lexical lifetimes](#non-lexical-lifetimes) + * [Module system changes](#module-system-changes) +* [More lifetime elision rules](#more-lifetime-elision-rules) +* [`const fn`](#const-fn) +* [Tool Lints](#tool-lints) +* [Library stabilizations](#library-stabilizations) +* [Cargo features](#cargo-features) +* [Contributors](#contributors-to-1310) + +### Rust 2018 + +We wrote about Rust 2018 [first in +March](https://blog.rust-lang.org/2018/03/12/roadmap.html), [and then in +July](https://blog.rust-lang.org/2018/07/27/what-is-rust-2018.html). +For some more background about the *why* of Rust 2018, please go read those +posts; there's a lot to cover in the release announcement, and so we're going +to focus on the *what* here. + +Let's create a new project with Cargo: + +```console +$ cargo new foo +``` + +Here's the contents of `Cargo.toml`: + +```toml +[package] +name = "foo" +version = "0.1.0" +authors = ["Your Name "] +edition = "2018" + +[dependencies] +``` + +A new key has been added under `[package]`: `edition`. You'll note it's been +set to `2018`. You can also set it to `2015`, which is the default if the key +does not exist. + +By using Rust 2018, you unlock some new features that are not allowed in Rust 2015. +And eventually, we'll be turning on some new warnings that help you use these +new features more effectively, as well. + +But it's important to note that each package you use can be in either 2015 or +2018 mode, and they work seamlessly together. Your 2018 project can use 2015 +dependencies, and a 2015 project can use 2018 dependencies. This ensures that +we don't split the ecosystem, and all of these new things are opt-in, +preserving compatibility for existing code. Furthermore, when you do choose +to migrate Rust 2015 code to Rust 2018, the changes can be made +automatically, via `cargo fix`. + +What kind of new features, you may ask? Well, first, features get added to +Rust 2015 unless they require some sort of incompatibility with 2015's +features. As such, most of the language is available everywhere. You can +check out [the edition +guide](https://doc.rust-lang.org/nightly/edition-guide) to check each +feature's minimum `rustc` version as well as edition requirements. However, +there are a few big-ticket features we'd like to mention here: non-lexical +lifetimes, and some module system improvements. + +#### Non-lexical lifetimes + +If you've been following Rust's development over the past few years, you may +have heard the term "NLL" or "non-lexical lifetimes" thrown around. This is +jargon, but it has a straightforward translation into simpler terms: the +borrow checker has gotten smarter, and now accepts some valid code that it +previously rejected. Consider this example: + +```rust +fn main() { + let mut x = 5; + + let y = &x; + + let z = &mut x; +} +``` + +In older Rust, this is a compile-time error: + +```text +error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable + --> src/main.rs:5:18 + | +4 | let y = &x; + | - immutable borrow occurs here +5 | let z = &mut x; + | ^ mutable borrow occurs here +6 | } + | - immutable borrow ends here +``` + +This is because lifetimes follow "lexical scope"; that is, the borrow from `y` +is considered to be held until `y` goes out of scope at the end of main, even +though we never use `y` again. This code is fine, but the borrow checker could +not handle it. + +Today, this code will compile just fine. + +What if we did use `y`, like this for example: + +```rust +fn main() { + let mut x = 5; + let y = &x; + let z = &mut x; + + println!("y: {}", y); +} +``` + +Older Rust will give you this error: + +```text +rror[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable + --> src/main.rs:5:18 + | +4 | let y = &x; + | - immutable borrow occurs here +5 | let z = &mut x; + | ^ mutable borrow occurs here +... +8 | } + | - immutable borrow ends here +``` + +With Rust 2018, this error changes for the better: + +```text +error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable + --> src/main.rs:5:13 + | +4 | let y = &x; + | -- immutable borrow occurs here +5 | let z = &mut x; + | ^^^^^^ mutable borrow occurs here +6 | +7 | println!("y: {}", y); + | - borrow later used here +``` + +Instead of pointing to where `y` goes out of scope, it shows you where the +conflicting borrow occurs. This makes these sorts of errors far easier to +debug. + +In Rust 1.31, this feature is exclusive to Rust 2018. We hope to backport it +to Rust 2015 at a later date. + +#### Module system changes + +The module system is often one of the hardest things for people new to Rust. +Everyone has their own things that take time to master, of course, but +there's a root cause for why it's so confusing to many: while there are +simple and consistent rules defining the module system, their consequences +can feel inconsistent, counterintuitive and mysterious. + +As such, the 2018 edition of Rust introduces a few new module system +features, but they end up simplifying the module system, to make it more +clear as to what is going on. + +Here's a brief summary: + +* `extern crate` is no longer needed in 99% of circumstances. +* You can import macros with `use`, rather than a `#[macro_use]` attribute. +* Absolute paths begin with a crate name, where the keyword `crate` refers to the current crate. +* A `foo.rs` and `foo/` subdirectory may coexist; `mod.rs` is no longer needed when placing submodules in a subdirectory. + +These may seem like arbitrary new rules when put this way, but the mental +model is now significantly simplified overall. + +There's a *lot* of details here, so please read [the edition +guide](https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html) +for full details. + +### More lifetime elision rules + +Let's talk about a feature that's available in both editions: we've added +some additional elision rules for `impl` blocks and function definitions. +Code like this: + +```rust +impl<'a> Reader for BufReader<'a> { + // methods go here +} +` + +can now be written like this: + +```rust +impl Reader for BufReader<'_> { + // methods go here +} +``` + +The `'_` lifetime still shows that `BufReader` takes a parameter, but we +don't need to create a name for it anymore. + +Lifetimes are still required to be defined in structs. We're considering +some options here in the future, but have no concrete plans yet. + +### `const fn` + +There's several ways to define a function in Rust: a regular function with +`fn`, an unsafe function with `unsafe fn`, an external function with `extern fn`. +This release adds a new way to qualify a function: `const fn`. It looks like +this: + +```rust +const fn foo(x: i32) -> i32 { + x + 1 +} +``` + +A `const fn` can be called like a regular function, but it can also be used +in any constant context. When it is, it is evaluated at compile time, rather +than at run time. As an example: + +```rust +const SIX: i32 = foo(5); +``` + +This will execute `foo` at compile time, and set `SIX` to `6`. + +`const fn`s cannot do everything that normal `fn`s can do; they must +have deterministic output. This is important for soundness reasons. +Currently, `const fn`s can do a minimal subset of operations. Here's +some examples of what you can do: + +* Arithmetic and comparison operators on integers +* All boolean operators except for `&&` and `||` +* Constructing arrays, structs, enums, and tuples +* Calls to other `const fn`s +* Index expressions on arrays and slices +* Field accesses on structs and tuples +* Reading from constants (but not statics, not even taking a reference to a static) +* `&` and `*` of references +* Casts, except for raw pointer to integer casts + +We'll be slowly growing the abilities of `const fn`, but we've decided that +this is enough useful stuff to start shipping the feature itself. + +For full details, please see [the +reference](https://doc.rust-lang.org/reference/items/functions.html#const-functions). + +### Tool lints + +In [Rust 1.30](https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html), we +stabilized "tool attributes", like `#[rustfmt::skip]`. In Rust 1.31, we're +stabilizing something similar: "tool lints," like +`#[allow(clippy::something)]` These give a namespace to lints, so that it's +more clear which tool they're coming from. + +If you previously used Clippy's lints, you can migrate like this: + +```rust +// old +#![allow(bool_comparison)] + +// new +#![allow(clippy::bool_comparison)] +``` + +You'll get warnings that can help you update to the new style. ### Library stabilizations -Three APIs were stabilized this release: +A bunch of `From` implementations have been added: + +* `u8` now implements `From`, and likewise for the other numeric types and their `NonZero` equivalents +* `Option<&T>` implements `From<&Option>`, and likewise for `&mut` -* [`Arc::downcast`](https://doc.rust-lang.org/std/sync/struct.Arc.html#method.downcast) +Additionally, these functions have been stabilized: -Additionally, you can [now compare `&str` and -`OsString`](https://github.com/rust-lang/rust/pull/51178/). +* [`slice::align_to`](https://doc.rust-lang.org/std/primitive.slice.html#method.align_to) and its mutable counterpart +* [`slice::chunks_exact`](https://doc.rust-lang.org/std/primitive.slice.html#method.chunks_exact), + as well as its mutable and `r` counterparts (like + [`slice::rchunks_exact_mut`](https://doc.rust-lang.org/std/primitive.slice.html#method.rchunks_mut)) in all combinations See the [detailed release notes][notes] for more. ### Cargo features +Cargo will now download packages in parallel using HTTP/2. Additionally, +now that `extern crate` is gone, you can't `extern crate foo as bar;` anymore +to rename a crate. As such, you can do so in your `Cargo.toml`, like this: + +```toml +[dependencies] +baz = { version = "0.1", package = "foo" } +``` + +or, the equivalent + +```toml +[dependencies.baz] +version = "0.1" +package = "foo" +``` + +Now, the `baz` package will be able to be used via `foo` in your code. + See the [detailed release notes][notes] for more. ## Contributors to 1.31.0 Many people came together to create Rust 1.31. We couldn't have done it -without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) \ No newline at end of file From 7ca425ac287e855219d4be109110b6e1cab51a0e Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 6 Dec 2018 09:07:17 -0500 Subject: [PATCH 03/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index 620052686..9c06516bb 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -174,7 +174,7 @@ Instead of pointing to where `y` goes out of scope, it shows you where the conflicting borrow occurs. This makes these sorts of errors far easier to debug. -In Rust 1.31, this feature is exclusive to Rust 2018. We hope to backport it +In Rust 1.31, this feature is exclusive to Rust 2018. We plan to backport it to Rust 2015 at a later date. #### Module system changes @@ -335,4 +335,4 @@ See the [detailed release notes][notes] for more. ## Contributors to 1.31.0 Many people came together to create Rust 1.31. We couldn't have done it -without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) \ No newline at end of file +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) From 3ca3a1a501987921ec04c250501e89feb5fcdbb6 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 6 Dec 2018 09:07:28 -0500 Subject: [PATCH 04/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index 9c06516bb..ed6930414 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -179,7 +179,7 @@ to Rust 2015 at a later date. #### Module system changes -The module system is often one of the hardest things for people new to Rust. +The module system can be a struggle for people first learning Rust. Everyone has their own things that take time to master, of course, but there's a root cause for why it's so confusing to many: while there are simple and consistent rules defining the module system, their consequences From 3d22329ad9d4da0c2b1e7bce9f0e36e3c0637c9b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 6 Dec 2018 09:11:10 -0500 Subject: [PATCH 05/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index ed6930414..8d3e9b525 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -64,7 +64,7 @@ edition = "2018" [dependencies] ``` -A new key has been added under `[package]`: `edition`. You'll note it's been +A new key has been added under `[package]`: `edition`. Note that it has been set to `2018`. You can also set it to `2015`, which is the default if the key does not exist. From 4a12defa51f1d0c696e6f52df446adb6ae82b877 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 6 Dec 2018 09:11:22 -0500 Subject: [PATCH 06/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index 8d3e9b525..b084ee0a8 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -68,7 +68,7 @@ A new key has been added under `[package]`: `edition`. Note that it has been set to `2018`. You can also set it to `2015`, which is the default if the key does not exist. -By using Rust 2018, you unlock some new features that are not allowed in Rust 2015. +By using Rust 2018, some new features are unlocked that are not allowed in Rust 2015. And eventually, we'll be turning on some new warnings that help you use these new features more effectively, as well. From 27e840585098862041dd8ec7724ed22962befe79 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 6 Dec 2018 09:11:45 -0500 Subject: [PATCH 07/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index b084ee0a8..809c8d4c6 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -72,7 +72,7 @@ By using Rust 2018, some new features are unlocked that are not allowed in Rust And eventually, we'll be turning on some new warnings that help you use these new features more effectively, as well. -But it's important to note that each package you use can be in either 2015 or +It is important to note that each package can be in either 2015 or 2018 mode, and they work seamlessly together. Your 2018 project can use 2015 dependencies, and a 2015 project can use 2018 dependencies. This ensures that we don't split the ecosystem, and all of these new things are opt-in, From 30ae7d4948ee6df269f38c4b8c7b92ee8ec013c3 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 6 Dec 2018 09:12:09 -0500 Subject: [PATCH 08/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index 809c8d4c6..48a97167e 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -191,7 +191,7 @@ clear as to what is going on. Here's a brief summary: -* `extern crate` is no longer needed in 99% of circumstances. +* `extern crate` is no longer needed in almost all circumstances. * You can import macros with `use`, rather than a `#[macro_use]` attribute. * Absolute paths begin with a crate name, where the keyword `crate` refers to the current crate. * A `foo.rs` and `foo/` subdirectory may coexist; `mod.rs` is no longer needed when placing submodules in a subdirectory. From 652eb151bf1eb01ca6eeed1055db3a604df4d246 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 6 Dec 2018 09:13:16 -0500 Subject: [PATCH 09/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index 48a97167e..b8379c60e 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -267,7 +267,7 @@ some examples of what you can do: * `&` and `*` of references * Casts, except for raw pointer to integer casts -We'll be slowly growing the abilities of `const fn`, but we've decided that +We'll be growing the abilities of `const fn`, but we've decided that this is enough useful stuff to start shipping the feature itself. For full details, please see [the From 90b0dbbfb87f8f60d32719f2b9b6187254927a2c Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 6 Dec 2018 09:21:00 -0500 Subject: [PATCH 10/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index b8379c60e..ff04dda0a 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -272,7 +272,25 @@ this is enough useful stuff to start shipping the feature itself. For full details, please see [the reference](https://doc.rust-lang.org/reference/items/functions.html#const-functions). +### New tools +The 2018 edition signals a new level of maturity for Rust's tools ecosystem. Cargo, Rustdoc, and Rustup have been crucial tools since 1.0; with the 2018 edition, there is a new generation of tools ready for all users: Clippy, Rustfmt, and IDE support. + +--- Clippy (Manish) goes here --- + +[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code. Automatically formatting your code lets you save time and arguments by using the [official Rust style](https://github.com/rust-lang/rfcs/blob/master/style-guide/README.md). You can install with `rustup component add rustfmt` and use it with `cargo fmt`. + +This release includes Rustfmt 1.0. From now on we guarantee backwards compatibility for Rustfmt: if you can format your code today, then the formatting will not change in the future (only with the default options). Backwards compatibility means that running Rustfmt on your CI is practical (use `cargo fmt --check`). Try that and 'format on save' in your editor to revolutionize your workflow. + +IDE support is one of the most requested tooling features for Rust. There are now multiple, high quality options: + +* [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust) +* [IntelliJ](https://plugins.jetbrains.com/plugin/8182-rust) +* [Atom](https://github.com/rust-lang-nursery/atom-ide-rust) +* [Sublime Text 3](https://github.com/rust-lang/rust-enhanced) +* [Eclipse](https://www.eclipse.org/downloads/packages/release/photon/r/eclipse-ide-rust-developers-includes-incubating-components) + +Work on IDE support is not finished, in particular code completion is not up to scratch in the RLS-based editors. However, if you mainly want support for types, documentation, and 'go to def', etc. then you should be happy. ### Tool lints In [Rust 1.30](https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html), we From 41a891c5ebd5d70a8ba98608a1a5f740d58b98d8 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 6 Dec 2018 09:23:15 -0500 Subject: [PATCH 11/16] Update _posts/2018-12-06.Rust-1.31.md Co-Authored-By: steveklabnik --- _posts/2018-12-06.Rust-1.31.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06.Rust-1.31.md index ff04dda0a..aeb0db39a 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06.Rust-1.31.md @@ -32,6 +32,7 @@ post, so here's a table of contents: * [Module system changes](#module-system-changes) * [More lifetime elision rules](#more-lifetime-elision-rules) * [`const fn`](#const-fn) +* [New tools](#new-tools) * [Tool Lints](#tool-lints) * [Library stabilizations](#library-stabilizations) * [Cargo features](#cargo-features) From e76a634f150fb2b44566329c97d2ae9bcd759d0a Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 6 Dec 2018 09:23:29 -0500 Subject: [PATCH 12/16] edit blog post --- ... => 2018-12-06-Rust-1.31-and-rust-2018.md} | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) rename _posts/{2018-12-06.Rust-1.31.md => 2018-12-06-Rust-1.31-and-rust-2018.md} (88%) diff --git a/_posts/2018-12-06.Rust-1.31.md b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md similarity index 88% rename from _posts/2018-12-06.Rust-1.31.md rename to _posts/2018-12-06-Rust-1.31-and-rust-2018.md index aeb0db39a..92f17f207 100644 --- a/_posts/2018-12-06.Rust-1.31.md +++ b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md @@ -1,11 +1,12 @@ --- layout: post -title: "Announcing Rust 1.31" +title: "Announcing Rust 1.31 and Rust 2018" author: The Rust Core Team --- -The Rust team is happy to announce a new version of Rust, 1.31.0. Rust is a -systems programming language focused on safety, speed, and concurrency. +The Rust team is happy to announce a new version of Rust, 1.31.0, and "Rust +2018" as well. Rust is a programming language that empowers everyone to build +reliable and efficient software. If you have a previous version of Rust installed via rustup, getting Rust 1.31.0 is as easy as: @@ -85,7 +86,7 @@ What kind of new features, you may ask? Well, first, features get added to Rust 2015 unless they require some sort of incompatibility with 2015's features. As such, most of the language is available everywhere. You can check out [the edition -guide](https://doc.rust-lang.org/nightly/edition-guide) to check each +guide](https://doc.rust-lang.org/edition-guide) to check each feature's minimum `rustc` version as well as edition requirements. However, there are a few big-ticket features we'd like to mention here: non-lexical lifetimes, and some module system improvements. @@ -144,7 +145,7 @@ fn main() { Older Rust will give you this error: ```text -rror[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable +error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable --> src/main.rs:5:18 | 4 | let y = &x; @@ -186,9 +187,9 @@ there's a root cause for why it's so confusing to many: while there are simple and consistent rules defining the module system, their consequences can feel inconsistent, counterintuitive and mysterious. -As such, the 2018 edition of Rust introduces a few new module system -features, but they end up simplifying the module system, to make it more -clear as to what is going on. +As such, the 2018 edition of Rust introduces a few changes to how paths work, +but they end up simplifying the module system, to make it more clear as to +what is going on. Here's a brief summary: @@ -201,7 +202,7 @@ These may seem like arbitrary new rules when put this way, but the mental model is now significantly simplified overall. There's a *lot* of details here, so please read [the edition -guide](https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html) +guide](https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html) for full details. ### More lifetime elision rules @@ -214,7 +215,7 @@ Code like this: impl<'a> Reader for BufReader<'a> { // methods go here } -` +``` can now be written like this: @@ -227,8 +228,24 @@ impl Reader for BufReader<'_> { The `'_` lifetime still shows that `BufReader` takes a parameter, but we don't need to create a name for it anymore. -Lifetimes are still required to be defined in structs. We're considering -some options here in the future, but have no concrete plans yet. +Lifetimes are still required to be defined in structs. However, we no longer +require as much boilerplate as before: + +```rust +// Rust 2015 +struct Ref<'a, T: 'a> { + field: &'a T +} + +// Rust 2018 +struct Ref<'a, T> { + field: &'a T +} +``` + +The `: 'a` is inferred. You can still be explicit if you prefer. We're +considering some more options for elision here in the future, but have no +concrete plans yet. ### `const fn` @@ -297,20 +314,21 @@ Work on IDE support is not finished, in particular code completion is not up to In [Rust 1.30](https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html), we stabilized "tool attributes", like `#[rustfmt::skip]`. In Rust 1.31, we're stabilizing something similar: "tool lints," like -`#[allow(clippy::something)]` These give a namespace to lints, so that it's +`#[allow(clippy::bool_comparison)]` These give a namespace to lints, so that it's more clear which tool they're coming from. If you previously used Clippy's lints, you can migrate like this: ```rust // old -#![allow(bool_comparison)] +#![cfg_attr(clippy, bool_comparison)] // new #![allow(clippy::bool_comparison)] ``` -You'll get warnings that can help you update to the new style. +You don't need `cfg_attr` anymore! You'll also get warnings that can help you +update to the new style. ### Library stabilizations @@ -330,9 +348,10 @@ See the [detailed release notes][notes] for more. ### Cargo features -Cargo will now download packages in parallel using HTTP/2. Additionally, -now that `extern crate` is gone, you can't `extern crate foo as bar;` anymore -to rename a crate. As such, you can do so in your `Cargo.toml`, like this: +Cargo will now download packages in parallel using HTTP/2. Additionally, now +that `extern crate` is not usually required, it would be jarring to do +`extern crate foo as bar;` to rename a crate. As such, you can do so in your +`Cargo.toml`, like this: ```toml [dependencies] @@ -347,7 +366,7 @@ version = "0.1" package = "foo" ``` -Now, the `baz` package will be able to be used via `foo` in your code. +Now, the `foo` package will be able to be used via `baz` in your code. See the [detailed release notes][notes] for more. From 1539291752c12073bbc1da7babafa3b5da7aeb14 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 6 Dec 2018 10:18:51 -0500 Subject: [PATCH 13/16] domain working groups --- _posts/2018-12-06-Rust-1.31-and-rust-2018.md | 117 ++++++++++++++++--- 1 file changed, 101 insertions(+), 16 deletions(-) diff --git a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md index 92f17f207..1864a0374 100644 --- a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md +++ b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md @@ -35,6 +35,9 @@ post, so here's a table of contents: * [`const fn`](#const-fn) * [New tools](#new-tools) * [Tool Lints](#tool-lints) +* [Documentation](#documentation) +* [Domain working groups](#domain-working-groups) +* [New website](#new-website) * [Library stabilizations](#library-stabilizations) * [Cargo features](#cargo-features) * [Contributors](#contributors-to-1310) @@ -46,7 +49,16 @@ March](https://blog.rust-lang.org/2018/03/12/roadmap.html), [and then in July](https://blog.rust-lang.org/2018/07/27/what-is-rust-2018.html). For some more background about the *why* of Rust 2018, please go read those posts; there's a lot to cover in the release announcement, and so we're going -to focus on the *what* here. +to focus on the *what* here. Breifly, Rust 2018 is an opportunity to bring +all of the work we've been doing over the past three years together, and create +a cohesive package. This is more than just language features, it also includes + +* Tooling (IDE support, `rustfmt`, Clippy) +* Documentation +* Domain working groups work +* A new web site + +We'll be covering all of this and more in this post. Let's create a new project with Cargo: @@ -290,17 +302,39 @@ this is enough useful stuff to start shipping the feature itself. For full details, please see [the reference](https://doc.rust-lang.org/reference/items/functions.html#const-functions). -### New tools - -The 2018 edition signals a new level of maturity for Rust's tools ecosystem. Cargo, Rustdoc, and Rustup have been crucial tools since 1.0; with the 2018 edition, there is a new generation of tools ready for all users: Clippy, Rustfmt, and IDE support. - ---- Clippy (Manish) goes here --- - -[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code. Automatically formatting your code lets you save time and arguments by using the [official Rust style](https://github.com/rust-lang/rfcs/blob/master/style-guide/README.md). You can install with `rustup component add rustfmt` and use it with `cargo fmt`. -This release includes Rustfmt 1.0. From now on we guarantee backwards compatibility for Rustfmt: if you can format your code today, then the formatting will not change in the future (only with the default options). Backwards compatibility means that running Rustfmt on your CI is practical (use `cargo fmt --check`). Try that and 'format on save' in your editor to revolutionize your workflow. +### New tools -IDE support is one of the most requested tooling features for Rust. There are now multiple, high quality options: +The 2018 edition signals a new level of maturity for Rust's tools ecosystem. +Cargo, Rustdoc, and Rustup have been crucial tools since 1.0; with the 2018 +edition, there is a new generation of tools ready for all users: Clippy, +Rustfmt, and IDE support. + +Rust's linter, [`clippy`](https://github.com/rust-lang/rust-clippy/), is +now available on stable Rust. You can install it via `rustup component add +clippy` and run it with `cargo clippy`. Clippy is now considered 1.0, which +carries the same lint stability guarantees as rustc. New lints may be added, +and lints may be modified to add more functionality, however lints may never +be removed (only deprecated). This means that code that compiles under clippy +will continue to compile under clippy (provided there are no lints set to +error via `deny`), but may throw new warnings. + +[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust +code. Automatically formatting your code lets you save time and arguments by +using the [official Rust +style](https://github.com/rust-lang/rfcs/blob/master/style-guide/README.md). +You can install with `rustup component add rustfmt` and use it with `cargo +fmt`. + +This release includes Rustfmt 1.0. From now on we guarantee backwards +compatibility for Rustfmt: if you can format your code today, then the +formatting will not change in the future (only with the default options). +Backwards compatibility means that running Rustfmt on your CI is practical +(use `cargo fmt --check`). Try that and 'format on save' in your editor to +revolutionize your workflow. + +IDE support is one of the most requested tooling features for Rust. There are +now multiple, high quality options: * [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust) * [IntelliJ](https://plugins.jetbrains.com/plugin/8182-rust) @@ -308,7 +342,10 @@ IDE support is one of the most requested tooling features for Rust. There are no * [Sublime Text 3](https://github.com/rust-lang/rust-enhanced) * [Eclipse](https://www.eclipse.org/downloads/packages/release/photon/r/eclipse-ide-rust-developers-includes-incubating-components) -Work on IDE support is not finished, in particular code completion is not up to scratch in the RLS-based editors. However, if you mainly want support for types, documentation, and 'go to def', etc. then you should be happy. +Work on IDE support is not finished, in particular code completion is not up +to scratch in the RLS-based editors. However, if you mainly want support for +types, documentation, and 'go to def', etc. then you should be happy. + ### Tool lints In [Rust 1.30](https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html), we @@ -330,6 +367,53 @@ If you previously used Clippy's lints, you can migrate like this: You don't need `cfg_attr` anymore! You'll also get warnings that can help you update to the new style. +### Documentation + +Rustdoc has seen a number of improvements this year, and we also shipped a +complete re-write of the "The Rust Programming Language." Additionally, you +can [buy a dead-tree copy from No Starch Press](https://nostarch.com/rust)! + +We had previously called this the "second edition" of the book, but since +it's the first edition in print, that was confusing. We also want to +periodically update the print edition as well. In the end, after many +discussions with No Starch, we're going to be updating the book on the +website with each release, and No Starch will periodically pull in our +changes and print them. The book has been selling quite well so far, raising +money for [Black Girls Code](http://www.blackgirlscode.com/). + +You can find the new TRPL [here](https://doc.rust-lang.org/beta/book/). + +### Domain working groups + +We announced the formation of four working groups this year: + +* Network services +* Command-line applications +* WebAssembly +* Embedded devices + +Each of these groups has been working very hard on a number of things to +make Rust awesome in each of these domains. Some highlights: + +* Network services has been shaking out the Futures interface, and async/await + on top of it. This hasn't shipped yet, but we're close! +* The CLI working group has been working on libraries and documentation for making awesome + command-line applications +* The WebAssembly group has been shipping a ton of world-class tooling for using Rust with wasm. +* Embedded devices has gotten ARM development working on stable Rust! + +You can find out more about this work on the new website! + +### New Website + +[Last +week](https://blog.rust-lang.org/2018/11/29/a-new-look-for-rust-lang-org.html) +we announced a new iteration of the web site. It's now been promoted to +rust-lang.org itself! + +There's still a ton of work to do, but we're proud of the year of work that it +took by many people to get it shipped. + ### Library stabilizations A bunch of `From` implementations have been added: @@ -348,10 +432,11 @@ See the [detailed release notes][notes] for more. ### Cargo features -Cargo will now download packages in parallel using HTTP/2. Additionally, now -that `extern crate` is not usually required, it would be jarring to do -`extern crate foo as bar;` to rename a crate. As such, you can do so in your -`Cargo.toml`, like this: +Cargo will now download packages in parallel using HTTP/2. + +Additionally, now that `extern crate` is not usually required, it would be +jarring to do `extern crate foo as bar;` to rename a crate. As such, you can +do so in your `Cargo.toml`, like this: ```toml [dependencies] @@ -373,4 +458,4 @@ See the [detailed release notes][notes] for more. ## Contributors to 1.31.0 Many people came together to create Rust 1.31. We couldn't have done it -without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) \ No newline at end of file From e790467145c02e022fd29b073f58eea0cbb10d09 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 6 Dec 2018 10:23:36 -0500 Subject: [PATCH 14/16] better thanks --- _posts/2018-12-06-Rust-1.31-and-rust-2018.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md index 1864a0374..e5c7ace1e 100644 --- a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md +++ b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md @@ -457,5 +457,10 @@ See the [detailed release notes][notes] for more. ## Contributors to 1.31.0 -Many people came together to create Rust 1.31. We couldn't have done it -without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.31.0) \ No newline at end of file +At the end of release posts, we normally thank [the people who contributed to +this release](https://thanks.rust-lang.org/rust/1.31.0). But for this +release, more so than others, this list does not truly capture the amount of +work and the number of people who have contributed. Each release is only six +weeks, but this release is the culmination of three years of effort, in +countless repositories, by numerous people. It's been a pleasure to work with +you all, and we look forward to continuing to grow in the next three years. \ No newline at end of file From df9d15634235a8728e8a147ad74a0cd6203f7b36 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 6 Dec 2018 10:26:02 -0500 Subject: [PATCH 15/16] dont mention idiom lints --- _posts/2018-12-06-Rust-1.31-and-rust-2018.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md index e5c7ace1e..4d2f5c670 100644 --- a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md +++ b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md @@ -82,9 +82,8 @@ A new key has been added under `[package]`: `edition`. Note that it has been set to `2018`. You can also set it to `2015`, which is the default if the key does not exist. -By using Rust 2018, some new features are unlocked that are not allowed in Rust 2015. -And eventually, we'll be turning on some new warnings that help you use these -new features more effectively, as well. +By using Rust 2018, some new features are unlocked that are not allowed in +Rust 2015. It is important to note that each package can be in either 2015 or 2018 mode, and they work seamlessly together. Your 2018 project can use 2015 From 397e1c27eed2c246e08bf8fafac3a37cb3b3eb75 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 6 Dec 2018 10:27:56 -0500 Subject: [PATCH 16/16] link to mozilla hacks --- _posts/2018-12-06-Rust-1.31-and-rust-2018.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md index 4d2f5c670..0271465b0 100644 --- a/_posts/2018-12-06-Rust-1.31-and-rust-2018.md +++ b/_posts/2018-12-06-Rust-1.31-and-rust-2018.md @@ -49,7 +49,11 @@ March](https://blog.rust-lang.org/2018/03/12/roadmap.html), [and then in July](https://blog.rust-lang.org/2018/07/27/what-is-rust-2018.html). For some more background about the *why* of Rust 2018, please go read those posts; there's a lot to cover in the release announcement, and so we're going -to focus on the *what* here. Breifly, Rust 2018 is an opportunity to bring +to focus on the *what* here. There's also a [post on Mozilla +Hacks](https://hacks.mozilla.org/2018/12/rust-2018-is-here-but-what-is-it/) +as well! + +Breifly, Rust 2018 is an opportunity to bring all of the work we've been doing over the past three years together, and create a cohesive package. This is more than just language features, it also includes