about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_dev/Cargo.toml1
-rw-r--r--clippy_dev/src/lib.rs1
-rw-r--r--clippy_dev/src/main.rs20
-rw-r--r--clippy_dev/src/sync.rs33
-rw-r--r--rust-toolchain2
5 files changed, 56 insertions, 1 deletions
diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml
index 952a8711fb4..d3a103eaf4c 100644
--- a/clippy_dev/Cargo.toml
+++ b/clippy_dev/Cargo.toml
@@ -6,6 +6,7 @@ edition = "2021"
 
 [dependencies]
 aho-corasick = "1.0"
+chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
 clap = { version = "4.4", features = ["derive"] }
 indoc = "1.0"
 itertools = "0.12"
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index d96b79ec26c..6505b33d345 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -20,5 +20,6 @@ pub mod lint;
 pub mod new_lint;
 pub mod serve;
 pub mod setup;
+pub mod sync;
 pub mod update_lints;
 pub mod utils;
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index f5055b42912..541ce50b6e0 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -3,7 +3,7 @@
 #![warn(rust_2018_idioms, unused_lifetimes)]
 
 use clap::{Args, Parser, Subcommand};
-use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, update_lints, utils};
+use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, sync, update_lints, utils};
 use std::convert::Infallible;
 
 fn main() {
@@ -75,6 +75,9 @@ fn main() {
             uplift,
         } => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift),
         DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, &reason),
+        DevCommand::Sync(SyncCommand { subcommand }) => match subcommand {
+            SyncSubcommand::UpdateNightly => sync::update_nightly(),
+        },
     }
 }
 
@@ -225,6 +228,8 @@ enum DevCommand {
         /// The reason for deprecation
         reason: String,
     },
+    /// Sync between the rust repo and the Clippy repo
+    Sync(SyncCommand),
 }
 
 #[derive(Args)]
@@ -291,3 +296,16 @@ enum RemoveSubcommand {
     /// Remove the tasks added with 'cargo dev setup vscode-tasks'
     VscodeTasks,
 }
+
+#[derive(Args)]
+struct SyncCommand {
+    #[command(subcommand)]
+    subcommand: SyncSubcommand,
+}
+
+#[derive(Subcommand)]
+enum SyncSubcommand {
+    #[command(name = "update_nightly")]
+    /// Update nightly version in rust-toolchain and `clippy_utils`
+    UpdateNightly,
+}
diff --git a/clippy_dev/src/sync.rs b/clippy_dev/src/sync.rs
new file mode 100644
index 00000000000..3522d182e90
--- /dev/null
+++ b/clippy_dev/src/sync.rs
@@ -0,0 +1,33 @@
+use std::fmt::Write;
+use std::path::Path;
+
+use chrono::offset::Utc;
+
+use crate::utils::{UpdateMode, replace_region_in_file};
+
+pub fn update_nightly() {
+    // Update rust-toolchain nightly version
+    let date = Utc::now().format("%Y-%m-%d").to_string();
+    replace_region_in_file(
+        UpdateMode::Change,
+        Path::new("rust-toolchain"),
+        "# begin autogenerated nightly\n",
+        "# end autogenerated nightly",
+        |res| {
+            writeln!(res, "channel = \"nightly-{date}\"").unwrap();
+        },
+    );
+
+    // Update clippy_utils nightly version
+    replace_region_in_file(
+        UpdateMode::Change,
+        Path::new("clippy_utils/README.md"),
+        "<!-- begin autogenerated nightly -->\n",
+        "<!-- end autogenerated nightly -->",
+        |res| {
+            writeln!(res, "```").unwrap();
+            writeln!(res, "nightly-{date}").unwrap();
+            writeln!(res, "```").unwrap();
+        },
+    );
+}
diff --git a/rust-toolchain b/rust-toolchain
index e32e0cb3604..0a2e9d89b6e 100644
--- a/rust-toolchain
+++ b/rust-toolchain
@@ -1,4 +1,6 @@
 [toolchain]
+# begin autogenerated nightly
 channel = "nightly-2024-11-14"
+# end autogenerated nightly
 components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
 profile = "minimal"