Releases: rust-lang/rust
Rust 1.48.0
Language
- The
unsafekeyword is now syntactically permitted on modules. This is still rejected semantically, but can now be parsed by procedural macros.
Compiler
- Stabilised the
-C link-self-contained=<yes|no>compiler flag. This tellsrustcwhether to link its own C runtime and libraries or to rely on a external linker to find them. (Supported only onwindows-gnu,linux-musl, andwasiplatforms.) - You can now use
-C target-feature=+crt-staticonlinux-gnutargets. Note: If you're using cargo you must explicitly pass the--targetflag. - Added tier 2* support for
aarch64-unknown-linux-musl.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
io::Writeis now implemented for&ChildStdin&Sink,&Stdout, and&Stderr.- All arrays of any length now implement
TryFrom<Vec<T>>. - The
matches!macro now supports having a trailing comma. Vec<A>now implementsPartialEq<[B]>whereA: PartialEq<B>.- The
RefCell::{replace, replace_with, clone}methods now all use#[track_caller].
Stabilized APIs
The following previously stable methods are now const fn's:
Option::is_someOption::is_noneOption::as_refResult::is_okResult::is_errResult::as_refOrdering::reverseOrdering::then
Cargo
Rustdoc
- You can now link to items in
rustdocusing the intra-doc link syntax. E.g./// Uses [`std::future`]will automatically generate a link tostd::future's documentation. See "Linking to items by name" for more information. - You can now specify
#[doc(alias = "<alias>")]on items to add search aliases when searching throughrustdoc's UI.
Compatibility Notes
- Promotion of references to
'staticlifetime insideconst fnnow follows the same rules as inside afnbody. In particular,&foo()will not be promoted to'staticlifetime any more insideconst fns. - Associated type bindings on trait objects are now verified to meet the bounds declared on the trait when checking that they implement the trait.
- When trait bounds on associated types or opaque types are ambiguous, the compiler no longer makes an arbitrary choice on which bound to use.
- Fixed recursive nonterminals not being expanded in macros during pretty-print/reparse check. This may cause errors if your macro wasn't correctly handling recursive nonterminal tokens.
&mutreferences to non zero-sized types are no longer promoted.rustcwill now warn if you use attributes like#[link_name]or#[cold]in places where they have no effect.- Updated
_mm256_extract_epi8and_mm256_extract_epi16signatures inarch::{x86, x86_64}to returni32to match the vendor signatures. mem::uninitializedwill now panic if any inner types inside a struct or enum disallow zero-initialization.#[target_feature]will now error if used in a place where it has no effect.- Foreign exceptions are now caught by
catch_unwindand will cause an abort. Note: This behaviour is not guaranteed and is still considered undefined behaviour, see thecatch_unwinddocumentation for further information.
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.
- Building
rustcfrom source now usesninjaby default overmake. You can continue building withmakeby settingninja=falsein yourbootstrap.toml. - cg_llvm:
fewer_namesinuncached_llvm_type - Made
ensure_sufficient_stack()non-generic
Rust 1.47.0
Language
Compiler
- Stabilized the
-C control-flow-guardcodegen option, which enables Control Flow Guard for Windows platforms, and is ignored on other platforms. - Upgraded to LLVM 11.
- Added tier 3* support for the
thumbv4t-none-eabitarget. - Upgrade the FreeBSD toolchain to version 11.4
RUST_BACKTRACE's output is now more compact.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
CStrnow implementsIndex<RangeFrom<usize>>.- Traits in
std/coreare now implemented for arrays of any length, not just those of length less than 33. ops::RangeFullandops::Rangenow implement Default.panic::Locationnow implementsCopy,Clone,Eq,Hash,Ord,PartialEq, andPartialOrd.
Stabilized APIs
Ident::new_rawRange::is_emptyRangeInclusive::is_emptyResult::as_derefResult::as_deref_mutVec::leakpointer::offset_fromf32::TAUf64::TAU
The following previously stable APIs have now been made const.
- The
newmethod for allNonZerointegers. - The
checked_add,checked_sub,checked_mul,checked_neg,checked_shl,checked_shr,saturating_add,saturating_sub, andsaturating_mulmethods for all integers. - The
checked_abs,saturating_abs,saturating_neg, andsignumfor all signed integers. - The
is_ascii_alphabetic,is_ascii_uppercase,is_ascii_lowercase,is_ascii_alphanumeric,is_ascii_digit,is_ascii_hexdigit,is_ascii_punctuation,is_ascii_graphic,is_ascii_whitespace, andis_ascii_controlmethods forcharandu8.
Cargo
build-dependenciesare now built with opt-level 0 by default. You can override this by setting the following in yourCargo.toml.[profile.release.build-override] opt-level = 3
cargo-helpwill now display man pages for commands rather just the--helptext.cargo-metadatanow emits atestfield indicating if a target has tests enabled.workspace.default-membersnow respectsworkspace.exclude.cargo-publishwill now use an alternative registry by default if it's the only registry specified inpackage.publish.
Misc
- Added a help button beside Rustdoc's searchbar that explains rustdoc's type based search.
- Added the Ayu theme to rustdoc.
Compatibility Notes
- Bumped the minimum supported Emscripten version to 1.39.20.
- Fixed a regression parsing
{} && falsein tail expressions. - Added changes to how proc-macros are expanded in
macro_rules!that should help to preserve more span information. These changes may cause compilation errors if your macro was unhygenic or didn't correctly handleDelimiter::None. - Moved support for the CloudABI target to tier 3.
linux-gnutargets now require minimum kernel 2.6.32 and glibc 2.11.- Added the
rustc-docscomponent. This allows you to install and read the documentation for the compiler internal APIs. (Currently only available forx86_64-unknown-linux-gnu.)
Internal Only
- Improved default settings for bootstrapping in
x.py. You can read details about this change in the "Changes tox.pydefaults" post on the Inside Rust blog.
Rust 1.46.0
Language
if,match, andloopexpressions can now be used in const functions.- Additionally you are now also able to coerce and cast to slices (
&[T]) in const functions. - The
#[track_caller]attribute can now be added to functions to use the function's caller's location information for panic messages. - Recursively indexing into tuples no longer needs parentheses. E.g.
x.0.0over(x.0).0. mem::transmutecan now be used in statics and constants. Note You currently can't usemem::transmutein constant functions.
Compiler
- You can now use the
cdylibtarget on Apple iOS and tvOS platforms. - Enabled static "Position Independent Executables" by default for
x86_64-unknown-linux-musl.
Libraries
mem::forgetis now aconst fn.Stringnow implementsFrom<char>.- The
leading_ones, andtrailing_onesmethods have been stabilised for all integer types. vec::IntoIter<T>now implementsAsRef<[T]>.- All non-zero integer types (
NonZeroU8) now implementTryFromfor their zero-able equivalent (e.g.TryFrom<u8>). &[T]and&mut [T]now implementPartialEq<Vec<T>>.(String, u16)now implementsToSocketAddrs.vec::Drain<'_, T>now implementsAsRef<[T]>.
Stabilized APIs
Cargo
Added a number of new environment variables that are now available when compiling your crate.
CARGO_BIN_NAMEandCARGO_CRATE_NAMEProviding the name of the specific binary being compiled and the name of the crate.CARGO_PKG_LICENSEThe license from the manifest of the package.CARGO_PKG_LICENSE_FILEThe path to the license file.
Compatibility Notes
- The target configuration option
abi_blacklisthas been renamed tounsupported_abis. The old name will still continue to work. - Rustc will now warn if you cast a C-like enum that implements
Drop. This was previously accepted but will become a hard error in a future release. - Rustc will fail to compile if you have a struct with
#[repr(i128)]or#[repr(u128)]. This representation is currently only allowed onenums. - Tokens passed to
macro_rules!are now always captured. This helps ensure that spans have the correct information, and may cause breakage if you were relying on receiving spans with dummy information. - The InnoSetup installer for Windows is no longer available. This was a legacy installer that was replaced by a MSI installer a few years ago but was still being built.
{f32, f64}::asinhnow returns the correct values for negative numbers.- Rustc will no longer accept overlapping trait implementations that only differ in how the lifetime was bound.
- Rustc now correctly relates the lifetime of an existential associated type. This fixes some edge cases where
rustcwould erroneously allow you to pass a shorter lifetime than expected. - Rustc now dynamically links to
libz(also calledzlib) on Linux. The library will need to be installed forrustcto work, even though we expect it to be already available on most systems. - Tests annotated with
#[should_panic]are broken on ARMv7 while running under QEMU. - Pretty printing of some tokens in procedural macros changed. The exact output returned by rustc's pretty printing is an unstable implementation detail: we recommend any macro relying on it to switch to a more robust parsing system.
Rust 1.45.2
Rust 1.45.1
Rust 1.45.0
Language
- Out of range float to int conversions using
ashas been defined as a saturating conversion. This was previously undefined behaviour, but you can use the{f64, f32}::to_int_uncheckedmethods 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-featureflag. E.g.-C target-feature=+avx2 -C target-feature=+fmais now equivalent to-C target-feature=+avx2,+fma. - Added the
force-unwind-tablesflag. This option allows rustc to always generate unwind tables regardless of panic strategy. - Added the
embed-bitcodeflag. This codegen flag allows rustc to include LLVM bitcode into generatedrlibs (this is on by default). - Added the
tinyvalue to thecode-modelcodegen flag. - Added tier 3 support* for the
mipsel-sony-psptarget. - Added tier 3 support for the
thumbv7a-uwp-windows-msvctarget. - 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 implementsPartialOrdandOrd.proc_macro::TokenStreamnow implementsDefault.- You can now use
charwithops::{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"
OsStringnow implementsFromStr.- The
saturating_negmethod has been added to all signed integer primitive types, and thesaturating_absmethod has been added for all integer primitive types. Arc<T>,Rc<T>now implementFrom<Cow<'_, T>>, andBoxnow implementsFrom<Cow>whenTis[T: Copy],str,CStr,OsStr, orPath.Box<[T]>now implementsFrom<[T; N]>.BitOrandBitOrAssignare implemented for allNonZerointeger types.- The
fetch_min, andfetch_maxmethods have been added to all atomic integer types. - The
fetch_updatemethod has been added to all atomic integer types.
Stabilized APIs
Arc::as_ptrBTreeMap::remove_entryRc::as_ptrrc::Weak::as_ptrrc::Weak::from_rawrc::Weak::into_rawstr::strip_prefixstr::strip_suffixsync::Weak::as_ptrsync::Weak::from_rawsync::Weak::into_rawchar::UNICODE_VERSIONSpan::resolved_atSpan::located_atSpan::mixed_siteunix::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}::powinow returns a slightly different value on Windows. This is due to changes in LLVM's intrinsics which{f32, f64}::powiuses.- 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
ltoflag is incompatible with the newembed-bitcode=no. This may cause issues if LTO is enabled throughRUSTFLAGSorcargo rustcflags while cargo is addingembed-bitcodeitself. The recommended way to control LTO is with Cargo profiles, either inCargo.tomlor.cargo/config, or by settingCARGO_PROFILE_<name>_LTOin 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-unitsflag in incremental mode. Additionally when in incremental mode rustc defaults to 256 codegen units. - Refactored
catch_unwindto have zero-cost, unless unwinding is enabled and a panic is thrown. - Added tier 3* support for the
aarch64-unknown-noneandaarch64-unknown-none-softfloattargets. - Added tier 3 support for
arm64-apple-tvosandx86_64-apple-tvostargets.
Libraries
- Special cased
vec![]to map directly toVec::new(). This allowsvec![]to be able to be used inconstcontexts. convert::Infalliblenow implementsHash.OsStringnow implementsDerefMutandIndexMutreturning a&mut OsStr.- Unicode 13 is now supported.
Stringnow implementsFrom<&mut str>.IoSlicenow implementsCopy.Vec<T>now implementsFrom<[T; N]>. WhereNis at most 32.proc_macro::LexErrornow implementsfmt::DisplayandError.from_le_bytes,to_le_bytes,from_be_bytes,to_be_bytes,from_ne_bytes, andto_ne_bytesmethods are nowconstfor all integer types.
Stabilized APIs
PathBuf::with_capacityPathBuf::capacityPathBuf::clearPathBuf::reservePathBuf::reserve_exactPathBuf::shrink_to_fitf32::to_int_uncheckedf64::to_int_uncheckedLayout::align_toLayout::pad_to_alignLayout::arrayLayout::extend
Cargo
- Added the
cargo treecommand 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
.aextension, rather than the previous.lib. - Removed the
-C no_integrated_asflag from rustc. - The
file_nameproperty 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
f64tou32using theasoperator has been defined as a saturating operation. This was previously undefined behaviour, but you can use the{f64, f32}::to_int_uncheckedmethods 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 onifexpressions.
Syntax only changes
- Allow
type Foo: Ordsyntactically. - Fuse associated and extern items up to defaultness.
- Syntactically allow
selfin allfncontexts. - Merge
fnsyntax + cleanup item parsing. itemmacro fragments can be interpolated intotraits,impls, andexternblocks. 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-variablesdenies everything in theunusedlint group exceptunused-variableswhich is explicitly allowed. However, passingrustc -A unused-variables -D unuseddenies everything in theunusedlint group includingunused-variablessince 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 whenNis0..=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::MAXorf32::NANwith no imports. u8::is_asciiis nowconst.Stringnow implementsAsMut<str>.- Added the
primitivemodule tostdandcore. 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
HashMapandHashSet. string::FromUtf8Errornow 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-programyou would useenv!("CARGO_BIN_EXE_my-program").
Misc
- Certain checks in the
const_errlint were deemed unrelated to const evaluation, and have been moved to theunconditional_panicandarithmetic_overflowlints.
Compatibility Notes
- Having trailing syntax in the
assert!macro is now a hard error. This has been a warning since 1.36.0. - Fixed
Selfnot 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=3instead 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
Dropterminators for enum variants without drop glue - Improve performance of coherence checks
- Deduplicate types in the generator witness
- Invert control in struct_lint_level.