|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.43.0" |
| 4 | +author: The Rust Release Team |
| 5 | +release: true |
| 6 | +--- |
| 7 | + |
| 8 | +The Rust team is happy to announce a new version of Rust, 1.43.0. Rust is a |
| 9 | +programming language that is empowering everyone to build reliable and |
| 10 | +efficient software. |
| 11 | + |
| 12 | +If you have a previous version of Rust installed via rustup, getting Rust |
| 13 | +1.43.0 is as easy as: |
| 14 | + |
| 15 | +```console |
| 16 | +rustup update stable |
| 17 | +``` |
| 18 | + |
| 19 | +If you don't have it already, you can [get `rustup`][install] from the |
| 20 | +appropriate page on our website, and check out the [detailed release notes for |
| 21 | +1.43.0][notes] on GitHub. |
| 22 | + |
| 23 | +[install]: https://www.rust-lang.org/install.html |
| 24 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1430-2020-04-23 |
| 25 | + |
| 26 | +## What's in 1.43.0 stable |
| 27 | + |
| 28 | +This release is fairly minor. There are no new major features. We have some |
| 29 | +new stabilized APIs, some compiler performance improvements, and a small |
| 30 | +macro-related feature. See the [detailed release notes][notes] to learn about |
| 31 | +other changes not covered by this post. |
| 32 | + |
| 33 | +### `item` fragments |
| 34 | + |
| 35 | +In macros, you can use `item` fragments to interpolate items into the body of traits, |
| 36 | +impls, and extern blocks. For example: |
| 37 | + |
| 38 | +```rust |
| 39 | +macro_rules! mac_trait { |
| 40 | + ($i:item) => { |
| 41 | + trait T { $i } |
| 42 | + } |
| 43 | +} |
| 44 | +mac_trait! { |
| 45 | + fn foo() {} |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +This will generate: |
| 50 | + |
| 51 | +```rust |
| 52 | +trait T { |
| 53 | + fn foo() {} |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### Type inference around primitives |
| 58 | + |
| 59 | +The type inference around primitives, references, and binary operations was |
| 60 | +improved. A code sample makes this easier to understand: this code fails to |
| 61 | +compile on Rust 1.42, but compiles in Rust 1.43. |
| 62 | + |
| 63 | +```rust |
| 64 | +let n: f32 = 0.0 + &0.0; |
| 65 | +``` |
| 66 | + |
| 67 | +In Rust 1.42, you would get an error that would say "hey, I don't know how to add |
| 68 | +an `f64` and an `&f64` with a result of `f32`." The algorithm now correctly decides |
| 69 | +that both `0.0` and `&0.0` should be `f32`s instead. |
| 70 | + |
| 71 | +### New Cargo environment variable for tests |
| 72 | + |
| 73 | +In a move to help integration testing, [Cargo will set some new environment |
| 74 | +variables](https://github.com/rust-lang/cargo/pull/7697). |
| 75 | + |
| 76 | +This is easiest to explain by example: let's say we're working on a command |
| 77 | +line project, simply named "cli". If we're writing an integration test, we want |
| 78 | +to invoke that `cli` binary and see what it does. When running tests and |
| 79 | +benchmarks, Cargo will set an environment variable named `CARGO_BIN_EXE_cli`, |
| 80 | +and I can use it inside my test: |
| 81 | + |
| 82 | +```rust |
| 83 | +let exe = env!("CARGO_BIN_EXE_cli"); |
| 84 | +``` |
| 85 | + |
| 86 | +This makes it easier to invoke `cli`, as we now have a path to it directly. |
| 87 | + |
| 88 | +### Library changes |
| 89 | + |
| 90 | +[You can now use associated constants on floats and integers directly][consts], rather |
| 91 | +than having to import the module. That is, you can now write `u32::MAX` or `f32::NAN` |
| 92 | +with no `use std::u32;` or `use std::f32;`. |
| 93 | + |
| 94 | +[consts]: https://github.com/rust-lang/rust/pull/68952/ |
| 95 | + |
| 96 | +There is a [new `primitive` |
| 97 | +module](https://github.com/rust-lang/rust/pull/67637/) that re-exports Rust's |
| 98 | +primitive types. This can be useful when you're writing a macro and want to make |
| 99 | +sure that the types aren't shadowed. |
| 100 | + |
| 101 | +Additionally, we stabilized six new APIs: |
| 102 | + |
| 103 | +- [`Once::is_completed`] |
| 104 | +- [`f32::LOG10_2`] |
| 105 | +- [`f32::LOG2_10`] |
| 106 | +- [`f64::LOG10_2`] |
| 107 | +- [`f64::LOG2_10`] |
| 108 | +- [`iter::once_with`] |
| 109 | + |
| 110 | +[`Once::is_completed`]: https://doc.rust-lang.org/std/sync/struct.Once.html#method.is_completed |
| 111 | +[`f32::LOG10_2`]: https://doc.rust-lang.org/std/f32/consts/constant.LOG10_2.html |
| 112 | +[`f32::LOG2_10`]: https://doc.rust-lang.org/std/f32/consts/constant.LOG2_10.html |
| 113 | +[`f64::LOG10_2`]: https://doc.rust-lang.org/std/f64/consts/constant.LOG10_2.html |
| 114 | +[`f64::LOG2_10`]: https://doc.rust-lang.org/std/f64/consts/constant.LOG2_10.html |
| 115 | +[`iter::once_with`]: https://doc.rust-lang.org/std/iter/fn.once_with.html |
| 116 | + |
| 117 | +### Other changes |
| 118 | + |
| 119 | +[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-143-2020-04-23 |
| 120 | +[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-143 |
| 121 | + |
| 122 | +There are other changes in the Rust 1.43.0 release: check out what changed in |
| 123 | +[Rust][notes], [Cargo][relnotes-cargo], and [Clippy][relnotes-clippy]. |
| 124 | + |
| 125 | +## Contributors to 1.43.0 |
| 126 | + |
| 127 | +Many people came together to create Rust 1.43.0. We couldn't have done it |
| 128 | +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.43.0/) |
0 commit comments