You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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};fnmain() -> 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(())}fnserialize(the_move:&Move,path:&Path) -> Result<File, io::Error>{
serde_json::to_writer(io::BufWriter::new(File::create(path)?), the_move)?;File::open(path)}fndeserialize(file:File) -> Result<Move, io::Error>{let u = serde_json::from_reader(io::BufReader::new(file))?;Ok(u)}#[derive(Debug,Serialize,Deserialize,Eq,PartialEq)]enumDirection{North,NorthEast,East,SouthEast,South,SouthWest,West,NorthWest,}#[derive(Debug,Serialize,Deserialize,Eq,PartialEq)]structMove{pubdirection:Direction,pubcount: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"
Reacted by Dakota Brink, therocode, Philip Kristoffersen, dozn, jzrake, luaneko, Christopher Lord and Marco Conte
NOTE: The error doesn't prevent the proper derivation of Serialize/Deserialize. It just shows the error (in the output tab if you don't have it configured to display errors inline). The error appears on the structure & enum. If I remove the Serialize/Deserialize from both, the error goes away, but then (obviously), Serialize/Deserialize is not implemented.
@gbutler69 You can use this patch which applies the upstream abi changes on top of rust-analyzer. Note, that this doesn't implement the functionality of rust-lang/rust#84717. But serde_derive should work without that.
@quantumsheep Switch to stable for you project (if possible) using: rustup default stable.
If you need to use nightly, then you'll need to apply the patch and use a patched version of rust-analyzer as mentioned by @cynecx
I just got this issue while using Rust stable on mac (rustc 1.48.0). Read through this issue and thought "I'm not using nightly, but I'll try it anyway". Rust updated to 1.54.0 and the issue is gone, so it's also worthwhile to make sure stable Rust is up to date as well. Hope this helps someone else!
I am experiencing this issue with nightly-2021-08-04-x86_64-unknown-linux-gnu in VSCode. I fixed it by overriding the rust-analyzer binary that is downloaded by VSCode with the one from the rustup toolchain install which gives me rust-analyzer ea105f9 2021-08-03 dev.
@flodiebold the version from VSCode before I overwrote it was rust-analyzer 3dae94bf2 2021-09-07 nightly (after I switched to the "nightly" channel, didn't check before that but since the channel was the "stable" one, I suppose the downloaded binary was the latest "stable" too). But neither worked, I had to overwrite the binary.
I tried uninstalling and reinstalling the VSCode (from "stable" channel) first, then again but switching to the "nightly" channel.
Activity
matklad commentedon May 22, 2021
Hm, I cant' reproduce this using the latest version of rust-analyzer:
Cound you check the version of rust-analyzer you are using? https://rust-analyzer.github.io/manual.html#troubleshooting
gbutler69 commentedon May 22, 2021
The RA version is: v0.2.599. The VSCode version is: 1.56.2.
lnicola commentedon May 22, 2021
And which
rustcversion?gbutler69 commentedon May 22, 2021
Latest nightly.
lnicola commentedon May 22, 2021
Dupe of #8925, I suppose.
gbutler69 commentedon May 22, 2021
NOTE: The error doesn't prevent the proper derivation of Serialize/Deserialize. It just shows the error (in the output tab if you don't have it configured to display errors inline). The error appears on the structure & enum. If I remove the Serialize/Deserialize from both, the error goes away, but then (obviously), Serialize/Deserialize is not implemented.
gbutler69 commentedon May 22, 2021
This does appear to be a nightly related issue. The problem goes away when I switch to stable.
lnicola commentedon May 22, 2021
Unfortunately, we currently don't support multiple proc macro ABIs, so we can't fix this until 1.54 comes out.
cynecx commentedon May 25, 2021
@gbutler69 You can use this patch which applies the upstream abi changes on top of rust-analyzer. Note, that this doesn't implement the functionality of rust-lang/rust#84717. But serde_derive should work without that.
quantumsheep commentedon Jun 1, 2021
Same issue :(
gbutler69 commentedon Jun 1, 2021
@quantumsheep Switch to stable for you project (if possible) using: rustup default stable.
If you need to use nightly, then you'll need to apply the patch and use a patched version of rust-analyzer as mentioned by @cynecx
branpk commentedon Jun 1, 2021
If you need to use nightly but not necessarily the latest nightly, you can also use
rustup default nightly-2021-05-20.sploders101 commentedon Aug 6, 2021
I just got this issue while using Rust stable on mac (rustc 1.48.0). Read through this issue and thought "I'm not using nightly, but I'll try it anyway". Rust updated to 1.54.0 and the issue is gone, so it's also worthwhile to make sure stable Rust is up to date as well. Hope this helps someone else!
tizoc commentedon Sep 7, 2021
I am experiencing this issue with
nightly-2021-08-04-x86_64-unknown-linux-gnuin VSCode. I fixed it by overriding the rust-analyzer binary that is downloaded by VSCode with the one from the rustup toolchain install which gives merust-analyzer ea105f9 2021-08-03 dev.flodiebold commentedon Sep 7, 2021
This was also fixed in #9550, I think.
@tizoc both of those versions are quite old. I'd instead recommend updating to the current stable version of rust-analyzer.
tizoc commentedon Sep 7, 2021
@flodiebold the version from VSCode before I overwrote it was
rust-analyzer 3dae94bf2 2021-09-07 nightly(after I switched to the "nightly" channel, didn't check before that but since the channel was the "stable" one, I suppose the downloaded binary was the latest "stable" too). But neither worked, I had to overwrite the binary.I tried uninstalling and reinstalling the VSCode (from "stable" channel) first, then again but switching to the "nightly" channel.