Series: The Rust Annals
Vol. I Issue 17 nlopes.dev
Announcing Rust 1.16
Rust 1.16’s largest addition is cargo check, which shortens many edit-and-compile cycles by performing the compiler’s checks without producing a final binary. The release also removes a misleading lifetime suggestion, expands typo suggestions, adds 21 standard-library APIs, improves string-slicing diagnostics, and brings workspace-wide commands and crate categories to Cargo and crates.io.
cargo check provides faster compiler feedback without producing binaries
cargo check runs the compiler’s safety, syntax, and other checks but skips the later step that produces binary code. It targets the common workflow in which developers repeatedly run cargo build only to find compilation errors, without executing the resulting program.
The measured improvement depended on the project. In the release post’s informal benchmarks, an initial check versus build was 2.648 times faster for thanks, 1.594 times faster for cargo, and 1.192 times faster for diesel. After adding one blank line to src\lib.rs, the respective speedups were 5.506, 6.925, and 1.100. Initial runs also checked every dependency, so larger projects with many dependencies saw a large improvement while smaller projects saw more modest gains.
Supporting this command, rustc can now emit .rmeta files containing only crate metadata. cargo check uses that metadata from dependencies for type checking and related analysis; it is also useful to the Rust Language Server and possibly other future tools.
Diagnostics avoid misleading lifetime advice and find more misspellings
Rust removed the long-standing consider using an explicit lifetime parameter help message. For the following impossible implementation, Rust 1.15.1 suggested tying s to 'a, although that made the method incompatible with FromStr; after another edit, it could suggest code already present.
use std::str::FromStr;
pub struct Name<'a> {
name: &'a str,
}
impl<'a> FromStr for Name<'a> {
type Err = ();
fn from_str(s: &str) -> Result<Name, ()> {
Ok(Name { name: s })
}
}error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in generic type due to conflicting requirements
--> .\foo.rs:10:5
|
10 | fn from_str(s: &str) -> Result<Name, ()> {
| _____^ starting here...
11 | | Ok(Name { name: s })
12 | | }
| |_____^ ...ending here
|
help: consider using an explicit lifetime parameter as shown: fn from_str(s: &'a str) -> Result<Name, ()>The diagnostic could even suggest invalid Rust syntax. Because experienced users generally did not need it and newcomers could be led down an unhelpful path, the help message has been removed for now. It may return if its false positives can be limited. The implementation above cannot work as written: Name would need a String, not &str.
Suggestions for misspelled names, previously available only in some local-variable and struct-field cases, now appear nearly everywhere. For example:
let foo = 5;
println!("{}", ffo);error[E0425]: cannot find value `ffo` in this scope
--> foo.rs:4:20
|
4 | println!("{}", ffo);
| ^^^ did you mean `foo`?
The standard library gains 21 APIs and clearer behavior
The newly stable APIs are:
VecDeque::truncateVecDeque::resizeString::insert_strDuration::checked_addDuration::checked_subDuration::checked_divDuration::checked_mulstr::replacenstr::repeatSocketAddr::is_ipv4SocketAddr::is_ipv6IpAddr::is_ipv4IpAddr::is_ipv6Vec::dedup_byVec::dedup_by_keyResult::unwrap_or_default<*const T>::wrapping_offset<*mut T>::wrapping_offsetCommandExt::creation_flagsFile::set_permissionsString::split_off
The single-argument form of writeln! is now available, matching println! and writing only a newline. All standard-library structs now implement Debug.
Invalid &str slicing now identifies the character containing the requested byte boundary. For this input:
&"abcαβγ"[..4]the text after the semicolon is new:
thread 'str::test_slice_fail_boundary_1' panicked at 'byte index 4 is not
a char boundary; it is inside 'α' (bytes 3..5) of `abcαβγ`'
Cargo expands workspace commands and crate discovery metadata
cargo build and cargo doc now accept --all, allowing every crate in a workspace to be built or documented with one command. Cargo also supports --version --verbose, mirroring rustc.
Crates.io can display Travis CI or AppVeyor badges on crate pages. Cargo and crates.io also understand categories. Categories are curated and intended for browsing, unlike free-form keywords, which are intended for searching.