Series: The Rust Annals

Vol. I Issue 54 nlopes.dev

Announcing Rust 1.53.0

Stabilization of or-patterns and IntoIterator for arrays significantly improves language ergonomics and expressiveness, marking a notable minor release.

IntoIterator for arrays

This is the first Rust release in which arrays implement the IntoIterator trait. This means you can now iterate over arrays by value:

for i in [1, 2, 3] {
    ..
}

Previously, this was only possible by reference, using &[1, 2, 3] or [1, 2, 3].iter().

Similarly, you can now pass arrays to methods expecting a T: IntoIterator:

let set = BTreeSet::from_iter([1, 2, 3]);
for (a, b) in some_iterator.chain([1]).zip([1, 2, 3]) {
    ..
}

This was not implemented before, due to backwards compatibility problems. Because IntoIterator was already implemented for references to arrays, array.into_iter() already compiled in earlier versions, resolving to (&array).into_iter().

As of this release, arrays implement IntoIterator with a small workaround to avoid breaking code. The compiler will continue to resolve array.into_iter() to (&array).into_iter(), as if the trait implementation does not exist. This only applies to the .into_iter() method call syntax, and does not affect any other syntax such as for e in [1, 2, 3], iter.zip([1, 2, 3]) or IntoIterator::into_iter([1, 2, 3]), which all compile fine.

Since this special case for .into_iter() is only required to avoid breaking existing code, it is removed in the new edition, Rust 2021, which will be released later this year. See the edition announcement for more information.

Or patterns

Pattern syntax has been extended to support | nested anywhere in the pattern. This enables you to write Some(1 | 2) instead of Some(1) | Some(2).

match result {
     Ok(Some(1 | 2)) => { .. }
     Err(MyError { kind: FileNotFound | PermissionDenied, .. }) => { .. }
     _ => { .. }
}

Unicode identifiers

Identifiers can now contain non-ascii characters. All valid identifier characters in Unicode as defined in UAX #31 can now be used. That includes characters from many different scripts and languages, but does not include emoji.

For example:

const BLÅHAJ: &str = "🦈";

struct 人 {
    名字: String,
}

let α = 1;

The compiler will warn about potentially confusing situations involving different scripts. For example, using identifiers that look very similar will result in a warning.

warning: identifier pair considered confusable between `s` and `s`

HEAD branch name support in Cargo

Cargo no longer assumes the default HEAD of git repositories is named master. This means you no longer need to specify branch = "main" for git dependencies from a repository where the default branch is called main.

Incremental Compilation remains off by default

As previously discussed on the blog post for version 1.52.1, incremental compilation has been turned off by default on the stable Rust release channel. The feature remains available on the beta and nightly release channels. For the 1.53.0 stable release, the method for reenabling incremental is unchanged from 1.52.1.

2021 contributors to this release.

Reproduced from the Rust blog under its publication licence. Typeset in Literata.