Releases: rust-lang/rust
Rust 1.45.0
Language
- Out of range float to int conversions using
as
has been defined as a saturating conversion. This was previously undefined behaviour, but you can use the{f64, f32}::to_int_unchecked
methods to continue using the current behaviour, which may be desirable in rare performance sensitive situations. mem::Discriminant<T>
now usesT
's discriminant type instead of always usingu64
.- Function like procedural macros can now be used in expression, pattern, and statement positions. This means you can now use a function-like procedural macro anywhere you can use a declarative (
macro_rules!
) macro.
Compiler
- You can now override individual target features through the
target-feature
flag. E.g.-C target-feature=+avx2 -C target-feature=+fma
is now equivalent to-C target-feature=+avx2,+fma
. - Added the
force-unwind-tables
flag. This option allows rustc to always generate unwind tables regardless of panic strategy. - Added the
embed-bitcode
flag. This codegen flag allows rustc to include LLVM bitcode into generatedrlib
s (this is on by default). - Added the
tiny
value to thecode-model
codegen flag. - Added tier 3 support* for the
mipsel-sony-psp
target. - Added tier 3 support for the
thumbv7a-uwp-windows-msvc
target. - Upgraded to LLVM 10.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
net::{SocketAddr, SocketAddrV4, SocketAddrV6}
now implementsPartialOrd
andOrd
.proc_macro::TokenStream
now implementsDefault
.- You can now use
char
withops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo}
to iterate over a range of codepoints. E.g. you can now write the following;for ch in 'a'..='z' { print!("{}", ch); } println!(); // Prints "abcdefghijklmnopqrstuvwxyz"
OsString
now implementsFromStr
.- The
saturating_neg
method has been added to all signed integer primitive types, and thesaturating_abs
method has been added for all integer primitive types. Arc<T>
,Rc<T>
now implementFrom<Cow<'_, T>>
, andBox
now implementsFrom<Cow>
whenT
is[T: Copy]
,str
,CStr
,OsStr
, orPath
.Box<[T]>
now implementsFrom<[T; N]>
.BitOr
andBitOrAssign
are implemented for allNonZero
integer types.- The
fetch_min
, andfetch_max
methods have been added to all atomic integer types. - The
fetch_update
method has been added to all atomic integer types.
Stabilized APIs
Arc::as_ptr
BTreeMap::remove_entry
Rc::as_ptr
rc::Weak::as_ptr
rc::Weak::from_raw
rc::Weak::into_raw
str::strip_prefix
str::strip_suffix
sync::Weak::as_ptr
sync::Weak::from_raw
sync::Weak::into_raw
char::UNICODE_VERSION
Span::resolved_at
Span::located_at
Span::mixed_site
unix::process::CommandExt::arg0
Cargo
Misc
- Rustdoc now supports strikethrough text in Markdown. E.g.
~~outdated information~~
becomes "outdated information". - Added an emoji to Rustdoc's deprecated API message.
Compatibility Notes
- Trying to self initialize a static value (that is creating a value using itself) is unsound and now causes a compile error.
{f32, f64}::powi
now returns a slightly different value on Windows. This is due to changes in LLVM's intrinsics which{f32, f64}::powi
uses.- Rustdoc's CLI's extra error exit codes have been removed. These were previously undocumented and not intended for public use. Rustdoc still provides a non-zero exit code on errors.
- Rustc's
lto
flag is incompatible with the newembed-bitcode=no
. This may cause issues if LTO is enabled throughRUSTFLAGS
orcargo rustc
flags while cargo is addingembed-bitcode
itself. The recommended way to control LTO is with Cargo profiles, either inCargo.toml
or.cargo/config
, or by settingCARGO_PROFILE_<name>_LTO
in the environment.
Internals Only
Rust 1.44.1
Rust 1.44.0
Language
Syntax-only changes
#[cfg(FALSE)]
mod foo {
mod bar {
mod baz; // `foo/bar/baz.rs` doesn't exist, but no error!
}
}
These are still rejected semantically, so you will likely receive an error but these changes can be seen and parsed by macros and conditional compilation.
Compiler
- Rustc now respects the
-C codegen-units
flag in incremental mode. Additionally when in incremental mode rustc defaults to 256 codegen units. - Refactored
catch_unwind
to have zero-cost, unless unwinding is enabled and a panic is thrown. - Added tier 3* support for the
aarch64-unknown-none
andaarch64-unknown-none-softfloat
targets. - Added tier 3 support for
arm64-apple-tvos
andx86_64-apple-tvos
targets.
Libraries
- Special cased
vec![]
to map directly toVec::new()
. This allowsvec![]
to be able to be used inconst
contexts. convert::Infallible
now implementsHash
.OsString
now implementsDerefMut
andIndexMut
returning a&mut OsStr
.- Unicode 13 is now supported.
String
now implementsFrom<&mut str>
.IoSlice
now implementsCopy
.Vec<T>
now implementsFrom<[T; N]>
. WhereN
is at most 32.proc_macro::LexError
now implementsfmt::Display
andError
.from_le_bytes
,to_le_bytes
,from_be_bytes
,to_be_bytes
,from_ne_bytes
, andto_ne_bytes
methods are nowconst
for all integer types.
Stabilized APIs
PathBuf::with_capacity
PathBuf::capacity
PathBuf::clear
PathBuf::reserve
PathBuf::reserve_exact
PathBuf::shrink_to_fit
f32::to_int_unchecked
f64::to_int_unchecked
Layout::align_to
Layout::pad_to_align
Layout::array
Layout::extend
Cargo
- Added the
cargo tree
command which will print a tree graph of your dependencies. E.g.You can also display dependencies on multiple versions of the same crate withmdbook v0.3.2 (/Users/src/rust/mdbook) ├── ammonia v3.0.0 │ ├── html5ever v0.24.0 │ │ ├── log v0.4.8 │ │ │ └── cfg-if v0.1.9 │ │ ├── mac v0.1.1 │ │ └── markup5ever v0.9.0 │ │ ├── log v0.4.8 (*) │ │ ├── phf v0.7.24 │ │ │ └── phf_shared v0.7.24 │ │ │ ├── siphasher v0.2.3 │ │ │ └── unicase v1.4.2 │ │ │ [build-dependencies] │ │ │ └── version_check v0.1.5 ...
cargo tree -d
(short forcargo tree --duplicates
).
Misc
Compatibility Notes
- Rustc now correctly generates static libraries on Windows GNU targets with the
.a
extension, rather than the previous.lib
. - Removed the
-C no_integrated_as
flag from rustc. - The
file_name
property in JSON output of macro errors now points the actual source file rather than the previous format of<NAME macros>
. Note: this may not point to a file that actually exists on the user's system. - The minimum required external LLVM version has been bumped to LLVM 8.
mem::{zeroed, uninitialised}
will now panic when used with types that do not allow zero initialization such asNonZeroU8
. This was previously a warning.- In 1.45.0 (the next release) converting a
f64
tou32
using theas
operator has been defined as a saturating operation. This was previously undefined behaviour, but you can use the{f64, f32}::to_int_unchecked
methods to continue using the current behaviour, which may be desirable in rare performance sensitive situations.
Internal Only
These changes provide no direct user facing benefits, but represent significant improvements to the internals and overall performance of rustc and related tools.
Rust 1.43.1
Rust 1.43.0
Language
- Fixed using binary operations with
&{number}
(e.g.&1.0
) not having the type inferred correctly. - Attributes such as
#[cfg()]
can now be used onif
expressions.
Syntax only changes
- Allow
type Foo: Ord
syntactically. - Fuse associated and extern items up to defaultness.
- Syntactically allow
self
in allfn
contexts. - Merge
fn
syntax + cleanup item parsing. item
macro fragments can be interpolated intotrait
s,impl
s, andextern
blocks. For example, you may now write:macro_rules! mac_trait { ($i:item) => { trait T { $i } } } mac_trait! { fn foo() {} }
These are still rejected semantically, so you will likely receive an error but these changes can be seen and parsed by macros and conditional compilation.
Compiler
- You can now pass multiple lint flags to rustc to override the previous flags. For example;
rustc -D unused -A unused-variables
denies everything in theunused
lint group exceptunused-variables
which is explicitly allowed. However, passingrustc -A unused-variables -D unused
denies everything in theunused
lint group includingunused-variables
since the allow flag is specified before the deny flag (and therefore overridden). - rustc will now prefer your system MinGW libraries over its bundled libraries if they are available on
windows-gnu
. - rustc now buffers errors/warnings printed in JSON.
Libraries
Arc<[T; N]>
,Box<[T; N]>
, andRc<[T; N]>
, now implementTryFrom<Arc<[T]>>
,TryFrom<Box<[T]>>
, andTryFrom<Rc<[T]>>
respectively. Note These conversions are only available whenN
is0..=32
.- You can now use associated constants on floats and integers directly, rather than having to import the module. e.g. You can now write
u32::MAX
orf32::NAN
with no imports. u8::is_ascii
is nowconst
.String
now implementsAsMut<str>
.- Added the
primitive
module tostd
andcore
. This module reexports Rust's primitive types. This is mainly useful in macros where you want avoid these types being shadowed. - Relaxed some of the trait bounds on
HashMap
andHashSet
. string::FromUtf8Error
now implementsClone + Eq
.
Stabilized APIs
Cargo
- You can now set config
[profile]
s in your.cargo/config
, or through your environment. - Cargo will now set
CARGO_BIN_EXE_<name>
pointing to a binary's executable path when running integration tests or benchmarks.<name>
is the name of your binary as-is e.g. If you wanted the executable path for a binary namedmy-program
you would useenv!("CARGO_BIN_EXE_my-program")
.
Misc
- Certain checks in the
const_err
lint were deemed unrelated to const evaluation, and have been moved to theunconditional_panic
andarithmetic_overflow
lints.
Compatibility Notes
- Having trailing syntax in the
assert!
macro is now a hard error. This has been a warning since 1.36.0. - Fixed
Self
not having the correctly inferred type. This incorrectly led to some instances being accepted, and now correctly emits a hard error.
Internal Only
These changes provide no direct user facing benefits, but represent significant improvements to the internals and overall performance of rustc
and related tools.
- All components are now built with
opt-level=3
instead of2
. - Improved how rustc generates drop code.
- Improved performance from
#[inline]
-ing certain hot functions. - traits: preallocate 2 Vecs of known initial size
- Avoid exponential behaviour when relating types
- Skip
Drop
terminators for enum variants without drop glue - Improve performance of coherence checks
- Deduplicate types in the generator witness
- Invert control in struct_lint_level.
Rust 1.42.0
Language
-
You can now use the slice pattern syntax with subslices. e.g.
fn foo(words: &[&str]) { match words { ["Hello", "World", "!", ..] => println!("Hello World!"), ["Foo", "Bar", ..] => println!("Baz"), rest => println!("{:?}", rest), } }
-
You can now use
#[repr(transparent)]
on univariantenum
s. Meaning that you can create an enum that has the exact layout and ABI of the type it contains. -
You can now use outer attribute procedural macros on inline modules.
-
There are some syntax-only changes:
default
is syntactically allowed before items intrait
definitions.- Items in
impl
s (i.e.const
s,type
s, andfn
s) may syntactically leave out their bodies in favor of;
. - Bounds on associated types in
impl
s are now syntactically allowed (e.g.type Foo: Ord;
). ...
(the C-variadic type) may occur syntactically directly as the type of any function parameter.
These are still rejected semantically, so you will likely receive an error but these changes can be seen and parsed by procedural macros and conditional compilation.
Compiler
- Added tier 2* support for
armv7a-none-eabi
. - Added tier 2 support for
riscv64gc-unknown-linux-gnu
. Option::{expect,unwrap}
andResult::{expect, expect_err, unwrap, unwrap_err}
now produce panic messages pointing to the location where they were called, rather thancore
's internals.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
iter::Empty<T>
now implementsSend
andSync
for anyT
.Pin::{map_unchecked, map_unchecked_mut}
no longer require the return type to implementSized
.io::Cursor
now derivesPartialEq
andEq
.Layout::new
is nowconst
.- Added Standard Library support for
riscv64gc-unknown-linux-gnu
.
Stabilized APIs
CondVar::wait_while
CondVar::wait_timeout_while
DebugMap::key
DebugMap::value
ManuallyDrop::take
matches!
ptr::slice_from_raw_parts_mut
ptr::slice_from_raw_parts
Cargo
Compatibility Notes
Error::description
has been deprecated, and its use will now produce a warning. It's recommended to useDisplay
/to_string
instead.
Rust 1.41.1
- Always check types of static items
- Always check lifetime bounds of
Copy
impls - Fix miscompilation in callers of
Layout::repeat
- Rust 1.41.0 was announced as the last Rust release with tier 1 or tier 2 support for 32-bit Apple targets. That announcement did not expect a patch release. 1.41.1 also includes release binaries for these targets.
Rust 1.41.0
Language
- You can now pass type parameters to foreign items when implementing traits. E.g. You can now write
impl<T> From<Foo> for Vec<T> {}
. - You can now arbitrarily nest receiver types in the
self
position. E.g. you can now writefn foo(self: Box<Box<Self>>) {}
. Previously onlySelf
,&Self
,&mut Self
,Arc<Self>
,Rc<Self>
, andBox<Self>
were allowed. - You can now use any valid identifier in a
format_args
macro. Previously identifiers starting with an underscore were not allowed. - Visibility modifiers (e.g.
pub
) are now syntactically allowed on trait items and enum variants. These are still rejected semantically, but can be seen and parsed by procedural macros and conditional compilation. - You can now define a Rust
extern "C"
function withBox<T>
and useT*
as the corresponding type on the C side. Please see the documentation for more information, including the important caveat about preferring to avoidBox<T>
in Rust signatures for functions defined in C.
Compiler
- Rustc will now warn if you have unused loop
'label
s. - Removed support for the
i686-unknown-dragonfly
target. - Added tier 3 support* for the
riscv64gc-unknown-linux-gnu
target. - You can now pass an arguments file passing the
@path
syntax to rustc. Note that the format differs somewhat from what is found in other tooling; please see the documentation for more information. - You can now provide
--extern
flag without a path, indicating that it is available from the search path or specified with an-L
flag.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
- The
core::panic
module is now stable. It was already stable throughstd
. NonZero*
numerics now implementFrom<NonZero*>
if it's a smaller integer width. E.g.NonZeroU16
now implementsFrom<NonZeroU8>
.MaybeUninit<T>
now implementsfmt::Debug
.
Stabilized APIs
Result::map_or
Result::map_or_else
std::rc::Weak::weak_count
std::rc::Weak::strong_count
std::sync::Weak::weak_count
std::sync::Weak::strong_count
Cargo
- Cargo will now document all the private items for binary crates by default.
cargo-install
will now reinstall the package if it detects that it is out of date.- Cargo.lock now uses a more git friendly format that should help to reduce merge conflicts.
- You can now override specific dependencies's build settings E.g.
[profile.dev.package.image] opt-level = 2
sets theimage
crate's optimisation level to2
for debug builds. You can also use[profile.<profile>.build-override]
to override build scripts and their dependencies.
Misc
- You can now specify
edition
in documentation code blocks to compile the block for that edition. E.g.edition2018
tells rustdoc that the code sample should be compiled the 2018 edition of Rust. - You can now provide custom themes to rustdoc with
--theme
, and check the current theme with--check-theme
. - You can use
#[cfg(doc)]
to compile an item when building documentation.
Compatibility Notes
- As previously announced 1.41 will be the last tier 1 release for 32-bit Apple targets. This means that the source code is still available to build, but the targets are no longer being tested and release binaries for those platforms will no longer be distributed by the Rust project. Please refer to the linked blog post for more information.
Rust 1.40.0
Language
-
You can now use tuple
struct
s and tupleenum
variant's constructors inconst
contexts. e.g.pub struct Point(i32, i32); const ORIGIN: Point = { let constructor = Point; constructor(0, 0) };
-
You can now mark
struct
s,enum
s, andenum
variants with the#[non_exhaustive]
attribute to indicate that there may be variants or fields added in the future. For example this requires adding a wild-card branch (_ => {}
) to any match statements on a non-exhaustiveenum
. (RFC 2008) -
You can now use function-like procedural macros in
extern
blocks and in type positions. e.g.type Generated = macro!();
-
The
meta
pattern matcher inmacro_rules!
now correctly matches the modern attribute syntax. For example(#[$m:meta])
now matches#[attr]
,#[attr{tokens}]
,#[attr[tokens]]
, and#[attr(tokens)]
.
Compiler
- Added tier 3 support* for the
thumbv7neon-unknown-linux-musleabihf
target. - Added tier 3 support for the
aarch64-unknown-none-softfloat
target. - Added tier 3 support for the
mips64-unknown-linux-muslabi64
, andmips64el-unknown-linux-muslabi64
targets.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
Stabilized APIs
BTreeMap::get_key_value
HashMap::get_key_value
Option::as_deref_mut
Option::as_deref
Option::flatten
UdpSocket::peer_addr
f32::to_be_bytes
f32::to_le_bytes
f32::to_ne_bytes
f64::to_be_bytes
f64::to_le_bytes
f64::to_ne_bytes
f32::from_be_bytes
f32::from_le_bytes
f32::from_ne_bytes
f64::from_be_bytes
f64::from_le_bytes
f64::from_ne_bytes
mem::take
slice::repeat
todo!
Cargo
- Cargo will now always display warnings, rather than only on fresh builds.
- Feature flags (except
--all-features
) passed to a virtual workspace will now produce an error. Previously these flags were ignored. - You can now publish
dev-dependencies
without including aversion
.
Misc
Compatibility Notes
- As previously announced, any previous NLL warnings in the 2015 edition are now hard errors.
- The
include!
macro will now warn if it failed to include the entire file. Theinclude!
macro unintentionally only includes the first expression in a file, and this can be unintuitive. This will become either a hard error in a future release, or the behavior may be fixed to include all expressions as expected. - Using
#[inline]
on function prototypes and consts now emits a warning underunused_attribute
lint. Using#[inline]
anywhere else inside traits orextern
blocks now correctly emits a hard error.
Rust 1.39.0
Language
- You can now create
async
functions and blocks withasync fn
,async move {}
, andasync {}
respectively, and you can now call.await
on async expressions. - You can now use certain attributes on function, closure, and function pointer parameters. These attributes include
cfg
,cfg_attr
,allow
,warn
,deny
,forbid
as well as inert helper attributes used by procedural macro attributes applied to items. e.g.fn len( #[cfg(windows)] slice: &[u16], #[cfg(not(windows))] slice: &[u8], ) -> usize { slice.len() }
- You can now take shared references to bind-by-move patterns in the
if
guards ofmatch
arms. e.g.fn main() { let array: Box<[u8; 4]> = Box::new([1, 2, 3, 4]); match array { nums // ---- `nums` is bound by move. if nums.iter().sum::<u8>() == 10 // ^------ `.iter()` implicitly takes a reference to `nums`. => { drop(nums); // ----------- Legal as `nums` was bound by move and so we have ownership. } _ => unreachable!(), } }
Compiler
- Added tier 3* support for the
i686-unknown-uefi
target. - Added tier 3 support for the
sparc64-unknown-openbsd
target. - rustc will now trim code snippets in diagnostics to fit in your terminal. Note Cargo currently doesn't use this feature. Refer to cargo#7315 to track this feature's progress.
- You can now pass
--show-output
argument to test binaries to print the output of successful tests.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
Vec::new
andString::new
are nowconst
functions.LinkedList::new
is now aconst
function.str::len
,[T]::len
andstr::as_bytes
are nowconst
functions.- The
abs
,wrapping_abs
, andoverflowing_abs
numeric functions are nowconst
.
Stabilized APIs
Cargo
- You can now publish git dependencies if supplied with a
version
. - The
--all
flag has been renamed to--workspace
. Using--all
is now deprecated.
Misc
Compatibility Notes
- Code that was previously accepted by the old borrow checker, but rejected by the NLL borrow checker is now a hard error in Rust 2018. This was previously a warning, and will also become a hard error in the Rust 2015 edition in the 1.40.0 release.
rustdoc
now requiresrustc
to be installed and in the same directory to run tests. This should improve performance when running a large amount of doctests.- The
try!
macro will now issue a deprecation warning. It is recommended to use the?
operator instead. asinh(-0.0)
now correctly returns-0.0
. Previously this returned0.0
.