Use differently named __private module per patch release

This commit is contained in:
David Tolnay
2025-09-15 09:48:58 -07:00
parent 957996f5fb
commit cbe98a9888
7 changed files with 54 additions and 10 deletions
+16
View File
@@ -1,13 +1,29 @@
use std::env; use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::str; use std::str;
const PRIVATE: &str = "\
#[doc(hidden)]
pub mod __private$$ {
#[doc(hidden)]
pub use crate::private::*;
}
use serde_core::__private$$ as serde_core_private;
";
// The rustc-cfg strings below are *not* public API. Please let us know by // The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable // opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script. // these cfgs other than by executing our build script.
fn main() { fn main() {
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
let module = PRIVATE.replace("$$", &patch_version);
fs::write(out_dir.join("private.rs"), module).unwrap();
let minor = match rustc_minor_version() { let minor = match rustc_minor_version() {
Some(minor) => minor, Some(minor) => minor,
None => return, None => return,
+3 -2
View File
@@ -239,8 +239,9 @@ mod integer128;
// Used by generated code and doc tests. Not public API. // Used by generated code and doc tests. Not public API.
#[doc(hidden)] #[doc(hidden)]
#[path = "private/mod.rs"] mod private;
pub mod __private;
include!(concat!(env!("OUT_DIR"), "/private.rs"));
// Re-export #[derive(Serialize, Deserialize)]. // Re-export #[derive(Serialize, Deserialize)].
// //
+3 -3
View File
@@ -17,7 +17,7 @@ pub use self::content::{
UntaggedUnitVisitor, UntaggedUnitVisitor,
}; };
pub use serde_core::__private::InPlaceSeed; pub use crate::serde_core_private::InPlaceSeed;
/// If the missing field is of type `Option<T>` then treat is as `None`, /// If the missing field is of type `Option<T>` then treat is as `None`,
/// otherwise it is an error. /// otherwise it is an error.
@@ -216,8 +216,8 @@ mod content {
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny, self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
MapAccess, SeqAccess, Unexpected, Visitor, MapAccess, SeqAccess, Unexpected, Visitor,
}; };
use serde_core::__private::size_hint; use crate::serde_core_private::size_hint;
pub use serde_core::__private::Content; pub use crate::serde_core_private::Content;
pub fn content_as_str<'a, 'de>(content: &'a Content<'de>) -> Option<&'a str> { pub fn content_as_str<'a, 'de>(content: &'a Content<'de>) -> Option<&'a str> {
match *content { match *content {
+1 -1
View File
@@ -12,7 +12,7 @@ pub use crate::lib::option::Option::{self, None, Some};
pub use crate::lib::ptr; pub use crate::lib::ptr;
pub use crate::lib::result::Result::{self, Err, Ok}; pub use crate::lib::result::Result::{self, Err, Ok};
pub use serde_core::__private::string::from_utf8_lossy; pub use crate::serde_core_private::string::from_utf8_lossy;
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
pub use crate::lib::{ToString, Vec}; pub use crate::lib::{ToString, Vec};
+15
View File
@@ -1,13 +1,28 @@
use std::env; use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::str; use std::str;
const PRIVATE: &str = "\
#[doc(hidden)]
pub mod __private$$ {
#[doc(hidden)]
pub use crate::private::*;
}
";
// The rustc-cfg strings below are *not* public API. Please let us know by // The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable // opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script. // these cfgs other than by executing our build script.
fn main() { fn main() {
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
let module = PRIVATE.replace("$$", &patch_version);
fs::write(out_dir.join("private.rs"), module).unwrap();
let minor = match rustc_minor_version() { let minor = match rustc_minor_version() {
Some(minor) => minor, Some(minor) => minor,
None => return, None => return,
+12 -3
View File
@@ -252,9 +252,18 @@ pub use crate::ser::{Serialize, Serializer};
// Used by generated code. Not public API. // Used by generated code. Not public API.
#[doc(hidden)] #[doc(hidden)]
#[path = "private/mod.rs"] mod private;
pub mod __private;
use self::__private as private; // Used by declarative macro generated code. Not public API.
#[doc(hidden)]
pub mod __private {
#[doc(hidden)]
pub use crate::private::doc;
#[doc(hidden)]
pub use core::result::Result;
}
include!(concat!(env!("OUT_DIR"), "/private.rs"));
#[cfg(all(not(feature = "std"), no_core_error))] #[cfg(all(not(feature = "std"), no_core_error))]
mod std_error; mod std_error;
+4 -1
View File
@@ -96,7 +96,10 @@ struct private;
impl private { impl private {
fn ident(&self) -> Ident { fn ident(&self) -> Ident {
Ident::new("__private", Span::call_site()) Ident::new(
concat!("__private", env!("CARGO_PKG_VERSION_PATCH")),
Span::call_site(),
)
} }
} }