Why serde derive macros are not working?

Im building an ident generator and I want to add it serde support. But the code GitHub - IronThread/ident_gen: A simple ident generator that lets you chose the table that use. when ran with cargo build --all-features always throws me this error:

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
   --> src\lib.rs:258:10
    |
258 | #[derive(Serialize, Deserialize)]
    |          ^^^^^^^^^
    |
    = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
    = help: add `#![feature(rustc_private)]` to the crate attributes to enable
    = note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
   --> src\lib.rs:258:21
    |
258 | #[derive(Serialize, Deserialize)]
    |                     ^^^^^^^^^^^
    |
    = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
    = help: add `#![feature(rustc_private)]` to the crate attributes to enable
    = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
   --> src\lib.rs:258:10
    |
258 | #[derive(Serialize, Deserialize)]
    |          ^^^^^^^^^
    |
    = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
    = help: add `#![feature(rustc_private)]` to the crate attributes to enable
    = note: this error originates in the macro `try` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
   --> src\lib.rs:260:5
    |
260 |     table: String,
    |     ^^^^^^^^^^^^^
    |
    = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
    = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
   --> src\lib.rs:261:5
    |
261 |     ident: String,
    |     ^^^^^^^^^^^^^
    |
    = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
    = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
   --> src\lib.rs:258:21
    |
258 | #[derive(Serialize, Deserialize)]
    |                     ^^^^^^^^^^^
    |
    = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
    = help: add `#![feature(rustc_private)]` to the crate attributes to enable
    = note: this error originates in the macro `try` (in Nightly builds, run with -Z macro-backtrace for more info)

It throws me that error no matter if I import the macros from serde_derive and rename them with as. I see this as a real problem for serde originating from rustc. But I dont know if make an issue on serde,on rust or a comment on https://github.com/rust-lang/rust/issues/27812.
I tested only on nightly the following version:

rustc --version --verbose:
rustc 1.71.0-nightly (458d4dae8 2023-04-25)
binary: rustc
commit-hash: 458d4dae845ec155b285681a5b88305641abb868
commit-date: 2023-04-25
host: i686-pc-windows-msvc
release: 1.71.0-nightly
LLVM version: 16.0.2

Please tell me if this is happening in other channels,thank you for your attention.

Renaming crates that are involved in procedural macro code generation generally goes quite badly.

If you change your Cargo.toml to

[dependencies]
serde = { optional = true, package = "serde", version = "1", features = [
    "derive",
] }

[features]
serde = ["dep:serde", "std"]
std = []

and update the reference to serde2 it builds fine with the feature enabled.

Note that the dep:dependency_name syntax is only available from Rust 1.60 and up. If you want your crate to be compatible with releases before that, you'll need to use a different name for the feature like

use_serde = ["serde", "std"]
1 Like