Rust 1.38.0 release: pipelined compilation, # [deprecated] for macros and std :: any :: type_name

The Rust development team is pleased to announce the release of a new version, 1.38.0. Rust is a programming language that allows everyone to create reliable and efficient software.







If you installed the previous version of Rust using rustup, then to upgrade to version 1.38.0 you just need to run the following command:







rustup update stable
      
      





If you have not already installed rustup, you can install it from the corresponding page of our website.







What is included in the stable version?



The highlight of this release is pipelined compilation.







Pipeline compilation



The compiler needs not fully assembled dependencies to build the package, but only their "metadata" (a list of types, dependencies, exports, etc.) generated at an early stage of compilation. Starting with Rust 1.38.0, Cargo will immediately begin building dependent packages as soon as their metadata is available.







The build time of one package did not decrease, but our tests showed that the compilation speed increases by 10% -20% in the case of optimized builds (where some dependencies are already compiled). For other packages, a strong increase in compilation speed did not happen. The time it takes to build the package depends on the computer, so performance may vary. Pipeline compilation is enabled automatically from version 1.38.0.







Checking for some misuse of mem::{uninitialized, zeroed}





As previously announced , std::mem::uninitialized



not recommended. Instead, MaybeUninit<T>



should be used.







The mem::uninitialized



function is not yet deprecated, but this will be done in future releases. But despite this, starting at 1.38.0, rustc



checks for a narrow class of incorrect initializations using mem::uninitialized



or mem::zeroed



.







For some types, such as &T



and Box<T>



, a null value is considered undefined behavior, since they are pointer-like objects that should not be null



. It will be a mistake to use mem::uninitialized



or mem::zeroed



to initialize these types, so the compiler will try to warn you if any of these functions are used to initialize the above objects, and it does not matter whether they are initialized directly or as fields of large structure. This check is recursive, so the following code entails a warning:







 struct Wrap<T>(T); struct Outer(Wrap<Wrap<Wrap<Box<i32>>>>); struct CannotBeZero { outer: Outer, foo: i32, bar: f32 } ... let bad_value: CannotBeZero = unsafe { std::mem::uninitialized() };
      
      





Attentive readers may notice that the standard library contains more types that should not be filled with zeros, especially NonNull<T>



and NonZero<T>



. So far, the initialization of these structures through mem::uninitialized



or mem::zeroed



not been verified.







These checks do not cover all cases of improper use of mem::uninitialized



or mem::zeroed



, but allow you to detect a guaranteed incorrect code that should switch to MaybeUninit



.







#[deprecated]



for macros



The #[deprecated]



attribute, first introduced in Rust 1.9.0, allows package authors to notify users of outdated functionality that is planned to be removed in future releases. Rust 1.38.0 allows you to apply this attribute to macros.







std::any::type_name





A string representation of the type used may be needed when debugging code. For example, in the body of a generic function, you might want to print the type of the argument passed. Now this is std::any::type_name



with std::any::type_name



:







 fn gen_value<T: Default>() -> T { println!("Initializing an instance of {}", std::any::type_name::<T>()); Default::default() } fn main() { let _: i32 = gen_value(); let _: String = gen_value(); }
      
      





Result:







 Initializing an instance of i32 Initializing an instance of alloc::string::String
      
      





Like all functions of the standard library intended for debugging only, this function does not guarantee the exact contents and format of the string. The return value is the best description of the type; several types may be represented by the same type_name



, but it may change in future versions of the compiler.







Changes to the Standard Library





In addition, some functions have been stabilized:









Other changes



The syntax , the cargo package manager, and the Clippy analyzer have also undergone some changes.







Members 1.38.0



A lot of people came together to create Rust 1.38.0. We could not have done this without all of you, thank you !







From translators



With any questions on the Rust language, you can be helped in the Russian-language Telegram chat or in a similar chat for newcomers .







This article was jointly translated by andreevlex , nlinker , funkill and Gymmasssorla .








All Articles