Merge branch 'xvar/clippy-fixes-collapsible_if' into 'master'

Fixed suppressed clippy warnings for #587 - collapsible_if

See merge request veloren/veloren!1064
This commit is contained in:
Imbris 2020-06-12 20:27:13 +00:00
commit 38ec0fde63
17 changed files with 375 additions and 427 deletions

View File

@ -79,7 +79,6 @@ fn nth_word(line: &str, n: usize) -> Option<usize> {
}
#[allow(clippy::chars_next_cmp)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
pub fn complete(line: &str, client: &Client) -> Vec<String> {
let word = if line.chars().last().map_or(true, char::is_whitespace) {
""
@ -93,8 +92,7 @@ pub fn complete(line: &str, client: &Client) -> Vec<String> {
if i == 0 {
// Completing chat command name
complete_command(word)
} else {
if let Ok(cmd) = cmd.parse::<ChatCommand>() {
} else if let Ok(cmd) = cmd.parse::<ChatCommand>() {
if let Some(arg) = cmd.data().args.get(i - 1) {
// Complete ith argument
arg.complete(word, &client)
@ -116,7 +114,6 @@ pub fn complete(line: &str, client: &Client) -> Vec<String> {
// Completing for unknown chat command
complete_player(word, &client)
}
}
} else {
// Not completing a command
complete_player(word, &client)

View File

@ -702,7 +702,7 @@ impl Client {
}
/// Handle new server messages.
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
fn handle_new_messages(&mut self) -> Result<Vec<Event>, Error> {
let mut frontend_events = Vec::new();
@ -713,14 +713,14 @@ impl Client {
let duration_since_last_pong = self.state.get_time() - self.last_server_pong;
// Dispatch a notification to the HUD warning they will be kicked in {n} seconds
if duration_since_last_pong >= SERVER_TIMEOUT_GRACE_PERIOD {
if self.state.get_time() - duration_since_last_pong > 0. {
if duration_since_last_pong >= SERVER_TIMEOUT_GRACE_PERIOD
&& self.state.get_time() - duration_since_last_pong > 0.
{
frontend_events.push(Event::DisconnectionNotification(
(self.state.get_time() - duration_since_last_pong).round() as u64,
));
}
}
}
let new_msgs = self.postbox.new_messages();

View File

@ -224,7 +224,6 @@ fn handle_goto(
}
}
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::option_map_unit_fn)] // TODO: Pending review in #587
fn handle_kill(
server: &mut Server,
@ -235,12 +234,10 @@ fn handle_kill(
) {
let reason = if client == target {
comp::HealthSource::Suicide
} else {
if let Some(uid) = server.state.read_storage::<Uid>().get(client) {
} else if let Some(uid) = server.state.read_storage::<Uid>().get(client) {
comp::HealthSource::Attack { by: *uid }
} else {
comp::HealthSource::Command
}
};
server
.state
@ -385,7 +382,6 @@ fn handle_alias(
}
}
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::identity_conversion)] // TODO: Pending review in #587
#[allow(clippy::useless_format)] // TODO: Pending review in #587
fn handle_tp(
@ -401,8 +397,7 @@ fn handle_tp(
.join()
.find(|(_, player)| player.alias == alias)
.map(|(entity, _)| entity)
} else {
if client != target {
} else if client != target {
Some(client)
} else {
server.notify_client(
@ -414,7 +409,6 @@ fn handle_tp(
ServerMsg::private(String::from(action.help_string())),
);
return;
}
};
if let Some(_pos) = server.state.read_component_cloned::<comp::Pos>(target) {
if let Some(player) = opt_player {

View File

@ -24,7 +24,6 @@ pub fn handle_damage(server: &Server, uid: Uid, change: HealthChange) {
}
}
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::option_map_unit_fn)] // TODO: Pending review in #587
pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSource) {
let state = server.state_mut();
@ -102,8 +101,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
.ecs()
.write_storage::<comp::CharacterState>()
.insert(entity, comp::CharacterState::default());
} else {
if state.ecs().read_storage::<comp::Agent>().contains(entity) {
} else if state.ecs().read_storage::<comp::Agent>().contains(entity) {
// Replace npc with loot
let _ = state
.ecs()
@ -307,9 +305,9 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
.write_storage::<comp::Controller>()
.remove(entity);
} else {
if let Err(err) = state.delete_entity_recorded(entity) {
error!("Failed to delete destroyed entity: {:?}", err);
}
let _ = state
.delete_entity_recorded(entity)
.map_err(|err| error!("Failed to delete destroyed entity: {:?}", err));
}
// TODO: Add Delete(time_left: Duration) component
@ -320,7 +318,6 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
}
*/
}
}
pub fn handle_land_on_ground(server: &Server, entity: EcsEntity, vel: Vec3<f32>) {
let state = &server.state;

View File

@ -30,7 +30,6 @@ pub fn snuff_lantern(storage: &mut WriteStorage<comp::LightEmitter>, entity: Ecs
}
#[allow(clippy::block_in_if_condition_stmt)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::let_and_return)] // TODO: Pending review in #587
pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::InventoryManip) {
let state = server.state_mut();
@ -95,14 +94,13 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
entity,
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::CollectFailed),
);
} else {
if block.is_collectible() && state.try_set_block(pos, Block::empty()).is_some()
} else if block.is_collectible()
&& state.try_set_block(pos, Block::empty()).is_some()
{
comp::Item::try_reclaim_from_block(block)
.map(|item| state.give_item(entity, item));
}
}
}
},
comp::InventoryManip::Use(slot) => {

View File

@ -129,7 +129,6 @@ impl CombatEventMapper {
}
}
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
fn map_event(
character_state: &CharacterState,
previous_state: &PreviousEntityState,
@ -151,25 +150,19 @@ impl CombatEventMapper {
CharacterAbilityType::from(character_state),
ToolCategory::from(data.kind),
);
} else {
if let Some(wield_event) = match (
} else if let Some(wield_event) = match (
previous_state.weapon_drawn,
character_state.is_dodge(),
Self::weapon_drawn(character_state),
) {
(false, false, true) => {
Some(SfxEvent::Wield(ToolCategory::from(data.kind)))
},
(true, false, false) => {
Some(SfxEvent::Unwield(ToolCategory::from(data.kind)))
},
(false, false, true) => Some(SfxEvent::Wield(ToolCategory::from(data.kind))),
(true, false, false) => Some(SfxEvent::Unwield(ToolCategory::from(data.kind))),
_ => None,
} {
return wield_event;
}
}
}
}
SfxEvent::Idle
}

View File

@ -146,7 +146,6 @@ impl<'a> Widget for Chat<'a> {
#[allow(clippy::unused_unit)] // TODO: Pending review in #587
fn style(&self) -> Self::Style { () }
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::redundant_clone)] // TODO: Pending review in #587
#[allow(clippy::single_match)] // TODO: Pending review in #587
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
@ -200,25 +199,21 @@ impl<'a> Widget for Chat<'a> {
state.update(|s| s.input.retain(|c| c != '\t'));
//tab_dir + 1
}
if !state.completions.is_empty() {
if tab_dir != 0 || state.completions_index.is_none() {
if !state.completions.is_empty() && (tab_dir != 0 || state.completions_index.is_none())
{
state.update(|s| {
let len = s.completions.len();
s.completions_index = Some(
(s.completions_index.unwrap_or(0) + (tab_dir + len as isize) as usize)
% len,
);
if let Some(replacement) = &s.completions.get(s.completions_index.unwrap())
{
let (completed, offset) =
do_tab_completion(cursor, &s.input, replacement);
force_cursor =
cursor_offset_to_index(offset, &completed, &ui, &self.fonts);
if let Some(replacement) = &s.completions.get(s.completions_index.unwrap()) {
let (completed, offset) = do_tab_completion(cursor, &s.input, replacement);
force_cursor = cursor_offset_to_index(offset, &completed, &ui, &self.fonts);
s.input = completed;
}
});
}
}
false
} else if let Some(cursor) = state.input.find('\t') {
// Begin tab completion
@ -236,11 +231,9 @@ impl<'a> Widget for Chat<'a> {
if s.history_pos < s.history.len() {
s.history_pos += 1;
}
} else {
if s.history_pos > 0 {
} else if s.history_pos > 0 {
s.history_pos -= 1;
}
}
if s.history_pos > 0 {
s.input = s.history.get(s.history_pos - 1).unwrap().to_owned();
force_cursor =
@ -368,8 +361,8 @@ impl<'a> Widget for Chat<'a> {
// Chat Arrow
// Check if already at bottom.
if !Self::scrolled_to_bottom(state, ui) {
if Button::image(self.imgs.chat_arrow)
if !Self::scrolled_to_bottom(state, ui)
&& Button::image(self.imgs.chat_arrow)
.w_h(20.0, 20.0)
.hover_image(self.imgs.chat_arrow_mo)
.press_image(self.imgs.chat_arrow_press)
@ -379,7 +372,6 @@ impl<'a> Widget for Chat<'a> {
{
ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]);
}
}
// We've started a new tab completion. Populate tab completion suggestions.
if request_tab_completions {

View File

@ -399,7 +399,6 @@ impl CharSelectionUi {
// TODO: Split this into multiple modules or functions.
#[allow(clippy::clone_on_copy)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::useless_let_if_seq)] // TODO: Pending review in #587
#[allow(clippy::unnecessary_operation)] // TODO: Pending review in #587
fn update_layout(&mut self, client: &mut Client) -> Vec<Event> {
@ -826,8 +825,8 @@ impl CharSelectionUi {
.image_color(color)
.set(self.ids.character_box_2, ui_widgets)
.was_clicked()
&& !character_limit_reached
{
if !character_limit_reached {
self.mode = Mode::Create {
name: "Character Name".to_string(),
body: humanoid::Body::random(),
@ -835,7 +834,6 @@ impl CharSelectionUi {
tool: Some(STARTER_SWORD),
};
}
}
// LOADING SCREEN HERE
if self.enter { /*stuff*/ };
@ -903,8 +901,7 @@ impl CharSelectionUi {
.set(self.ids.create_button, ui_widgets)
.was_clicked()
{}
} else {
if create_button
} else if create_button
.set(self.ids.create_button, ui_widgets)
.was_clicked()
{
@ -918,7 +915,6 @@ impl CharSelectionUi {
to_select = true;
}
}
// Character Name Input
Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97))
.mid_bottom_with_margin_on(ui_widgets.window, 20.0)

View File

@ -206,7 +206,7 @@ impl<'a, V: RectRasterableVol<Vox = Block> + ReadVol + Debug>
type Supplement = Aabb<i32>;
type TranslucentPipeline = FluidPipeline;
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)]
#[allow(clippy::many_single_char_names)]
#[allow(clippy::needless_range_loop)] // TODO: Pending review in #587
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587

View File

@ -46,7 +46,7 @@ gfx_defines! {
}
impl Vertex {
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)]
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>, ao: f32, bone_idx: u8) -> Self {
let norm_bits = if norm.x != 0.0 {
if norm.x < 0.0 { 0 } else { 1 }

View File

@ -45,7 +45,7 @@ gfx_defines! {
}
impl Vertex {
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)]
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>, ao: f32) -> Self {
let norm_bits = if norm.x != 0.0 {
if norm.x < 0.0 { 0 } else { 1 }

View File

@ -368,7 +368,6 @@ impl<'a> Widget for Tooltip<'a> {
fn style(&self) -> Self::Style { self.style.clone() }
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
fn update(self, args: widget::UpdateArgs<Self>) {
let widget::UpdateArgs {
id,
@ -440,14 +439,12 @@ impl<'a> Widget for Tooltip<'a> {
if !self.title_text.is_empty() {
desc.down_from(state.ids.title, V_PAD * 0.5 + title_space)
.align_left_of(state.ids.title)
} else {
if self.image.is_some() {
} else if self.image.is_some() {
desc.right_from(state.ids.image, H_PAD)
.align_top_of(state.ids.image)
} else {
desc.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
}
}
.set(state.ids.desc, ui);
}

View File

@ -9,7 +9,6 @@ use veloren_world::{
const W: usize = 1024;
const H: usize = 1024;
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::needless_update)] // TODO: Pending review in #587
#[allow(clippy::unused_io_amount)] // TODO: Pending review in #587
fn main() {

View File

@ -168,7 +168,6 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
type Index = Vec2<i32>;
type Sample = Option<ColumnSample<'a>>;
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::float_cmp)] // TODO: Pending review in #587
#[allow(clippy::if_same_then_else)] // TODO: Pending review in #587
#[allow(clippy::nonminimal_bool)] // TODO: Pending review in #587
@ -679,8 +678,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
let (_, dist, _, (river_t, _, downhill_river_chunk)) =
if let Some(dist) = max_border_river_dist {
dist
} else {
if lake_dist
} else if lake_dist
<= TerrainChunkSize::RECT_SIZE.x as f64 * 1.0
|| in_bounds
{
@ -692,8 +690,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
> alt_for_river,
Some(lake_dist as f32),
alt_for_river,
(downhill_water_alt
.max(river_chunk.water_alt)
(downhill_water_alt.max(river_chunk.water_alt)
- river_gouge),
alt_for_river,
river_scale_factor as f32
@ -708,7 +705,6 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
alt_for_river,
river_scale_factor as f32,
));
}
};
let lake_dist = dist.y;

View File

@ -687,7 +687,6 @@ fn get_max_slope(
/// Copyright 2003 by the American Geophysical Union
/// 10.1029/135GM09
#[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::many_single_char_names)]
#[allow(clippy::too_many_arguments)]
fn erode(
@ -1388,8 +1387,7 @@ fn erode(
// NOTE: If we want erosion to proceed underwater, use h_j here instead
// of wh_j.
new_h_i = wh_j;
} else {
if compute_stats && new_h_i > 0.0 {
} else if compute_stats && new_h_i > 0.0 {
let dxy = (uniform_idx_as_vec2(posi) - uniform_idx_as_vec2(posj))
.map(|e| e as f64);
let neighbor_distance = (neighbor_coef * dxy).magnitude();
@ -1401,7 +1399,6 @@ fn erode(
sumh += new_h_i;
sums += mag_slope;
}
}
} else {
new_h_i = old_elev_i;
let posj_stack = mstack_inv[posj];
@ -1628,8 +1625,7 @@ fn erode(
if compute_stats {
ncorr += 1;
}
} else {
if compute_stats && new_h_i > 0.0 {
} else if compute_stats && new_h_i > 0.0 {
let dz = (new_h_i - h_j).max(0.0);
let slope = dz / neighbor_distance;
sums += slope;
@ -1637,7 +1633,6 @@ fn erode(
sumh += new_h_i;
sumsed_land += sed;
}
}
if compute_stats {
ntherm += 1;
prodscrit_therm += max_slope.ln();

View File

@ -1821,7 +1821,6 @@ pub struct RegionInfo {
}
impl SimChunk {
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::if_same_then_else)] // TODO: Pending review in #587
fn generate(posi: usize, gen_ctx: &GenCtx, gen_cdf: &GenCdf) -> Self {
let pos = uniform_idx_as_vec2(posi);
@ -2012,8 +2011,7 @@ impl SimChunk {
} else {
ForestKind::Savannah
}
} else {
if humidity > CONFIG.jungle_hum {
} else if humidity > CONFIG.jungle_hum {
// Temperate climate with jungle humidity...
// https://en.wikipedia.org/wiki/Humid_subtropical_climates are often
// densely wooded and full of water. Semitropical rainforests, basically.
@ -2029,7 +2027,6 @@ impl SimChunk {
} else {
ForestKind::Savannah
}
}
} else {
// For now we don't take humidity into account for cold climates (but we really
// should!) except that we make sure we only have snow pines when there is snow.

View File

@ -481,7 +481,6 @@ impl Settlement {
}
}
#[allow(clippy::collapsible_if)] // TODO: Pending review in #587
#[allow(clippy::identity_op)] // TODO: Pending review in #587
#[allow(clippy::modulo_one)] // TODO: Pending review in #587
pub fn apply_to<'a>(
@ -645,15 +644,13 @@ impl Settlement {
})
.map(|kind| Block::new(kind, Rgb::white()));
}
} else {
if roll(0, 20) == 0 {
} else if roll(0, 20) == 0 {
surface_block =
Some(Block::new(BlockKind::ShortGrass, Rgb::white()));
} else if roll(1, 30) == 0 {
surface_block =
Some(Block::new(BlockKind::MediumGrass, Rgb::white()));
}
}
Some(if in_furrow { dirt } else { mound })
},