Description: Use bincode 1
 bincode 2 has a completely different API from 1. The usage in cache.rs is
 limited: encode/decode of three small structs. Port to bincode 1 by:
 - replacing bincode::Encode/Decode derives with serde::Serialize/Deserialize
 - replacing encode_to_vec/decode_from_reader with serialize/deserialize_from
 - adding two small helper functions for AtomicU64, which serde cannot derive
   automatically (bincode 2 supports atomic types natively)
Forwarded: not-needed
---
Index: ruff/Cargo.toml
===================================================================
--- ruff.orig/Cargo.toml
+++ ruff/Cargo.toml
@@ -68,7 +68,7 @@ anyhow = { version = "1.0.80" }
 arc-swap = { version = "1.7.1" }
 argfile = { version = "1.0.0" }
 assert_fs = { version = "1.1.0" }
-bincode = { version = "2.0.0" }
+bincode = { version = "1" }
 bitflags = { version = "2.5.0" }
 bitvec = { version = "1.0.1", default-features = false, features = [
     "alloc",
Index: ruff/crates/ruff/Cargo.toml
===================================================================
--- ruff.orig/crates/ruff/Cargo.toml
+++ ruff/crates/ruff/Cargo.toml
@@ -39,7 +39,7 @@ ruff_workspace = { workspace = true }

 anyhow = { workspace = true }
 argfile = { workspace = true }
-bincode = { workspace = true, features = ["serde"] }
+bincode = { workspace = true }
 bitflags = { workspace = true }
 cachedir = { workspace = true }
 clap = { workspace = true, features = ["derive", "env", "wrap_help"] }
Index: ruff/crates/ruff/src/cache.rs
===================================================================
--- ruff.orig/crates/ruff/src/cache.rs
+++ ruff/crates/ruff/src/cache.rs
@@ -110,7 +110,7 @@ impl Cache {
         };

         let mut package: PackageCache =
-            match bincode::decode_from_reader(BufReader::new(file), bincode::config::standard()) {
+            match bincode::deserialize_from(BufReader::new(file)) {
                 Ok(package) => package,
                 Err(err) => {
                     warn_user!("Failed parse cache file `{}`: {err}", path.display());
@@ -167,7 +167,7 @@ impl Cache {

         // Serialize to in-memory buffer because hyperfine benchmark showed that it's faster than
         // using a `BufWriter` and our cache files are small enough that streaming isn't necessary.
-        let serialized = bincode::encode_to_vec(&self.package, bincode::config::standard())
+        let serialized = bincode::serialize(&self.package)
             .context("Failed to serialize cache data")?;
         temp_file
             .write_all(&serialized)
@@ -317,7 +317,7 @@ fn tempfile_in(path: &Path) -> io::Resul
 }

 /// On disk representation of a cache of a package.
-#[derive(bincode::Encode, Debug, bincode::Decode)]
+#[derive(serde::Serialize, Debug, serde::Deserialize)]
 struct PackageCache {
     /// Path to the root of the package.
     ///
@@ -329,7 +329,7 @@ struct PackageCache {
 }

 /// On disk representation of the cache per source file.
-#[derive(bincode::Decode, Debug, bincode::Encode)]
+#[derive(serde::Deserialize, Debug, serde::Serialize)]
 pub(crate) struct FileCache {
     /// Key that determines if the cached item is still valid.
     key: u64,
@@ -337,6 +337,7 @@ pub(crate) struct FileCache {
     ///
     /// Represented as the number of milliseconds since Unix epoch. This will
     /// break in 1970 + ~584 years (~2554).
+    #[serde(serialize_with = "ser_atomic_u64", deserialize_with = "de_atomic_u64")]
     last_seen: AtomicU64,

     data: FileCacheData,
@@ -349,12 +350,21 @@ impl FileCache {
     }
 }

-#[derive(Debug, Default, bincode::Decode, bincode::Encode)]
+#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
 struct FileCacheData {
     linted: bool,
     formatted: bool,
 }

+fn ser_atomic_u64<S: serde::Serializer>(v: &AtomicU64, s: S) -> Result<S::Ok, S::Error> {
+    s.serialize_u64(v.load(Ordering::Relaxed))
+}
+
+fn de_atomic_u64<'de, D: serde::Deserializer<'de>>(d: D) -> Result<AtomicU64, D::Error> {
+    use serde::Deserialize;
+    Ok(AtomicU64::new(u64::deserialize(d)?))
+}
+
 /// Returns a hash key based on the `package_root`, `settings` and the crate
 /// version.
 fn cache_key(package_root: &Path, settings: &Settings) -> u64 {
