Rust programming language 1.58 release

The release of the general-purpose programming language Rust 1.58, founded by the Mozilla project, but now developed under the auspices of the independent non-profit organization Rust Foundation, has been published. The language focuses on memory safety, provides automatic memory management, and provides the means to achieve high task parallelism without using a garbage collector or runtime (runtime is reduced to basic initialization and maintenance of the standard library).

Rust's automatic memory management saves the developer from errors when manipulating pointers and protects against problems that arise due to low-level memory manipulation, such as accessing a memory area after it has been freed, dereferencing null pointers, buffer overruns, etc. To distribute libraries, provide builds and manage dependencies, the project develops the Cargo package manager. The crates.io repository is supported for hosting libraries.

Main innovations:

  • In line formatting blocks, in addition to the previously available ability to substitute variables explicitly listed after a line by number and name, the ability to substitute arbitrary identifiers by adding the expression “{identifier}” to the line is implemented. For example: // Previously supported constructions: println!("Hello, {}!", get_person()); println!("Hello, {0}!", get_person()); println!("Hello, {person}!", person = get_person()); // now you can specify let person = get_person(); println!("Hello, {person}!");

    Identifiers can also be specified directly in formatting options. let (width, precision) = get_format(); for (name, score) in get_scores() { println!("{name}: {score:width$.precision$}"); }

    The new substitution works in all macros that support string format definition, with the exception of the “panic!” macro. in the 2015 and 2018 versions of the Rust language, in which panic!("{ident}") is treated as a regular string (in Rust 2021 the substitution works).

  • The behavior of the std::process::Command structure on the Windows platform has been changed so that when executing commands, for security reasons, it no longer looks for executable files in the current directory. The current directory is excluded because it could be used to execute malicious code if programs are run in untrusted directories (CVE-2021-3013). The new executable detection logic involves searching the Rust directories, the application directory, the Windows system directory, and the directories specified in the PATH environment variable.
  • The standard library has expanded the number of functions marked "#[must_use]" to issue a warning if the return value is ignored, which helps identify errors caused by assuming a function will change values ​​rather than return a new value.
  • A new portion of the API has been moved to the category of stable, including the methods and implementations of traits have been stabilized:
    • Metadata::is_symlink
    • Path::is_symlink
    • {integer}::saturating_div
    • Option::unwrap_unchecked
    • Result::unwrap_unchecked
    • Result::unwrap_err_unchecked
  • The "const" attribute, which determines the possibility of using it in any context instead of constants, is used in functions:
    • Duration::new
    • Duration::checked_add
    • Duration::saturating_add
    • Duration::checked_sub
    • Duration::saturating_sub
    • Duration::checked_mul
    • Duration::saturating_mul
    • Duration::checked_div
  • Allowed dereferencing of "*const T" pointers in "const" contexts.
  • In the Cargo package manager, the rust_version field has been added to the package metadata, and the “--message-format” option has been added to the “cargo install” command.
  • The compiler implements support for the CFI (Control Flow Integrity) protection mechanism, which adds checks before each indirect call to detect some forms of undefined behavior that could potentially lead to a violation of the normal execution order (control flow) as a result of the use of exploits that change pointers stored in memory on functions.
  • The compiler has added support for versions 5 and 6 of the LLVM coverage comparison format, used to evaluate code coverage during testing.
  • In the compiler, the requirements for the minimum version of LLVM are raised to LLVM 12.
  • The third level of support for the x86_64-unknown-none platform has been implemented. The third level involves basic support, but without automated testing, publishing official builds, or checking whether the code can be built.

Additionally, we can note the publication by Microsoft of the release of Rust for Windows 0.30 libraries, which allow you to use the Rust language to develop applications for the Windows OS. The set includes two crate packages (windows and windows-sys), through which you can access the Win API in Rust programs. Code for API support is generated dynamically from metadata describing the API, which allows you to implement support not only for existing Win API calls, but for calls that will appear in the future. The new version adds support for the UWP (Universal Windows Platform) target platform and implements the Handle and Debug types.

Source: opennet.ru

Add a comment