Merge pull request #2966 from dtolnay/noserdecore

Enforce derive cannot be used against serde_core
This commit is contained in:
David Tolnay
2025-09-13 14:19:01 -07:00
committed by GitHub
5 changed files with 27 additions and 8 deletions
-8
View File
@@ -34,14 +34,6 @@ rustdoc-args = [
"--extern-html-root-url=std=https://doc.rust-lang.org",
]
# This cfg cannot be enabled, but it still forces Cargo to keep serde_derive's
# version in lockstep with serde's, even if someone depends on the two crates
# separately with serde's "derive" feature disabled. Every serde_derive release
# is compatible with exactly one serde release because the generated code
# involves nonpublic APIs which are not bound by semver.
[target.'cfg(any())'.dependencies]
serde_derive = { version = "=1.0.219", path = "../serde_derive" }
### FEATURES #################################################################
+6
View File
@@ -256,3 +256,9 @@ extern crate serde_derive;
#[cfg(feature = "serde_derive")]
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub use serde_derive::{Deserialize, Serialize};
#[macro_export]
#[doc(hidden)]
macro_rules! __require_serde_not_serde_core {
() => {};
}
+8
View File
@@ -29,6 +29,14 @@ rustdoc-args = [
"--extern-html-root-url=std=https://doc.rust-lang.org",
]
# This cfg cannot be enabled, but it still forces Cargo to keep serde_derive's
# version in lockstep with serde's, even if someone depends on the two crates
# separately with serde's "derive" feature disabled. Every serde_derive release
# is compatible with exactly one serde release because the generated code
# involves nonpublic APIs which are not bound by semver.
[target.'cfg(any())'.dependencies]
serde_derive = { version = "=1.0.219", path = "../serde_derive" }
### FEATURES #################################################################
+10
View File
@@ -266,3 +266,13 @@ mod seed;
#[cfg(all(not(feature = "std"), no_core_error))]
mod std_error;
#[macro_export]
#[doc(hidden)]
macro_rules! __require_serde_not_serde_core {
() => {
::core::compile_error!(
"Serde derive requires a dependency on the serde crate, not serde_core"
);
};
}
+3
View File
@@ -22,6 +22,9 @@ pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> Token
)]
const _: () = {
#use_serde
_serde::__require_serde_not_serde_core!();
#code
};
}