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"); } }