|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.9" |
| 4 | +author: The Rust Core Team |
| 5 | +--- |
| 6 | + |
| 7 | +The Rust team is happy to announce the latest version of Rust, 1.9. Rust is a |
| 8 | +systems programming language focused on safety, speed, and concurrency. |
| 9 | + |
| 10 | +As always, you can [install Rust 1.9][install] from the appropriate page on our |
| 11 | +website, and check out the [detailed release notes for 1.9][notes] on GitHub. |
| 12 | +About 1400 patches were landed in this release. |
| 13 | + |
| 14 | +[install]: https://www.rust-lang.org/install.html |
| 15 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-190-2016-05-26 |
| 16 | + |
| 17 | +### What's in 1.9 stable |
| 18 | + |
| 19 | +Rust 1.9 contains some exciting new things! |
| 20 | + |
| 21 | +First up, a new attribute for library authors: `#[deprecated]`. Authors of |
| 22 | +libraries can now tag items with this attribute, and users of their crate |
| 23 | +will see a warning when it is used. This new feature was defined in [RFC 1270]. |
| 24 | + |
| 25 | +[RFC 1270]: https://github.com/rust-lang/rfcs/blob/master/text/1270-deprecation.md |
| 26 | + |
| 27 | +We now publishes std binaries for the `mips-unknown-linux-musl`, |
| 28 | +`mipsel-unknown-linux-musl`, and `i586-pc-windows-msvc` targets. |
| 29 | + |
| 30 | +[The time complexity of comparing variables for equivalence][compare] during |
| 31 | +type unification is reduced from O(n!) to O(n). What does this mean? Certain |
| 32 | +kinds of code compiles much, much faster. |
| 33 | + |
| 34 | +[compare]: https://github.com/rust-lang/rust/pull/32062 |
| 35 | + |
| 36 | +Strings are a very common type, and implement a lot of different traits. |
| 37 | +Specifically, when converting between `&str` and `String`, you have many |
| 38 | +options. Rustaceans used these two the most: |
| 39 | + |
| 40 | +```rust |
| 41 | +let s = "some string".to_string(); |
| 42 | +let s = "some string".to_owned(); |
| 43 | +``` |
| 44 | + |
| 45 | +The former is the official convention, but it was discovered that it's not |
| 46 | +as fast as the second method. For a long time, it was not possible to improve |
| 47 | +this situation, however, a new language feature has landed on nightly and made |
| 48 | +this possible. [`libstd` now uses this internally][str] to make the two equivalent. |
| 49 | + |
| 50 | +[str]: https://github.com/rust-lang/rust/pull/32586 |
| 51 | + |
| 52 | +Finally, this feature is technically a library change, but it's worth |
| 53 | +mentioning here as well. The `std::panic` module is being stabilized. This |
| 54 | +allows panics to be caught: |
| 55 | + |
| 56 | +```rust |
| 57 | +use std::panic; |
| 58 | + |
| 59 | +let result = panic::catch_unwind(|| { |
| 60 | + println!("hello!"); |
| 61 | +}); |
| 62 | +assert!(result.is_ok()); |
| 63 | + |
| 64 | +let result = panic::catch_unwind(|| { |
| 65 | + panic!("oh no!"); |
| 66 | +}); |
| 67 | +assert!(result.is_err()); |
| 68 | +``` |
| 69 | + |
| 70 | +This behavior was defined in [RFC 1236]. |
| 71 | + |
| 72 | +[`std::panic`]: http://doc.rust-lang.org/stable/std/panic/index.html |
| 73 | +[RFC 1236]: https://github.com/rust-lang/rfcs/pull/1236 |
| 74 | + |
| 75 | +Historically, this has not been possible in Rust: panics are always |
| 76 | +unrecoverable. And in practice, this is still how they should be used. While |
| 77 | +the current implementation of `panic!` does unwinding, in a future release, |
| 78 | +crates will be able to choose a different implementation, namely, that |
| 79 | +`panic!` causes an abort, rather than unwind. Given that panics are for |
| 80 | +non-recoverable errors only, this is a valid implementation. |
| 81 | + |
| 82 | +If panics are for non-recoverable errors, why provide an interface for |
| 83 | +recovering from them? There are two big use-cases here: |
| 84 | + |
| 85 | +* Embedding Rust in other languages |
| 86 | +* Abstractions that manage threads |
| 87 | + |
| 88 | +For the first case, unwinding across a language boundary is undefined behavior, |
| 89 | +and often leads to segfaults in practice. This means that when embedding Rust |
| 90 | +inside of other languages, you must avoid any code that can possibly panic, or |
| 91 | +rely on the (still unstable and only recently landed) 'abort' implementation of |
| 92 | +panic. Allowing panics to be caught at the language boundary provides more |
| 93 | +options in this case: an issue in Rust can return an error, rather than aborting |
| 94 | +the entire process. This is very important for many use-cases of embedding Rust; |
| 95 | +aborting is not always an acceptable option. |
| 96 | + |
| 97 | +In the second, consider a threadpool library. If a thread panics, it's |
| 98 | +reasonable for the pool to not want to abort, but instead report the error, |
| 99 | +and, depending on the details, possibly even restart the thread, in an |
| 100 | +Erlang-style model. Recovering from these kinds of errors is very useful. |
| 101 | + |
| 102 | +This change had a lot of discussion and thought put into it, by a large group |
| 103 | +of people. A significant worry about this change is that people may use it to |
| 104 | +try and emulate exceptions, which is not the intention of this functionality. |
| 105 | +However, the use-cases for this feature are legitimate, and there are two |
| 106 | +reasons we believe that this will not happen, generally: |
| 107 | + |
| 108 | +* Rust already has a very strong culture of using `Result<T, E>` and `panic!` |
| 109 | + appropriately, and a new function will not change this culture overnight. |
| 110 | +* A significant part of Rust's userbase desires the abort implementation of |
| 111 | + panic, and libraries will need to work with both implementations. |
| 112 | + |
| 113 | +See the [detailed release notes][notes] for more. |
| 114 | + |
| 115 | +#### Library stabilizations |
| 116 | + |
| 117 | +About 80 library functions and methods are now stable in 1.8. Lots of stuff! |
| 118 | +The most major is the `std::panic` module, described in the previous section, |
| 119 | +but there's a lot more too: |
| 120 | + |
| 121 | +* Raw pointers gained `as_ref()` and `as_mut()`, which returns an `Option<&T>`. |
| 122 | +* `char` gained the ability to decode into UTF-16. |
| 123 | +* `BTreeSet` and `HashSet` gained the `take()`, `replace()`, and `get()` methods. |
| 124 | +* `OsString` gained some methods to bring it up to parity with `String`. |
| 125 | +* `SocketAddr` and its variants gained `set_ip()` and `set_port()`. |
| 126 | +* Slices gained `copy_from_slice()`, a way to efficiently copy a slice. |
| 127 | +* `ptr::{read,write}_volitile()` allow for volitile reading and writing from a |
| 128 | + raw pointer. |
| 129 | +* `TcpStream`, `TcpListener`, and `UdpSocket` gained a number of methods that |
| 130 | + let you set various aspects of the connection. |
| 131 | + |
| 132 | +Finally, many of the types in `libcore` did not contain a `Debug` |
| 133 | +implementation. [This was fixed](https://github.com/rust-lang/rust/pull/32054). |
| 134 | + |
| 135 | +See the [detailed release notes][notes] for more. |
| 136 | + |
| 137 | +#### Cargo features |
| 138 | + |
| 139 | +There were two major changes to Cargo: |
| 140 | + |
| 141 | +First, Cargo has historically not been able to be run concurrently. [This has |
| 142 | +been fixed](https://github.com/rust-lang/cargo/pull/2486). |
| 143 | + |
| 144 | +Second, a new flag, `RUSTFLAGS`, [was |
| 145 | +added](https://github.com/rust-lang/cargo/pull/2241). This allows you to |
| 146 | +specify arbitrary flags to be passed to `rustc` through an environment |
| 147 | +variable, which is useful for packagers, for example. |
| 148 | + |
| 149 | +See the [detailed release notes][notes] for more. |
| 150 | + |
| 151 | +### Contributors to 1.9 |
| 152 | + |
| 153 | +We had XXX individuals contribute to 1.9. Thank you so much! |
| 154 | + |
| 155 | +* YOUR NAME HERE |
0 commit comments