esp-rs / rust

Rust for the xtensa architecture. Built in targets for the ESP32 and ESP8266
https://www.rust-lang.org
Other
743 stars 39 forks source link

Weird behavior on variable assign inside a match case #149

Closed FloppyDisck closed 2 years ago

FloppyDisck commented 2 years ago

I tried this code:

pub enum TemperatureUnit {
    Celsius,
    Fahrenheit
}

let unit = TemperatureUnit::Fahrenheit;

    let (sub, mul) = match unit {
    TemperatureUnit::Celsius => (45f32, 175f32),
    TemperatureUnit::Fahrenheit => (49f32, 315f32),
};

println!("{} {}", sub, mul);

I expected to see this happen: Its supposed to print 49 315

Instead, this happened: It prints -197961600000000000000000000 -197961600000000000000000000

Interesting enough, if you add println!(""); inside the match cases, the output comes out fine...

Meta

rustc --version --verbose:

rustc 1.62.1-nightly (e4f2cf605 2022-07-19)
binary: rustc
commit-hash: e4f2cf60561c2ad852af81cf1fddb7203ed058b1
commit-date: 2022-07-19
host: x86_64-unknown-linux-gnu
release: 1.62.1-nightly
LLVM version: 14.0.0
Backtrace

``` ```

usbalbin commented 2 years ago

Could this be #136?

MabezDev commented 2 years ago

rustc 1.62

This issue was fixed back in 1.63, please upgrade your toolchain.

Could this be https://github.com/esp-rs/rust/issues/136?

It's not, but we have a fix for that coming in the next toolchain :)