From 846df3a18a4840c264e1344e186e48cfc57d339a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Fri, 21 May 2021 14:34:34 +0200 Subject: [PATCH] --all-targets does not run targets that needs some features which are not provided. --all-features is NOT possible as we have some features which are conflicting. The only possibility is to manually add the features we need to check in CI to the clippy query --- .gitlab/CI/check.gitlab-ci.yml | 2 +- client/examples/chat-cli/main.rs | 11 ++-- client/src/bin/bot/main.rs | 25 +++----- client/src/bin/bot/tui.rs | 17 ++---- common/src/bin/csv_export/main.rs | 2 - common/src/bin/csv_import/main.rs | 98 +++++++++++++------------------ 6 files changed, 63 insertions(+), 92 deletions(-) diff --git a/.gitlab/CI/check.gitlab-ci.yml b/.gitlab/CI/check.gitlab-ci.yml index a26a4caf8e..8f465e1be7 100644 --- a/.gitlab/CI/check.gitlab-ci.yml +++ b/.gitlab/CI/check.gitlab-ci.yml @@ -6,7 +6,7 @@ code-quality: script: - ln -s /dockercache/target target - rm -r target/debug/incremental/* || echo "all good" # TMP FIX FOR 2021-03-22-nightly - - cargo clippy --all-targets --locked -- -D warnings + - cargo clippy --all-targets --locked --features="bin_csv,bin_bot" -- -D warnings - cargo fmt --all -- --check security: diff --git a/client/examples/chat-cli/main.rs b/client/examples/chat-cli/main.rs index 2d7f7f210e..e23f1bb8c5 100644 --- a/client/examples/chat-cli/main.rs +++ b/client/examples/chat-cli/main.rs @@ -45,15 +45,14 @@ fn main() { let runtime = Arc::new(Runtime::new().unwrap()); let runtime2 = Arc::clone(&runtime); + let addr = ConnectionArgs::Tcp { + prefer_ipv6: false, + hostname: server_addr, + }; // Create a client. let mut client = runtime - .block_on(async { - let addr = ConnectionArgs::resolve(&server_addr, false) - .await - .expect("dns resolve failed"); - Client::new(addr, None, runtime2, &mut None).await - }) + .block_on(Client::new(addr, runtime2, &mut None)) .expect("Failed to create client instance"); println!("Server info: {:?}", client.server_info()); diff --git a/client/src/bin/bot/main.rs b/client/src/bin/bot/main.rs index 7cb0aaab38..162de7658f 100644 --- a/client/src/bin/bot/main.rs +++ b/client/src/bin/bot/main.rs @@ -1,5 +1,3 @@ -#![feature(str_split_once)] - #[macro_use] extern crate serde; use authc::AuthClient; @@ -54,15 +52,13 @@ pub struct BotClient { pub fn make_client(runtime: &Arc, server: &str) -> Client { let runtime2 = Arc::clone(&runtime); - let view_distance: Option = None; - runtime.block_on(async { - let connection_args = ConnectionArgs::resolve(server, false) - .await - .expect("DNS resolution failed"); - Client::new(connection_args, view_distance, runtime2, &mut None) - .await - .expect("Failed to connect to server") - }) + let addr = ConnectionArgs::Tcp { + prefer_ipv6: false, + hostname: server.to_owned(), + }; + runtime + .block_on(Client::new(addr, runtime2, &mut None)) + .expect("Failed to connect to server") } impl BotClient { @@ -84,7 +80,7 @@ impl BotClient { for (username, client) in self.bot_clients.iter_mut() { //trace!("cl {:?}: {:?}", username, client.character_list()); trace!(?username, "tick"); - let msgs: Result, veloren_client::Error> = + let _msgs: Result, veloren_client::Error> = client.tick(comp::ControllerInputs::default(), self.clock.dt(), |_| {}); /*trace!( "msgs {:?}: {:?} {:?}", @@ -131,7 +127,7 @@ impl BotClient { .settings .bot_logins .iter() - .any(|x| &*x.username == &*username) + .any(|x| *x.username == *username) { continue; } @@ -216,9 +212,6 @@ impl BotClient { .cloned() .collect(); for cred in creds.iter() { - let runtime = Arc::clone(&self.runtime); - - let server = self.settings.server.clone(); let client = match self.bot_clients.get_mut(&cred.username) { Some(c) => c, None => { diff --git a/client/src/bin/bot/tui.rs b/client/src/bin/bot/tui.rs index bb55168930..af3014da96 100644 --- a/client/src/bin/bot/tui.rs +++ b/client/src/bin/bot/tui.rs @@ -27,16 +27,11 @@ impl Tui { let handle = thread::spawn(move || { thread::sleep(Duration::from_millis(20)); let mut readline = rustyline::Editor::<()>::new(); - loop { - match readline.readline("\n\nbotclient> ") { - Ok(cmd) => { - let keep_going = Self::process_command(&cmd, &mut commands_s); - readline.add_history_entry(cmd); - if !keep_going { - break; - } - }, - Err(_) => break, + while let Ok(cmd) = readline.readline("\n\nbotclient> ") { + let keep_going = Self::process_command(&cmd, &mut commands_s); + readline.add_history_entry(cmd); + if !keep_going { + break; } } }); @@ -69,7 +64,7 @@ impl Tui { .about("Join the world with some random character") .args(&[Arg::with_name("prefix").required(true)]), ) - .get_matches_from_safe(cmd.split(" ")); + .get_matches_from_safe(cmd.split(' ')); use clap::ErrorKind::*; match matches { Ok(matches) => { diff --git a/common/src/bin/csv_export/main.rs b/common/src/bin/csv_export/main.rs index 7c4d5bbe9f..c21beba187 100644 --- a/common/src/bin/csv_export/main.rs +++ b/common/src/bin/csv_export/main.rs @@ -121,7 +121,6 @@ fn weapon_stats() -> Result<(), Box> { let poise_strength = tool.base_poise_strength(&msm, &[]).to_string(); let speed = tool.base_speed(&msm, &[]).to_string(); let crit_chance = tool.base_crit_chance(&msm, &[]).to_string(); - let crit_mult = tool.base_crit_mult(&msm, &[]).to_string(); let equip_time = tool.equip_time(&msm, &[]).as_secs_f32().to_string(); let kind = get_tool_kind(&tool.kind); let hands = get_tool_hands(&tool); @@ -136,7 +135,6 @@ fn weapon_stats() -> Result<(), Box> { &poise_strength, &speed, &crit_chance, - &crit_mult, &equip_time, item.description(), ])?; diff --git a/common/src/bin/csv_import/main.rs b/common/src/bin/csv_import/main.rs index fc5e207c68..5e594e1421 100644 --- a/common/src/bin/csv_import/main.rs +++ b/common/src/bin/csv_import/main.rs @@ -1,4 +1,5 @@ #![deny(clippy::clone_on_ref_ptr)] +#![allow(clippy::expect_fun_call)] use hashbrown::HashMap; use ron::ser::{to_string_pretty, PrettyConfig}; @@ -68,11 +69,8 @@ fn armor_stats() -> Result<(), Box> { { match item.kind() { comp::item::ItemKind::Armor(armor) => { - match armor.kind { - ArmorKind::Bag(_) => { - continue; - }, - _ => {}, + if let ArmorKind::Bag(_) = armor.kind { + continue; } if let Ok(ref record) = record { @@ -217,7 +215,7 @@ fn armor_stats() -> Result<(), Box> { .with_enumerate_arrays(true); let mut path = ASSETS_PATH.clone(); - for part in item.item_definition_id().split(".") { + for part in item.item_definition_id().split('.') { path.push(part); } path.set_extension("ron"); @@ -329,15 +327,6 @@ fn weapon_stats() -> Result<(), Box> { .parse() .expect(&format!("Not a f32? {:?}", item.item_definition_id())); - let crit_mult: f32 = record - .get(headers["Crit Mult"]) - .expect(&format!( - "Error unwrapping crit_mult for {:?}", - item.item_definition_id() - )) - .parse() - .expect(&format!("Not a f32? {:?}", item.item_definition_id())); - let tool = comp::item::tool::Tool::new( kind, hands, @@ -346,7 +335,6 @@ fn weapon_stats() -> Result<(), Box> { poise_strength, speed, crit_chance, - crit_mult, ); let quality = if let Some(quality_raw) = record.get(headers["Quality"]) @@ -396,7 +384,7 @@ fn weapon_stats() -> Result<(), Box> { .with_enumerate_arrays(true); let mut path = ASSETS_PATH.clone(); - for part in item.item_definition_id().split(".") { + for part in item.item_definition_id().split('.') { path.push(part); } path.set_extension("ron"); @@ -432,41 +420,39 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { let mut items = Vec::<(f32, LootSpec)>::new(); - for record in rdr.records() { - if let Ok(ref record) = record { - let item = match record.get(headers["Kind"]).expect("No loot specifier") { - "Item" => { - if let (Some(Ok(lower)), Some(Ok(upper))) = ( - record.get(headers["Lower Amount"]).map(|a| a.parse()), - record.get(headers["Upper Amount"]).map(|a| a.parse()), - ) { - LootSpec::ItemQuantity( - record.get(headers["Item"]).expect("No item").to_string(), - lower, - upper, - ) - } else { - LootSpec::Item(record.get(headers["Item"]).expect("No item").to_string()) - } - }, - "LootTable" => LootSpec::LootTable( - record - .get(headers["Item"]) - .expect("No loot table") - .to_string(), - ), - a => panic!( - "Loot specifier kind must be either \"Item\" or \"LootTable\"\n{}", - a - ), - }; - let chance: f32 = record - .get(headers["Relative Chance"]) - .expect("No chance for item in entry") - .parse() - .expect("Not an f32 for chance in entry"); - items.push((chance, item)); - } + for ref record in rdr.records().flatten() { + let item = match record.get(headers["Kind"]).expect("No loot specifier") { + "Item" => { + if let (Some(Ok(lower)), Some(Ok(upper))) = ( + record.get(headers["Lower Amount"]).map(|a| a.parse()), + record.get(headers["Upper Amount"]).map(|a| a.parse()), + ) { + LootSpec::ItemQuantity( + record.get(headers["Item"]).expect("No item").to_string(), + lower, + upper, + ) + } else { + LootSpec::Item(record.get(headers["Item"]).expect("No item").to_string()) + } + }, + "LootTable" => LootSpec::LootTable( + record + .get(headers["Item"]) + .expect("No loot table") + .to_string(), + ), + a => panic!( + "Loot specifier kind must be either \"Item\" or \"LootTable\"\n{}", + a + ), + }; + let chance: f32 = record + .get(headers["Relative Chance"]) + .expect("No chance for item in entry") + .parse() + .expect("Not an f32 for chance in entry"); + items.push((chance, item)); } let pretty_config = PrettyConfig::new() @@ -476,7 +462,7 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { let mut path = ASSETS_PATH.clone(); path.push("common"); path.push("loot_tables"); - for part in loot_table.split(".") { + for part in loot_table.split('.') { path.push(part); } path.set_extension("ron"); @@ -514,7 +500,7 @@ Would you like to continue? (y/n) > ", ) .to_lowercase() - == "y".to_string() + == *"y" { if let Err(e) = armor_stats() { println!("Error: {}\n", e) @@ -544,7 +530,7 @@ Would you like to continue? (y/n) > ", ) .to_lowercase() - == "y".to_string() + == *"y" { if let Err(e) = weapon_stats() { println!("Error: {}\n", e) @@ -578,7 +564,7 @@ Would you like to continue? (y/n) > ", ) .to_lowercase() - == "y".to_string() + == *"y" { if let Err(e) = loot_table(&loot_table_name) { println!("Error: {}\n", e)