[SOLVED]: Macro Error on Serde Serialize/Deserialize: `Err` value: ParseFloatError { kind: Invalid } rust-analyzer macro-error

With the latest Rust Analyzer release in VS Code (latest) I'm receiving the following error when deriving Serialize/Deserialize (Serde) on a simple struct:

proc macro returned error: proc-macro panicked: called Result::unwrap() on an Err value: ParseFloatError { kind: Invalid } rust-analyzer macro-error

I am getting the error with the following simple code:

use std::{fs::File, io, path::Path};

use serde::{Deserialize, Serialize};

fn main() -> Result<(), io::Error> {
    let move_a = Move {
        direction: Direction::North,
        count: 3,
    };

    let file = serialize(&move_a, &Path::new("./tmp.txt"))?;
    let move_b = deserialize(file)?;

    println!("Move A = {:?}", move_a);
    println!("Move B = {:?}", move_b);

    assert_eq!(move_a, move_b);

    Ok(())
}

fn serialize(the_move: &Move, path: &Path) -> Result<File, io::Error> {
    serde_json::to_writer(io::BufWriter::new(File::create(path)?), the_move)?;
    File::open(path)
}

fn deserialize(file: File) -> Result<Move, io::Error> {
    let u = serde_json::from_reader(io::BufReader::new(file))?;
    Ok(u)
}

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
enum Direction {
    North,
    NorthEast,
    East,
    SouthEast,
    South,
    SouthWest,
    West,
    NorthWest,
}

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
struct Move {
    pub direction: Direction,
    pub count: u8,
}

This code compile as runs fine from the command line using cargo run.

Also, somewhat counter-intuitively, the "Move" structure is recognized at the usage site as correctly implementing Serialize/Deserialize.

Is this a bug in rust-analyzer (it seems like it) or am I doing something wrong.

Here is my Cargo.toml:

[package]
name = "ex-bb2-serde-json"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

Should I open an issue?

EDIT: Answer "Yes". Here is the issue: https://github.com/rust-analyzer/rust-analyzer/issues/8928

Yes, if you managed to minimize examle, it definitelly makes sense to open an issue to get a :heart: :slight_smile:

I think we've seen this recently, but I don't remember if we tried to minimize this

Coolio. I'll open an issue and point to this forum post as well. Thanks.

Here is the issue opened for this: https://github.com/rust-analyzer/rust-analyzer/issues/8928

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.