From 256dae983bdbffc964b76ae17aa718b855702c92 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Sun, 5 May 2024 13:11:44 +0100 Subject: [PATCH 1/2] chore: bump rust and fix new lints that come with it --- Cargo.toml | 2 +- complement/Dockerfile | 2 +- flake.nix | 2 +- rust-toolchain.toml | 2 +- src/api/appservice_server.rs | 4 ++-- src/api/client_server/device.rs | 2 +- src/api/client_server/membership.rs | 4 ++-- src/api/ruma_wrapper/axum.rs | 2 +- src/api/server_server.rs | 4 ++-- src/database/abstraction.rs | 1 - src/database/abstraction/rocksdb.rs | 2 -- src/database/abstraction/sqlite.rs | 4 ++-- src/database/abstraction/watchers.rs | 2 +- src/database/mod.rs | 8 ++++---- src/main.rs | 6 +++--- src/service/globals/mod.rs | 6 +++--- src/service/pusher/mod.rs | 8 ++++---- src/service/rooms/spaces/mod.rs | 2 +- src/service/sending/mod.rs | 8 ++++---- src/service/users/mod.rs | 10 ++++++---- src/utils/mod.rs | 8 +++----- 21 files changed, 43 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb7463ca..1ab0798f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ version = "0.8.0-alpha" edition = "2021" # See also `rust-toolchain.toml` -rust-version = "1.75.0" +rust-version = "1.78.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/complement/Dockerfile b/complement/Dockerfile index 813af10e..341470af 100644 --- a/complement/Dockerfile +++ b/complement/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.75.0 +FROM rust:1.78.0 WORKDIR /workdir diff --git a/flake.nix b/flake.nix index 09aa9e09..91325443 100644 --- a/flake.nix +++ b/flake.nix @@ -59,7 +59,7 @@ file = ./rust-toolchain.toml; # See also `rust-toolchain.toml` - sha256 = "sha256-SXRtAuO4IqNOQq+nLbrsDFbVk+3aVA8NNpSZsKlVH/8="; + sha256 = "sha256-opUgs6ckUQCyDxcB9Wy51pqhd0MPGHUVbwRKKPGiwZU="; }; }); in diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f7a94340..811d9cef 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -10,7 +10,7 @@ # If you're having trouble making the relevant changes, bug a maintainer. [toolchain] -channel = "1.75.0" +channel = "1.78.0" components = [ # For rust-analyzer "rust-src", diff --git a/src/api/appservice_server.rs b/src/api/appservice_server.rs index 3ec7a66e..6af31d8f 100644 --- a/src/api/appservice_server.rs +++ b/src/api/appservice_server.rs @@ -10,12 +10,12 @@ use tracing::warn; /// /// Only returns None if there is no url specified in the appservice registration file #[tracing::instrument(skip(request))] -pub(crate) async fn send_request( +pub(crate) async fn send_request( registration: Registration, request: T, ) -> Result> where - T: Debug, + T: OutgoingRequest + Debug, { let destination = match registration.url { Some(url) => url, diff --git a/src/api/client_server/device.rs b/src/api/client_server/device.rs index aba061b2..9a42f048 100644 --- a/src/api/client_server/device.rs +++ b/src/api/client_server/device.rs @@ -53,7 +53,7 @@ pub async fn update_device_route( .get_device_metadata(sender_user, &body.device_id)? .ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?; - device.display_name = body.display_name.clone(); + device.display_name.clone_from(&body.display_name); services() .users diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 6fe1e0ea..cb43545e 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -213,7 +213,7 @@ pub async fn kick_user_route( .map_err(|_| Error::bad_database("Invalid member event in database."))?; event.membership = MembershipState::Leave; - event.reason = body.reason.clone(); + event.reason.clone_from(&body.reason); let mutex_state = Arc::clone( services() @@ -364,7 +364,7 @@ pub async fn unban_user_route( .map_err(|_| Error::bad_database("Invalid member event in database."))?; event.membership = MembershipState::Leave; - event.reason = body.reason.clone(); + event.reason.clone_from(&body.reason); let mutex_state = Arc::clone( services() diff --git a/src/api/ruma_wrapper/axum.rs b/src/api/ruma_wrapper/axum.rs index 0e66769b..a56ee359 100644 --- a/src/api/ruma_wrapper/axum.rs +++ b/src/api/ruma_wrapper/axum.rs @@ -286,7 +286,7 @@ where } }; - let mut http_request = http::Request::builder().uri(parts.uri).method(parts.method); + let mut http_request = Request::builder().uri(parts.uri).method(parts.method); *http_request.headers_mut().unwrap() = parts.headers; if let Some(CanonicalJsonValue::Object(json_body)) = &mut json_body { diff --git a/src/api/server_server.rs b/src/api/server_server.rs index d816a3e9..6ca352b8 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -116,12 +116,12 @@ impl FedDest { } #[tracing::instrument(skip(request))] -pub(crate) async fn send_request( +pub(crate) async fn send_request( destination: &ServerName, request: T, ) -> Result where - T: Debug, + T: OutgoingRequest + Debug, { if !services().globals.allow_federation() { return Err(Error::bad_config("Federation is disabled.")); diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index 0a321054..93660f9f 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -38,7 +38,6 @@ pub trait KeyValueDatabaseEngine: Send + Sync { fn memory_usage(&self) -> Result { Ok("Current database engine does not support memory usage reporting.".to_owned()) } - fn clear_caches(&self) {} } pub trait KvTree: Send + Sync { diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 447ee038..cf77e3dd 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -126,8 +126,6 @@ impl KeyValueDatabaseEngine for Arc { self.cache.get_pinned_usage() as f64 / 1024.0 / 1024.0, )) } - - fn clear_caches(&self) {} } impl RocksDbEngineTree<'_> { diff --git a/src/database/abstraction/sqlite.rs b/src/database/abstraction/sqlite.rs index 222a8433..b448c3b6 100644 --- a/src/database/abstraction/sqlite.rs +++ b/src/database/abstraction/sqlite.rs @@ -13,8 +13,8 @@ use thread_local::ThreadLocal; use tracing::debug; thread_local! { - static READ_CONNECTION: RefCell> = RefCell::new(None); - static READ_CONNECTION_ITERATOR: RefCell> = RefCell::new(None); + static READ_CONNECTION: RefCell> = const { RefCell::new(None) }; + static READ_CONNECTION_ITERATOR: RefCell> = const { RefCell::new(None) }; } struct PreparedStatementIterator<'a> { diff --git a/src/database/abstraction/watchers.rs b/src/database/abstraction/watchers.rs index 01156abd..eb5792be 100644 --- a/src/database/abstraction/watchers.rs +++ b/src/database/abstraction/watchers.rs @@ -20,7 +20,7 @@ impl Watchers { let mut rx = match self.watchers.write().unwrap().entry(prefix.to_vec()) { hash_map::Entry::Occupied(o) => o.get().1.clone(), hash_map::Entry::Vacant(v) => { - let (tx, rx) = tokio::sync::watch::channel(()); + let (tx, rx) = watch::channel(()); v.insert((tx, rx.clone())); rx } diff --git a/src/database/mod.rs b/src/database/mod.rs index 41da857c..8d1b1913 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -237,7 +237,7 @@ impl KeyValueDatabase { Self::check_db_setup(&config)?; if !Path::new(&config.database_path).exists() { - std::fs::create_dir_all(&config.database_path) + fs::create_dir_all(&config.database_path) .map_err(|_| Error::BadConfig("Database folder doesn't exists and couldn't be created (e.g. due to missing permissions). Please create the database folder yourself."))?; } @@ -846,7 +846,7 @@ impl KeyValueDatabase { let rule = rules_list.content.get(content_rule_transformation[0]); if rule.is_some() { let mut rule = rule.unwrap().clone(); - rule.rule_id = content_rule_transformation[1].to_owned(); + content_rule_transformation[1].clone_into(&mut rule.rule_id); rules_list .content .shift_remove(content_rule_transformation[0]); @@ -871,7 +871,7 @@ impl KeyValueDatabase { let rule = rules_list.underride.get(transformation[0]); if let Some(rule) = rule { let mut rule = rule.clone(); - rule.rule_id = transformation[1].to_owned(); + transformation[1].clone_into(&mut rule.rule_id); rules_list.underride.shift_remove(transformation[0]); rules_list.underride.insert(rule); } @@ -918,7 +918,7 @@ impl KeyValueDatabase { let mut account_data = serde_json::from_str::(raw_rules_list.get()).unwrap(); - let user_default_rules = ruma::push::Ruleset::server_default(&user); + let user_default_rules = Ruleset::server_default(&user); account_data .content .global diff --git a/src/main.rs b/src/main.rs index 84467543..5d60a6bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -217,7 +217,7 @@ async fn run_server() -> io::Result<()> { } async fn spawn_task( - req: axum::http::Request, + req: http::Request, next: axum::middleware::Next, ) -> std::result::Result { if services().globals.shutdown.load(atomic::Ordering::Relaxed) { @@ -229,13 +229,13 @@ async fn spawn_task( } async fn unrecognized_method( - req: axum::http::Request, + req: http::Request, next: axum::middleware::Next, ) -> std::result::Result { let method = req.method().clone(); let uri = req.uri().clone(); let inner = next.run(req).await; - if inner.status() == axum::http::StatusCode::METHOD_NOT_ALLOWED { + if inner.status() == StatusCode::METHOD_NOT_ALLOWED { warn!("Method not allowed: {method} {uri}"); return Ok(RumaResponse(UiaaResponse::MatrixError(RumaError { body: ErrorBody::Standard { diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 263463d7..2373a270 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -80,12 +80,12 @@ pub struct Service { /// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like. /// /// This is utilized to have sync workers return early and release read locks on the database. -pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>); +pub struct RotationHandler(broadcast::Sender<()>); impl RotationHandler { pub fn new() -> Self { - let (s, r) = broadcast::channel(1); - Self(s, r) + let s = broadcast::channel(1).0; + Self(s) } pub fn watch(&self) -> impl Future { diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 6ca86be7..83127e63 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -44,13 +44,13 @@ impl Service { } #[tracing::instrument(skip(self, destination, request))] - pub async fn send_request( + pub async fn send_request( &self, destination: &str, request: T, ) -> Result where - T: Debug, + T: OutgoingRequest + Debug, { let destination = destination.replace("/_matrix/push/v1/notify", ""); @@ -231,11 +231,11 @@ impl Service { let mut device = Device::new(pusher.ids.app_id.clone(), pusher.ids.pushkey.clone()); device.data.default_payload = http.default_payload.clone(); - device.data.format = http.format.clone(); + device.data.format.clone_from(&http.format); // Tweaks are only added if the format is NOT event_id_only if !event_id_only { - device.tweaks = tweaks.clone(); + device.tweaks.clone_from(&tweaks); } let d = vec![device]; diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 981d4a37..5addc6fc 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -482,7 +482,7 @@ impl Service { match join_rule { JoinRule::Restricted(r) => { for rule in &r.allow { - if let join_rules::AllowRule::RoomMembership(rm) = rule { + if let AllowRule::RoomMembership(rm) = rule { if let Ok(true) = services() .rooms .state_cache diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index 7e54e8b4..fa14f123 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -675,13 +675,13 @@ impl Service { } #[tracing::instrument(skip(self, destination, request))] - pub async fn send_federation_request( + pub async fn send_federation_request( &self, destination: &ServerName, request: T, ) -> Result where - T: Debug, + T: OutgoingRequest + Debug, { debug!("Waiting for permit"); let permit = self.maximum_requests.acquire().await; @@ -704,13 +704,13 @@ impl Service { /// /// Only returns None if there is no url specified in the appservice registration file #[tracing::instrument(skip(self, registration, request))] - pub async fn send_appservice_request( + pub async fn send_appservice_request( &self, registration: Registration, request: T, ) -> Result> where - T: Debug, + T: OutgoingRequest + Debug, { let permit = self.maximum_requests.acquire().await; let response = appservice_server::send_request(registration, request).await; diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index fb983a41..91331667 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -86,11 +86,12 @@ impl Service { for (list_id, list) in &mut request.lists { if let Some(cached_list) = cached.lists.get(list_id) { if list.sort.is_empty() { - list.sort = cached_list.sort.clone(); + list.sort.clone_from(&cached_list.sort); }; if list.room_details.required_state.is_empty() { - list.room_details.required_state = - cached_list.room_details.required_state.clone(); + list.room_details + .required_state + .clone_from(&cached_list.room_details.required_state); }; list.room_details.timeline_limit = list .room_details @@ -132,7 +133,8 @@ impl Service { (_, _) => {} } if list.bump_event_types.is_empty() { - list.bump_event_types = cached_list.bump_event_types.clone(); + list.bump_event_types + .clone_from(&cached_list.bump_event_types); }; } cached.lists.insert(list_id.clone(), list.clone()); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 0b5b1ae4..d09a1033 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -122,16 +122,14 @@ pub fn deserialize_from_str< 'de, D: serde::de::Deserializer<'de>, T: FromStr, - E: std::fmt::Display, + E: fmt::Display, >( deserializer: D, ) -> Result { struct Visitor, E>(std::marker::PhantomData); - impl<'de, T: FromStr, Err: std::fmt::Display> serde::de::Visitor<'de> - for Visitor - { + impl<'de, T: FromStr, Err: fmt::Display> serde::de::Visitor<'de> for Visitor { type Value = T; - fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { write!(formatter, "a parsable string") } fn visit_str(self, v: &str) -> Result From eec9b9ed87ec0494f55c51685918a9af83272340 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Sun, 5 May 2024 13:13:34 +0100 Subject: [PATCH 2/2] chore: bump nix --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da109e50..90de6024 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,7 +54,7 @@ before_script: ci: stage: ci - image: nixos/nix:2.20.4 + image: nixos/nix:2.22.0 script: # Cache the inputs required for the devShell - ./bin/nix-build-and-cache .#devShells.x86_64-linux.default.inputDerivation @@ -79,7 +79,7 @@ ci: artifacts: stage: artifacts - image: nixos/nix:2.20.4 + image: nixos/nix:2.22.0 script: - ./bin/nix-build-and-cache .#static-x86_64-unknown-linux-musl - cp result/bin/conduit x86_64-unknown-linux-musl