Rust 1.45.0: stabilization of functional procedural macros, fixes for conversion defects

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



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



rustup update stable


If you don't already have it rustup, you can install it from the appropriate page on our website, and also look at it on GitHub .



What's included in stable version 1.45.0



This release contains two big changes: fixing long-standing defects in converting between integers and floating point numbers, and stabilizing features necessary for at least one web framework to run on stable Rust.



Correction of defects in transformations



Initially Issue 10184 was opened in October 2013, for a year and a half before the release Rust 1.0. Since it rustcuses LLVM as its backend compiler, when you write code like this:



pub fn cast(x: f32) -> u8 {
    x as u8
}


The Rust compiler in versions 1.44.0 and earlier generated the following LLVM-IR:



define i8 @_ZN10playground4cast17h1bdf307357423fcfE(float %x) unnamed_addr #0 {
start:
  %0 = fptoui float %x to i8
  ret i8 %0
}


fptoui "floating point to unsigned integer".



, :



‘fptoui’ ( ) . ty2, .

The ‘fptoui’ instruction converts its floating-point operand into the nearest (rounding towards zero) unsigned integer value. If the value cannot fit in ty2, the result is a poison value.


, , . , : , .



, , :



fn cast(x: f32) -> u8 {
    x as u8
}

fn main() {
    let f = 300.0;

    let x = cast(f);

    println!("x: {}", x);
}


Rust 1.44.0 "x: 0", .. , . «» ( unsafe ) — , . I-unsound, .



. , , .



:



  • as " " (saturating cast),
  • unsafe , .


, :



  • array[i] , , array i + 1 ,
  • unsafe { array.get_unchecked(i) }, .


, ? :



fn cast(x: f32) -> u8 {
    x as u8
}

fn main() {
    let too_big = 300.0;
    let too_small = -100.0;
    let nan = f32::NAN;

    println!("too_big_casted = {}", cast(too_big));
    println!("too_small_casted = {}", cast(too_small));
    println!("not_a_number_casted = {}", cast(nan));
}


:



too_big_casted = 255
too_small_casted = 0
not_a_number_casted = 0


. ( ). NaN .



API :



let x: f32 = 1.0;
let y: u8 = unsafe { x.to_int_unchecked() };


, , . , , , .



,



Rust 1.30.0 « ». , gnome-class:



Gnome- — Rust. Rust- -, , GObject, , , GObject. , .

:



gobject_gen! {
    class MyClass: GObject {
        foo: Cell<i32>,
        bar: RefCell<String>,
    }

    impl MyClass {
        virtual fn my_virtual_method(&self, x: i32) {
            ... do something with x ...
        }
    }
}


" " — , , gobject_gen! .



Rust 1.45.0 :



// ,      "mac"

mac!(); //  , ,    

//    3 :
fn main() {
  let expr = mac!(); //  

  match expr {
      mac!() => {} //  
  }

  mac!(); //  
}


, , : Rocket. - Rocket, 2016 , , Rust. ", " :



#[macro_use] extern crate rocket;

#[get("/<name>/<age>")]
fn hello(name: String, age: u8) -> String {
    format!("Hello, {} year old named {}!", age, name)
}

#[launch]
fn rocket() -> rocket::Rocket {
    rocket::ignite().mount("/hello", routes![hello])
}


Rocket . , , Rocket proc_macro_hygiene . , , ! Rocket. !



Rocket , , :)





Rust 1.45.0 :





char :



for ch in 'a'..='z' {
    print!("{}", ch);
}
println!();
//  "abcdefghijklmnopqrstuvwxyz"


.





, Cargo Clippy .



1.45.0



, Rust 1.45.0. , !





Rust - . , .



nlinker, funkill, Hirrolot blandger.




All Articles