Serde: "error: cannot find derive macro `Serialize` in this scope" with homepage example

Created on 25 Jul 2019  路  2Comments  路  Source: serde-rs/serde

Hey,

I'm really, really confused by this. For reference, I have this same issue on two different machines with two different projects running two different operating systems. Also, in one project it used to work fine maybe a week ago without me changing anything in the project.

My "serde" dependency is set to "*" in the Cargo.toml, so cargo updated it to the most recent version. When I try to set it to an older version again (I went back as far as 1.0.90), the error remains. Here's what happens:

Given this code (simple example project, that I just created):

Cargo.toml

[package]
name = "ggg"
version = "0.1.0"
authors = ["Benedikt Terhechte <[email protected]>"]
edition = "2018"

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

[dependencies]
serde = "1.0.97"

main.rs

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32
}

fn main() {
    println!("Hello, world!");
}

When I run cargo check or cargo build or cargo build --release the following error happens:

cargo build --release
   Compiling serde v1.0.97
   Compiling ggg v0.1.0 (/private/tmp/ggg)
error: cannot find derive macro `Deserialize` in this scope
 --> src/main.rs:3:21
  |
3 | #[derive(Serialize, Deserialize, Debug)]
  |                     ^^^^^^^^^^^

error: cannot find derive macro `Serialize` in this scope
 --> src/main.rs:3:10
  |
3 | #[derive(Serialize, Deserialize, Debug)]
  |          ^^^^^^^^^

warning: unused imports: `Deserialize`, `Serialize`
 --> src/main.rs:1:13
  |
1 | use serde::{Serialize, Deserialize};
  |             ^^^^^^^^^  ^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error: aborting due to 2 previous errors

error: Could not compile `ggg`.

To learn more, run the command again with --verbose.

cargo -V says: cargo 1.36.0 (c4fcfb725 2019-05-15)

Initially I thought, it would be a weird issue in my other project, but I've since created this super simple example project with nothing but the default example code, and it still fails.

Setting the Cargo.toml to serde = "*" and trying again (cargo clean; cargo build --release) still leads to the same issue. Anything else I can provide you with to help out?

Edit: One operating system is macOS 10.14, the other is macOS 10.15 beta.

Cheers

Most helpful comment

Take a look at where it says "Click to show Cargo.toml" in the readme, or check out https://serde.rs/derive.html. It looks like you haven't enabled the "derive" feature.

All 2 comments

Take a look at where it says "Click to show Cargo.toml" in the readme, or check out https://serde.rs/derive.html. It looks like you haven't enabled the "derive" feature.

Thanks, I鈥檒l try that tomorrow, is that a new addition?

Was this page helpful?
0 / 5 - 0 ratings