From ded6a5af0747e7d5a58ae8352758c5a56bc9d7d5 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Wed, 10 May 2023 11:27:57 -0700 Subject: [PATCH] cargo clippy fixes, enable lints in CI --- .github/workflows/ci.yml | 50 ++++++++++++++--------------- example/proxy/src/main.rs | 2 +- riven/src/req/rate_limit.rs | 4 +-- riven/src/req/regional_requester.rs | 4 +-- riven/src/riot_api.rs | 2 -- riven/tests/tests_euw.rs | 4 +-- riven/tests/tests_euw_tft.rs | 6 ++-- riven/tests/tests_la1.rs | 2 +- riven/tests/tests_na.rs | 4 +-- riven/tests/testutils.rs | 4 +-- 10 files changed, 38 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9f83cb..51b3661 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,31 +90,31 @@ jobs: RUSTLOG: riven=trace RGAPI_KEY: ${{ secrets.RGAPI_KEY }} - # lints: - # name: Lints - # needs: pre_job - # if: ${{ needs.pre_job.outputs.should_skip != 'true' }} - # runs-on: ubuntu-latest - # steps: - # - name: Checkout sources - # uses: actions/checkout@v2 + lints: + name: Lints + needs: pre_job + if: ${{ needs.pre_job.outputs.should_skip != 'true' }} + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 - # - name: Install nightly toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: nightly - # override: true - # components: rustfmt, clippy + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt, clippy - # - name: Run cargo fmt - # uses: actions-rs/cargo@v1 - # with: - # command: fmt - # args: --all -- --check + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check - # - name: Run cargo clippy - # uses: actions-rs/cargo@v1 - # with: - # command: clippy - # args: -- -D warnings + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/example/proxy/src/main.rs b/example/proxy/src/main.rs index 10c0642..5a5e4fc 100644 --- a/example/proxy/src/main.rs +++ b/example/proxy/src/main.rs @@ -116,7 +116,7 @@ async fn handle_request(req: Request) -> Result, Infallible } Ok(bytes) => bytes, }; - *out_response.body_mut() = Body::from((&bytes[..]).to_vec()); + *out_response.body_mut() = Body::from(bytes); } Ok(out_response) } diff --git a/riven/src/req/rate_limit.rs b/riven/src/req/rate_limit.rs index c4f018e..7b04824 100644 --- a/riven/src/req/rate_limit.rs +++ b/riven/src/req/rate_limit.rs @@ -1,8 +1,6 @@ use std::cmp; use std::time::{Duration, Instant}; -#[cfg(not(feature = "tracing"))] -use log; #[cfg(feature = "tracing")] use tracing as log; @@ -231,7 +229,7 @@ impl RateLimit { if let (Some(limit_header), Some(count_header)) = (limit_header_opt, count_header_opt) { { let buckets = self.buckets.upgradable_read(); - if !buckets_require_updating(limit_header, &*buckets) { + if !buckets_require_updating(limit_header, &buckets) { return; } diff --git a/riven/src/req/regional_requester.rs b/riven/src/req/regional_requester.rs index ddb3b11..08a79d7 100644 --- a/riven/src/req/regional_requester.rs +++ b/riven/src/req/regional_requester.rs @@ -1,8 +1,6 @@ use std::future::Future; use std::sync::Arc; -#[cfg(not(feature = "tracing"))] -use log; #[cfg(feature = "tracing")] use tracing as log; #[cfg(feature = "tracing")] @@ -54,7 +52,7 @@ impl RegionalRequester { .get_or_insert_with(method_id, || RateLimit::new(RateLimitType::Method)); // Rate limit. - let rate_limit = RateLimit::acquire_both(&self.app_rate_limit, &*method_rate_limit); + let rate_limit = RateLimit::acquire_both(&self.app_rate_limit, &method_rate_limit); #[cfg(feature = "tracing")] let rate_limit = rate_limit.instrument(tracing::info_span!("rate_limit")); rate_limit.await; diff --git a/riven/src/riot_api.rs b/riven/src/riot_api.rs index 045a70b..3d30ede 100644 --- a/riven/src/riot_api.rs +++ b/riven/src/riot_api.rs @@ -1,8 +1,6 @@ use std::future::Future; use std::sync::Arc; -#[cfg(not(feature = "tracing"))] -use log; #[cfg(feature = "tracing")] use tracing as log; diff --git a/riven/tests/tests_euw.rs b/riven/tests/tests_euw.rs index 4329f12..2dcdd0b 100644 --- a/riven/tests/tests_euw.rs +++ b/riven/tests/tests_euw.rs @@ -18,7 +18,7 @@ async_tests! { let sum = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "ma5tery"); let sum = sum.await.map_err(|e| e.to_string())?.ok_or_else(|| "Failed to get summoner".to_owned())?; - let p = RIOT_API.champion_mastery_v4().get_champion_mastery_score(ROUTE, &*sum.id); + let p = RIOT_API.champion_mastery_v4().get_champion_mastery_score(ROUTE, &sum.id); let s = p.await.map_err(|e| e.to_string())?; rassert!((969..=1000).contains(&s), "Unexpected ma5tery score: {}.", s); Ok(()) @@ -27,7 +27,7 @@ async_tests! { let sum = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "ma5tery"); let sum = sum.await.map_err(|e| e.to_string())?.ok_or_else(|| "Failed to get summoner".to_owned())?; - let p = RIOT_API.champion_mastery_v4().get_all_champion_masteries(ROUTE, &*sum.id); + let p = RIOT_API.champion_mastery_v4().get_all_champion_masteries(ROUTE, &sum.id); let s = p.await.map_err(|e| e.to_string())?; rassert!(s.len() >= 142, "Expected masteries: {}.", s.len()); Ok(()) diff --git a/riven/tests/tests_euw_tft.rs b/riven/tests/tests_euw_tft.rs index 4ca2578..464fb66 100644 --- a/riven/tests/tests_euw_tft.rs +++ b/riven/tests/tests_euw_tft.rs @@ -53,13 +53,13 @@ async_tests! { tft_combo: async { let top_players = RIOT_API.tft_league_v1().get_top_rated_ladder(ROUTE, QueueType::RANKED_TFT_TURBO); let top_players = top_players.await.map_err(|e| e.to_string())?; - rassert!(0 < top_players.len()); + rassert!(!top_players.is_empty()); let top_player_entry = &top_players[0]; - let top_player = RIOT_API.tft_summoner_v1().get_by_summoner_id(ROUTE, &*top_player_entry.summoner_id); + let top_player = RIOT_API.tft_summoner_v1().get_by_summoner_id(ROUTE, &top_player_entry.summoner_id); let top_player = top_player.await.map_err(|e| e.to_string())?; println!("Top player is {} with `puuid` {}.", top_player.name, top_player.puuid); let match_ids = RIOT_API.tft_match_v1().get_match_ids_by_puuid( - ROUTE.to_regional(), &*top_player.puuid, Some(10), None, None, None); + ROUTE.to_regional(), &top_player.puuid, Some(10), None, None, None); let match_ids = match_ids.await.map_err(|e| e.to_string())?; tft_match_v1_get(ROUTE.to_regional(), &*match_ids).await?; Ok(()) diff --git a/riven/tests/tests_la1.rs b/riven/tests/tests_la1.rs index b56e8fd..0b146b4 100644 --- a/riven/tests/tests_la1.rs +++ b/riven/tests/tests_la1.rs @@ -40,7 +40,7 @@ async_tests! { // Spot check 10% for `player-data`. for entry in leaderboard.iter().step_by(10) { - let _player_data = RIOT_API.lol_challenges_v1().get_player_data(ROUTE, &*entry.puuid) + let _player_data = RIOT_API.lol_challenges_v1().get_player_data(ROUTE, &entry.puuid) .await.map_err(|e| format!("Failed to get player data PUUID {}: {}", entry.puuid, e))?; } diff --git a/riven/tests/tests_na.rs b/riven/tests/tests_na.rs index 25cdff3..dd976a6 100644 --- a/riven/tests/tests_na.rs +++ b/riven/tests/tests_na.rs @@ -58,10 +58,10 @@ async_tests! { // summoner must have double-up rank. league_getforsummoner_tftbug: async { // TODO(mingwei): get summoner from leaderboard to avoid updating this all the time. - const SUMMONER_NAME: &'static str = "Vincentscc"; + const SUMMONER_NAME: &str = "Vincentscc"; let summoner_fut = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, SUMMONER_NAME); let summoner = summoner_fut.await.map_err(|e| e.to_string())?.ok_or_else(|| format!("Failed to get \"{}\"", SUMMONER_NAME))?; - let league_fut = RIOT_API.league_v4().get_league_entries_for_summoner(ROUTE, &*summoner.id); + let league_fut = RIOT_API.league_v4().get_league_entries_for_summoner(ROUTE, &summoner.id); let leagues = league_fut.await.map_err(|e| e.to_string())?; let tft_league = leagues.iter().find(|league| QueueType::RANKED_TFT_DOUBLE_UP == league.queue_type); rassert!(tft_league.is_some()); diff --git a/riven/tests/testutils.rs b/riven/tests/testutils.rs index 5d58fe1..c703c5e 100644 --- a/riven/tests/testutils.rs +++ b/riven/tests/testutils.rs @@ -23,7 +23,7 @@ pub async fn league_v4_match_v5_latest_combo(route: PlatformRoute) -> Result<(), .get_challenger_league(route, QueueType::RANKED_SOLO_5x5); let challenger_league = challenger_future.await.map_err(|e| e.to_string())?; - if &QueueType::RANKED_SOLO_5x5 != &challenger_league.queue { + if QueueType::RANKED_SOLO_5x5 != challenger_league.queue { return Err(format!("Unexpected `queue`: {}", challenger_league.queue)); } if challenger_league.entries.is_empty() { @@ -42,7 +42,7 @@ pub async fn league_v4_match_v5_latest_combo(route: PlatformRoute) -> Result<(), let match_ids_future = RIOT_API.match_v5().get_match_ids_by_puuid( route.to_regional(), - &*summoner_info.puuid, + &summoner_info.puuid, Some(5), None, None,