As usual, a thread to highlight some of the new features:
1/11
1. panic!() and assert!() can now be used in const fns.
Any formatting other than panic!("..") and panic!("{}", some_str) is not accepted though, because formatting is not const (yet!).
2/11
2. Many functions in the standard library have been marked as #[must_use], to warn you when just calling the function without using its result is most likely a mistake.
Vec, String, VecDeque, HashMap and HashSet now have a .try_reserve() method. This method is similar to .reserve(), except it doesn't panic/abort when it was unable to allocate memory.
7/11
7. Vec::leak no longer reallocates.
Vec::leak used to shrink the capacity before leaking the data, which might involve a reallocation. The behaviour is now changed to always leak the current allocation, without shrinking/reallocating first.
8/11
8. std::hint::unreachable_unchecked is now const.
In *const* context, it'll result in a compiler error when reached, not in undefined behaviour like it would at runtime.
2. Closures in Rust 2021 will capture only the fields of an object you use, instead of the entire object. This should result in fewer fights with the borrow checker:
We already had str::split and str::splitn, which result in an iterator. But when parsing something simple, you often want to split something exactly once. For example, to parse a string containing `key=value`.
2/10
Another one I'm excited about is one of the first features I worked on: std::fmt::Arguments::as_str()
fmt::Arguments is returned by format_args!(), and appears in macros that support formatting.
as_str() allows handling the literal case without special-casing your macro:
I just approved the PR for a very exciting addition to @rustlang 1.53: IntoIterator for arrays 🎉🦀
Before this change, only references to arrays implemented IntoIterator, which meant you could iterate over &[1,2,3] and &mut [1,2,3], but not over [1,2,3] directly.
1/6
The reason we didn't add it sooner was backwards compatibility. `array.into_iter()` already compiles today, because of the way methods get resolved in Rust. This implicitly calls `(&array).into_iter()`. Adding the trait implementation would change the meaning and break code.
2/6
Technically we consider this type of breakage (adding a trait impl) 'minor' and acceptable. But there was too much code that would be broken by it. Thanks to @LukasKalbertodt, such code results in a warning nowadays, but there's a lot of code that just doesn't get updated.