Releases: rust-lang/rust
Rust 1.31.0
Language
- 🎉 This version marks the release of the 2018 edition of Rust. 🎉
- New lifetime elision rules now allow for eliding lifetimes in functions and impl headers. E.g.
impl<'a> Reader for BufReader<'a> {}
can now beimpl Reader for BufReader<'_> {}
. Lifetimes are still required to be defined in structs. - You can now define and use
const
functions. These are currently a strict minimal subset of the const fn RFC. Refer to the language reference for what exactly is available. - You can now use tool lints, which allow you to scope lints from external tools using attributes. E.g.
#[allow(clippy::filter_map)]
. #[no_mangle]
and#[export_name]
attributes can now be located anywhere in a crate, not just in exported functions.- You can now use parentheses in pattern matches.
Compiler
Libraries
- You can now convert
num::NonZero*
types to their raw equivalents using theFrom
trait. E.g.u8
now implementsFrom<NonZeroU8>
. - You can now convert a
&Option<T>
intoOption<&T>
and&mut Option<T>
intoOption<&mut T>
using theFrom
trait. - You can now multiply (
*
) atime::Duration
by au32
.
Stabilized APIs
slice::align_to
slice::align_to_mut
slice::chunks_exact
slice::chunks_exact_mut
slice::rchunks
slice::rchunks_mut
slice::rchunks_exact
slice::rchunks_exact_mut
Option::replace
Cargo
Rust 1.30.1
Rust 1.30.0
Language
- Procedural macros are now available. These kinds of macros allow for more powerful code generation. There is a new chapter available in the Rust Programming Language book that goes further in depth.
- You can now use keywords as identifiers using the raw identifiers syntax (
r#
), e.g.let r#for = true;
- Using anonymous parameters in traits is now deprecated with a warning and will be a hard error in the 2018 edition.
- You can now use
crate
in paths. This allows you to refer to the crate root in the path, e.g.use crate::foo;
refers tofoo
insrc/lib.rs
. - Using a external crate no longer requires being prefixed with
::
. Previously, using a external crate in a module without a use statement requiredlet json = ::serde_json::from_str(foo);
but can now be written aslet json = serde_json::from_str(foo);
. - You can now apply the
#[used]
attribute to static items to prevent the compiler from optimising them away, even if they appear to be unused, e.g.#[used] static FOO: u32 = 1;
- You can now import and reexport macros from other crates with the
use
syntax. Macros exported with#[macro_export]
are now placed into the root module of the crate. If your macro relies on calling other local macros, it is recommended to export with the#[macro_export(local_inner_macros)]
attribute so users won't have to import those macros. - You can now catch visibility keywords (e.g.
pub
,pub(crate)
) in macros using thevis
specifier. - Non-macro attributes now allow all forms of literals, not just strings. Previously, you would write
#[attr("true")]
, and you can now write#[attr(true)]
. - You can now specify a function to handle a panic in the Rust runtime with the
#[panic_handler]
attribute.
Compiler
- Added the
riscv32imc-unknown-none-elf
target. - Added the
aarch64-unknown-netbsd
target - Upgraded to LLVM 8.
Libraries
Stabilized APIs
-
The following methods are replacement methods for
trim_left
,trim_right
,trim_left_matches
, andtrim_right_matches
, which will be deprecated in 1.33.0:
Cargo
cargo run
doesn't require specifying a package in workspaces.cargo doc
now supports--message-format=json
. This is equivalent to callingrustdoc --error-format=json
.- Cargo will now provide a progress bar for builds.
Misc
rustdoc
allows you to specify what edition to treat your code as with the--edition
option.rustdoc
now has the--color
(specify whether to output color) and--error-format
(specify error format, e.g.json
) options.- We now distribute a
rust-gdbgui
script that invokesgdbgui
with Rust debug symbols. - Attributes from Rust tools such as
rustfmt
orclippy
are now available, e.g.#[rustfmt::skip]
will skip formatting the next item.
Rust 1.29.2
- Workaround for an aliasing-related LLVM bug, which caused miscompilation.
- The
rls-preview
component on the windows-gnu targets has been restored.
Rust 1.29.1
Security Notes
-
The standard library's
str::repeat
function contained an out of bounds write caused by an integer overflow. This has been fixed by deterministically panicking when an overflow happens.Thank you to Scott McMurray for responsibly disclosing this vulnerability to us.
Rust 1.29.0
Compiler
- Bumped minimum LLVM version to 5.0.
- Added
powerpc64le-unknown-linux-musl
target. - Added
aarch64-unknown-hermit
andx86_64-unknown-hermit
targets. - Upgraded to LLVM 7.
Libraries
Once::call_once
no longer requiresOnce
to be'static
.BuildHasherDefault
now implementsPartialEq
andEq
.Box<CStr>
,Box<OsStr>
, andBox<Path>
now implementClone
.- Implemented
PartialEq<&str>
forOsString
andPartialEq<OsString>
for&str
. Cell<T>
now allowsT
to be unsized.SocketAddr
is now stable on Redox.
Stabilized APIs
Cargo
- Cargo can silently fix some bad lockfiles. You can use
--locked
to disable this behavior. cargo-install
will now allow you to cross compile an install using--target
.- Added the
cargo-fix
subcommand to automatically move project code from 2015 edition to 2018. cargo doc
can now optionally document private types using the--document-private-items
flag.
Misc
rustdoc
now has the--cap-lints
option which demotes all lints above the specified level to that level. For example--cap-lints warn
will demotedeny
andforbid
lints towarn
.rustc
andrustdoc
will now have the exit code of1
if compilation fails and101
if there is a panic.- A preview of clippy has been made available through rustup. You can install the preview with
rustup component add clippy-preview
.
Compatibility Notes
str::{slice_unchecked, slice_unchecked_mut}
are now deprecated. Usestr::get_unchecked(begin..end)
instead.std::env::home_dir
is now deprecated for its unintuitive behavior. Consider using thehome_dir
function from https://crates.io/crates/dirs instead.rustc
will no longer silently ignore invalid data in target spec.cfg
attributes and--cfg
command line flags are now more strictly validated.
Rust 1.28.0
Language
- The
#[repr(transparent)]
attribute is now stable. This attribute allows a Rust newtype wrapper (struct NewType<T>(T);
) to be represented as the inner type across Foreign Function Interface (FFI) boundaries. - The keywords
pure
,sizeof
,alignof
, andoffsetof
have been unreserved and can now be used as identifiers. - The
GlobalAlloc
trait and#[global_allocator]
attribute are now stable. This will allow users to specify a global allocator for their program. - Unit test functions marked with the
#[test]
attribute can now returnResult<(), E: Debug>
in addition to()
. - The
lifetime
specifier formacro_rules!
is now stable. This allows macros to easily target lifetimes.
Compiler
- The
s
andz
optimisation levels are now stable. These optimisations prioritise making smaller binary sizes.z
is the same ass
with the exception that it does not vectorise loops, which typically results in an even smaller binary. - The short error format is now stable. Specified with
--error-format=short
this option will provide a more compressed output of rust error messages. - Added a lint warning when you have duplicated
macro_export
s. - Reduced the number of allocations in the macro parser. This can improve compile times of macro heavy crates on average by 5%.
Libraries
- Implemented
Default
for&mut str
. - Implemented
From<bool>
for all integer and unsigned number types. - Implemented
Extend
for()
. - The
Debug
implementation oftime::Duration
should now be more easily human readable. Previously aDuration
of one second would printed asDuration { secs: 1, nanos: 0 }
and will now be printed as1s
. - Implemented
From<&String>
forCow<str>
,From<&Vec<T>>
forCow<[T]>
,From<Cow<CStr>>
forCString
,From<CString>, From<CStr>, From<&CString>
forCow<CStr>
,From<OsString>, From<OsStr>, From<&OsString>
forCow<OsStr>
,From<&PathBuf>
forCow<Path>
, andFrom<Cow<Path>>
forPathBuf
. - Implemented
Shl
andShr
forWrapping<u128>
andWrapping<i128>
. DirEntry::metadata
now usesfstatat
instead oflstat
when possible. This can provide up to a 40% speed increase.- Improved error messages when using
format!
.
Stabilized APIs
Iterator::step_by
Path::ancestors
SystemTime::UNIX_EPOCH
alloc::GlobalAlloc
alloc::Layout
alloc::LayoutErr
alloc::System
alloc::alloc
alloc::alloc_zeroed
alloc::dealloc
alloc::realloc
alloc::handle_alloc_error
btree_map::Entry::or_default
fmt::Alignment
hash_map::Entry::or_default
iter::repeat_with
num::NonZeroUsize
num::NonZeroU128
num::NonZeroU16
num::NonZeroU32
num::NonZeroU64
num::NonZeroU8
ops::RangeBounds
slice::SliceIndex
slice::from_mut
slice::from_ref
{Any + Send + Sync}::downcast_mut
{Any + Send + Sync}::downcast_ref
{Any + Send + Sync}::is
Cargo
- Cargo will now no longer allow you to publish crates with build scripts that modify the
src
directory. Thesrc
directory in a crate should be considered to be immutable.
Misc
- The
suggestion_applicability
field inrustc
's json output is now stable. This will allow dev tools to check whether a code suggestion would apply to them.
Compatibility Notes
- Rust will consider trait objects with duplicated constraints to be the same type as without the duplicated constraint. For example the below code will now fail to compile.
trait Trait {} impl Trait + Send { fn test(&self) { println!("one"); } //~ ERROR duplicate definitions with name `test` } impl Trait + Send + Send { fn test(&self) { println!("two"); } }
Rust 1.27.2
Compatibility Notes
- The borrow checker was fixed to avoid potential unsoundness when using match ergonomics: #52213.
Rust 1.27.1
Security Notes
-
rustdoc would execute plugins in the /tmp/rustdoc/plugins directory when running, which enabled executing code as some other user on a given machine. This release fixes that vulnerability; you can read more about this on the blog. The associated CVE is CVE-2018-1000622.
Thank you to Red Hat for responsibly disclosing this vulnerability to us.
Compatibility Notes
Rust 1.27.0
Language
- Removed 'proc' from the reserved keywords list. This allows
proc
to be used as an identifier. - The dyn syntax is now available. This syntax is equivalent to the bare
Trait
syntax, and should make it clearer when being used in tandem withimpl Trait
because it is equivalent to the following syntax:&Trait == &dyn Trait
,&mut Trait == &mut dyn Trait
, andBox<Trait> == Box<dyn Trait>
. - Attributes on generic parameters such as types and lifetimes are now stable. e.g.
fn foo<#[lifetime_attr] 'a, #[type_attr] T: 'a>() {}
- The
#[must_use]
attribute can now also be used on functions as well as types. It provides a lint that by default warns users when the value returned by a function has not been used.
Compiler
Libraries
- SIMD (Single Instruction Multiple Data) on x86/x86_64 is now stable. This includes
arch::x86
&arch::x86_64
modules which contain SIMD intrinsics, a new macro calledis_x86_feature_detected!
, the#[target_feature(enable="")]
attribute, and addingtarget_feature = ""
to thecfg
attribute. - A lot of methods for
[u8]
,f32
, andf64
previously only available in std are now available in core. - The generic
Rhs
type parameter onops::{Shl, ShlAssign, Shr}
now defaults toSelf
. std::str::replace
now has the#[must_use]
attribute to clarify that the operation isn't done in place.Clone::clone
,Iterator::collect
, andToOwned::to_owned
now have the#[must_use]
attribute to warn about unused potentially expensive allocations.
Stabilized APIs
DoubleEndedIterator::rfind
DoubleEndedIterator::rfold
DoubleEndedIterator::try_rfold
Duration::from_micros
Duration::from_nanos
Duration::subsec_micros
Duration::subsec_millis
HashMap::remove_entry
Iterator::try_fold
Iterator::try_for_each
NonNull::cast
Option::filter
String::replace_range
Take::set_limit
hint::unreachable_unchecked
os::unix::process::parent_id
ptr::swap_nonoverlapping
slice::rsplit_mut
slice::rsplit
slice::swap_with_slice
Cargo
cargo-metadata
now includesauthors
,categories
,keywords
,readme
, andrepository
fields.cargo-metadata
now includes a package'smetadata
table.- Added the
--target-dir
optional argument. This allows you to specify a different directory thantarget
for placing compilation artifacts. - Cargo will be adding automatic target inference for binaries, benchmarks, examples, and tests in the Rust 2018 edition. If your project specifies specific targets, e.g. using
[[bin]]
, and have other binaries in locations where cargo would infer a binary, Cargo will produce a warning. You can disable this feature ahead of time by setting any of the following to false:autobins
,autobenches
,autoexamples
,autotests
. - Cargo will now cache compiler information. This can be disabled by setting
CARGO_CACHE_RUSTC_INFO=0
in your environment.
Misc
- Added “The Rustc book” into the official documentation. “The Rustc book” documents and teaches how to use the rustc compiler.
- All books available on
doc.rust-lang.org
are now searchable.
Compatibility Notes
- Calling a
CharExt
orStrExt
method directly on core will no longer work. e.g.::core::prelude::v1::StrExt::is_empty("")
will not compile,"".is_empty()
will still compile. Debug
output onatomic::{AtomicBool, AtomicIsize, AtomicPtr, AtomicUsize}
will only print the inner type. E.g.print!("{:?}", AtomicBool::new(true))
will printtrue
, notAtomicBool(true)
.- The maximum number for
repr(align(N))
is now 2²⁹. Previously you could enter higher numbers but they were not supported by LLVM. Up to 512MB alignment should cover all use cases. - The
.description()
method on thestd::error::Error
trait has been soft-deprecated. It is no longer required to implement it.