diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5d565fb07..c0eccff9a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,10 +19,14 @@ jobs: timeout-minutes: 15 steps: - - run: rustup component add clippy rustfmt + - uses: actions/checkout@v4 - - name: Rust Cache - uses: Swatinem/rust-cache@v2.7.3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt, clippy + toolchain: 1.84.0 + # - name: Rust Cache + # uses: Swatinem/rust-cache@v2.7.3 - name: Check format run: cargo fmt --all -- --check - name: Check diff --git a/crates/ott-balancer/src/balancer.rs b/crates/ott-balancer/src/balancer.rs index 4c251b0af..6ed3eaf47 100644 --- a/crates/ott-balancer/src/balancer.rs +++ b/crates/ott-balancer/src/balancer.rs @@ -414,12 +414,12 @@ impl BalancerContext { pub fn select_monolith(&self, room: &RoomName) -> anyhow::Result<&BalancerMonolith> { let filtered = self.filter_monoliths(); - return self.monolith_selection.select_monolith(room, filtered); + self.monolith_selection.select_monolith(room, filtered) } pub fn random_monolith(&self) -> anyhow::Result<&BalancerMonolith> { let filtered = self.filter_monoliths(); - return self.monolith_selection.random_monolith(filtered); + self.monolith_selection.random_monolith(filtered) } #[instrument(skip(self, monolith), err, fields(monolith_id = %monolith))] diff --git a/crates/ott-balancer/src/client.rs b/crates/ott-balancer/src/client.rs index 0837e8922..475dd463d 100644 --- a/crates/ott-balancer/src/client.rs +++ b/crates/ott-balancer/src/client.rs @@ -346,10 +346,7 @@ pub async fn client_entry<'r>( Ok(()) } -async fn close<'s, S>( - stream: &mut WebSocketStream, - frame: CloseFrame<'static>, -) -> anyhow::Result<()> +async fn close(stream: &mut WebSocketStream, frame: CloseFrame<'static>) -> anyhow::Result<()> where S: AsyncRead + AsyncWrite + Unpin, { diff --git a/crates/ott-balancer/src/config.rs b/crates/ott-balancer/src/config.rs index cca95fdb4..cfb618d64 100644 --- a/crates/ott-balancer/src/config.rs +++ b/crates/ott-balancer/src/config.rs @@ -48,6 +48,7 @@ impl BalancerConfig { config.region = region.into(); } // SAFETY: CONFIG is only mutated once, and only from this thread. All other accesses are read-only. + #[allow(static_mut_refs)] CONFIG_INIT.call_once(|| unsafe { *CONFIG.borrow_mut() = Some(config) }); Ok(()) } @@ -55,13 +56,17 @@ impl BalancerConfig { /// Initialize the config with default values. pub fn init_default() { // SAFETY: CONFIG is only mutated once, and only from this thread. All other accesses are read-only. + #[allow(static_mut_refs)] CONFIG_INIT.call_once(|| unsafe { *CONFIG.borrow_mut() = Some(BalancerConfig::default()) }); } pub fn get() -> &'static Self { debug_assert!(CONFIG_INIT.is_completed(), "config not initialized"); // SAFETY: get is never called before CONFIG is initialized. - unsafe { CONFIG.as_ref().expect("config not initialized") } + #[allow(static_mut_refs)] + unsafe { + CONFIG.as_ref().expect("config not initialized") + } } /// Get a mutable reference to the config. Should only be used for tests and benchmarks. @@ -72,6 +77,7 @@ impl BalancerConfig { pub unsafe fn get_mut() -> &'static mut Self { debug_assert!(CONFIG_INIT.is_completed(), "config not initialized"); // SAFETY: get_mut is only used for benchmarks + #[allow(static_mut_refs)] CONFIG.as_mut().expect("config not initialized") } } diff --git a/crates/ott-balancer/src/selection.rs b/crates/ott-balancer/src/selection.rs index db21a9632..f3cb82758 100644 --- a/crates/ott-balancer/src/selection.rs +++ b/crates/ott-balancer/src/selection.rs @@ -13,12 +13,12 @@ pub trait MonolithSelection: std::fmt::Debug { &'a self, room: &RoomName, monoliths: Vec<&'a BalancerMonolith>, - ) -> anyhow::Result<&BalancerMonolith>; + ) -> anyhow::Result<&'a BalancerMonolith>; fn random_monolith<'a>( &'a self, monoliths: Vec<&'a BalancerMonolith>, - ) -> anyhow::Result<&BalancerMonolith> { + ) -> anyhow::Result<&'a BalancerMonolith> { let selected = monoliths .iter() .choose(&mut rand::thread_rng()) @@ -72,7 +72,7 @@ impl MonolithSelection for MinRoomsSelector { &'a self, _room: &RoomName, monoliths: Vec<&'a BalancerMonolith>, - ) -> anyhow::Result<&BalancerMonolith> { + ) -> anyhow::Result<&'a BalancerMonolith> { fn cmp(x: &BalancerMonolith, y: &BalancerMonolith) -> std::cmp::Ordering { x.rooms().len().cmp(&y.rooms().len()) } @@ -113,7 +113,7 @@ impl MonolithSelection for HashRingSelector { &'a self, room: &RoomName, monoliths: Vec<&'a BalancerMonolith>, - ) -> anyhow::Result<&BalancerMonolith> { + ) -> anyhow::Result<&'a BalancerMonolith> { let weight = self.config.weight.max(1); let mut ring = HashRing::new(); ring.batch_add( @@ -154,7 +154,7 @@ impl MonolithSelection for RandomSelector { &'a self, _room: &RoomName, monoliths: Vec<&'a BalancerMonolith>, - ) -> anyhow::Result<&BalancerMonolith> { + ) -> anyhow::Result<&'a BalancerMonolith> { self.random_monolith(monoliths) } }