Rust’s development team released a new language update on Wednesday. Rust 1.45.0 comes with very few new features, but several improvements and bug fixes. There is also in this version the stabilization of certain APIs. Here is a few lines on what it is all about.

  • Correction of casts solidity defects
  • The Rust compiler in Rust 1.44.0 and older versions of the language would produce an that looks like this:

    LLVM-IR

    This fptoui implements the cast, it is the abbreviation of “floating point to unsigned integer”. But according to the Rust team, there’s a problem with that. According to the language documentation, the “fptoui” instruction converts its floating point operand to the nearest unsigned integer value (rounded to zero). If the value cannot hold in ty2, the result is a “poisoned” value. This means that if you transform a floating point number that is large to an integer that is small, you get undefined behavior.

    This behavior is for example not defined:

    behavior

    With Rust 1.44.0 it happens to print “x: 0”, but it could print anything, or do anything. It is undefined behavior. But there is no unsafe code here. This is called a “robustness” bug, that is, a bug where the compiler does something unexpected. That said, the problem is now resolved. According to the team, this bug took a long time to resolve because it was not at all sure what to do next. Ultimately, it was decided that you would need to add a new unsafe cast if you wanted to skip the controls.

    According to the team, this is very similar to accessing tables. For example, array [i] will check that the array has at least i + 1 elements. So you can use “unsafe {array.get_unchecked (i)}” to skip the check. However, she cautioned against this method. “But as always, you should only use this method as a last resort. As with accessing tables, the compiler can often optimize checks, making the safe and insecure versions equivalent when the compiler can prove it, “she said.

  • Stabilization of functional type procedural macros in expressions, models and statements
  • In Rust 1.45.0, functions such as procedural macros can now be used in expression, template and declaration positions. This means that you can now use a procedural macro of the function type wherever you can use a declarative macro (macro_rules!). Rust 1.45.0 also introduces other improvements to the compiler, including:

    • it is now possible to replace individual target entities via the target-feature indicator. For example, -C target-feature = + avx2 -C target-feature = + fma is now equivalent to -C target-feature = + avx2, + fma;
    • added the force-unwind-tables flag. This option allows rustc to always generate workout tables, regardless of the panic strategy;
    • added the embed-bitcode flag. This codegen flag allows rustc to include the LLVM bitcode in the generated rlibs (it is enabled by default);
    • adding the tiny value to the codegen code-model flag;
    • added level 3 support for the mipsel-sony-psp target;
    • added level 3 support for the thumbv7a-uwp-windows-msvc target.

    In addition, as of this version, Rust now supports barcode in Markdown. Finally, several APIs are stabilized in Rust 1.45.0, including:

    • Arc::as_ptr ;
    • BTreeMap::remove_entry ;
    • Rc::as_ptr ;
    • rc::Weak::as_ptr ;
    • rc::Weak::from_raw ;
    • rc::Weak::into_raw ;
    • str::strip_prefix ;
    • str::strip_suffixe ;
    • sync::Weak::as_ptr ;
    • sync::Weak::from_raw ;
    • sync::Weak::into_raw ;
    • char::UNICODE_VERSION ;
    • Span::resolved_at ;
    • Span::located_at ;
    • Span::mixed_site ;
    • unix::process::CommandExt::arg0.

Source : Rust

Related Articles
Leave a Reply

Your email address will not be published.