From dbfa336887043666dbb9b0376ead773c1403a712 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 23 Jul 2023 21:44:37 -0700 Subject: [PATCH] Run nightly `cargo fmt` for `let-else` syntax --- crates/valence_advancement/src/lib.rs | 4 ++- crates/valence_anvil/src/lib.rs | 2 +- crates/valence_anvil/src/parse_chunk.rs | 32 ++++++++++++------------ crates/valence_client/src/lib.rs | 9 ++++--- crates/valence_core_macros/src/packet.rs | 5 +++- crates/valence_instance/src/instance.rs | 12 +++++++-- crates/valence_inventory/src/lib.rs | 18 ++++++------- crates/valence_inventory/src/validate.rs | 7 +++--- crates/valence_nbt/src/snbt.rs | 4 ++- crates/valence_registry/src/codec.rs | 6 ++--- examples/advancement.rs | 12 +++++++-- examples/block_entities.rs | 4 +-- examples/combat.rs | 5 ++-- examples/entity_hitbox.rs | 4 ++- 14 files changed, 76 insertions(+), 48 deletions(-) diff --git a/crates/valence_advancement/src/lib.rs b/crates/valence_advancement/src/lib.rs index 74cf91db4..755b07487 100644 --- a/crates/valence_advancement/src/lib.rs +++ b/crates/valence_advancement/src/lib.rs @@ -132,7 +132,9 @@ impl<'w, 's> UpdateAdvancementCachedBytesQuery<'w, 's> { if let Some(a_children) = a_children { for a_child in a_children.iter() { - let Ok(c_identifier) = criteria_query.get(*a_child) else { continue; }; + let Ok(c_identifier) = criteria_query.get(*a_child) else { + continue; + }; pkt.criteria.push((c_identifier.0.borrowed(), ())); } } diff --git a/crates/valence_anvil/src/lib.rs b/crates/valence_anvil/src/lib.rs index 7695c166d..9dbb8e7c0 100644 --- a/crates/valence_anvil/src/lib.rs +++ b/crates/valence_anvil/src/lib.rs @@ -326,7 +326,7 @@ fn update_client_views( if loc != &*old_loc || view != old_view || old_loc.is_added() { let Ok((inst, mut anvil)) = instances.get_mut(loc.0) else { - continue + continue; }; let queue_pos = |pos| { diff --git a/crates/valence_anvil/src/parse_chunk.rs b/crates/valence_anvil/src/parse_chunk.rs index 9b7c1e35b..a1bf3f028 100644 --- a/crates/valence_anvil/src/parse_chunk.rs +++ b/crates/valence_anvil/src/parse_chunk.rs @@ -69,7 +69,7 @@ pub(crate) fn parse_chunk( biome_map: &BTreeMap, BiomeId>, // TODO: replace with biome registry arg. ) -> Result { let Some(Value::List(List::Compound(sections))) = nbt.remove("sections") else { - return Err(ParseChunkError::MissingSections) + return Err(ParseChunkError::MissingSections); }; if sections.is_empty() { @@ -96,7 +96,7 @@ pub(crate) fn parse_chunk( for mut section in sections { let Some(Value::Byte(sect_y)) = section.remove("Y") else { - return Err(ParseChunkError::MissingSectionY) + return Err(ParseChunkError::MissingSectionY); }; let sect_y = (sect_y as i32 - min_sect_y) as u32; @@ -106,11 +106,11 @@ pub(crate) fn parse_chunk( } let Some(Value::Compound(mut block_states)) = section.remove("block_states") else { - return Err(ParseChunkError::MissingBlockStates) + return Err(ParseChunkError::MissingBlockStates); }; let Some(Value::List(List::Compound(palette))) = block_states.remove("palette") else { - return Err(ParseChunkError::MissingBlockPalette) + return Err(ParseChunkError::MissingBlockPalette); }; if !(1..BLOCKS_PER_SECTION).contains(&palette.len()) { @@ -121,11 +121,11 @@ pub(crate) fn parse_chunk( for mut block in palette { let Some(Value::String(name)) = block.remove("Name") else { - return Err(ParseChunkError::MissingBlockName) + return Err(ParseChunkError::MissingBlockName); }; let Some(block_kind) = BlockKind::from_str(ident_path(&name)) else { - return Err(ParseChunkError::UnknownBlockName(name)) + return Err(ParseChunkError::UnknownBlockName(name)); }; let mut state = block_kind.to_state(); @@ -133,15 +133,15 @@ pub(crate) fn parse_chunk( if let Some(Value::Compound(properties)) = block.remove("Properties") { for (key, value) in properties { let Value::String(value) = value else { - return Err(ParseChunkError::BadPropValueType) + return Err(ParseChunkError::BadPropValueType); }; let Some(prop_name) = PropName::from_str(&key) else { - return Err(ParseChunkError::UnknownPropName(key)) + return Err(ParseChunkError::UnknownPropName(key)); }; let Some(prop_value) = PropValue::from_str(&value) else { - return Err(ParseChunkError::UnknownPropValue(value)) + return Err(ParseChunkError::UnknownPropValue(value)); }; state = state.set(prop_name, prop_value); @@ -157,7 +157,7 @@ pub(crate) fn parse_chunk( debug_assert!(converted_block_palette.len() > 1); let Some(Value::LongArray(data)) = block_states.remove("data") else { - return Err(ParseChunkError::MissingBlockStateData) + return Err(ParseChunkError::MissingBlockStateData); }; let bits_per_idx = bit_width(converted_block_palette.len() - 1).max(4); @@ -181,7 +181,7 @@ pub(crate) fn parse_chunk( let idx = (u64 >> (bits_per_idx * j)) & mask; let Some(block) = converted_block_palette.get(idx as usize).cloned() else { - return Err(ParseChunkError::BadBlockPaletteIndex) + return Err(ParseChunkError::BadBlockPaletteIndex); }; let x = i % 16; @@ -196,11 +196,11 @@ pub(crate) fn parse_chunk( } let Some(Value::Compound(biomes)) = section.get("biomes") else { - return Err(ParseChunkError::MissingBiomes) + return Err(ParseChunkError::MissingBiomes); }; let Some(Value::List(List::String(palette))) = biomes.get("palette") else { - return Err(ParseChunkError::MissingBiomePalette) + return Err(ParseChunkError::MissingBiomePalette); }; if !(1..BIOMES_PER_SECTION).contains(&palette.len()) { @@ -211,7 +211,7 @@ pub(crate) fn parse_chunk( for biome_name in palette { let Ok(ident) = Ident::>::new(biome_name) else { - return Err(ParseChunkError::BadBiomeName) + return Err(ParseChunkError::BadBiomeName); }; converted_biome_palette @@ -224,7 +224,7 @@ pub(crate) fn parse_chunk( debug_assert!(converted_biome_palette.len() > 1); let Some(Value::LongArray(data)) = biomes.get("data") else { - return Err(ParseChunkError::MissingBiomeData) + return Err(ParseChunkError::MissingBiomeData); }; let bits_per_idx = bit_width(converted_biome_palette.len() - 1); @@ -248,7 +248,7 @@ pub(crate) fn parse_chunk( let idx = (u64 >> (bits_per_idx * j)) & mask; let Some(biome) = converted_biome_palette.get(idx as usize).cloned() else { - return Err(ParseChunkError::BadBiomePaletteIndex) + return Err(ParseChunkError::BadBiomePaletteIndex); }; let x = i % 4; diff --git a/crates/valence_client/src/lib.rs b/crates/valence_client/src/lib.rs index a6b6fc678..9587a0b1b 100644 --- a/crates/valence_client/src/lib.rs +++ b/crates/valence_client/src/lib.rs @@ -688,9 +688,12 @@ fn initial_join( ) { for mut q in &mut clients { let Ok(instance) = instances.get(q.loc.0) else { - warn!("client {:?} joined nonexistent instance {:?}", q.entity, q.loc.0); + warn!( + "client {:?} joined nonexistent instance {:?}", + q.entity, q.loc.0 + ); commands.entity(q.entity).remove::(); - continue + continue; }; let dimension_names: Vec>> = codec @@ -766,7 +769,7 @@ fn respawn( let Ok(instance) = instances.get(loc.0) else { warn!("Client respawned in nonexistent instance."); - continue + continue; }; let dimension_name = instance.dimension_type_name(); diff --git a/crates/valence_core_macros/src/packet.rs b/crates/valence_core_macros/src/packet.rs index 9e9a1e942..f1eda6a18 100644 --- a/crates/valence_core_macros/src/packet.rs +++ b/crates/valence_core_macros/src/packet.rs @@ -13,7 +13,10 @@ pub(super) fn derive_packet(item: TokenStream) -> Result { }; let Some(packet_id) = packet_attr.id else { - return Err(Error::new(packet_attr.span, "missing `id = ...` value from packet attribute")); + return Err(Error::new( + packet_attr.span, + "missing `id = ...` value from packet attribute", + )); }; add_trait_bounds(&mut input.generics, quote!(::std::fmt::Debug)); diff --git a/crates/valence_instance/src/instance.rs b/crates/valence_instance/src/instance.rs index e05bc0adb..174849f92 100644 --- a/crates/valence_instance/src/instance.rs +++ b/crates/valence_instance/src/instance.rs @@ -202,7 +202,11 @@ impl Instance { #[inline] fn chunk_and_offsets(&self, pos: BlockPos) -> Option<(&LoadedChunk, u32, u32, u32)> { - let Some(y) = pos.y.checked_sub(self.info.min_y).and_then(|y| y.try_into().ok()) else { + let Some(y) = pos + .y + .checked_sub(self.info.min_y) + .and_then(|y| y.try_into().ok()) + else { return None; }; @@ -225,7 +229,11 @@ impl Instance { &mut self, pos: BlockPos, ) -> Option<(&mut LoadedChunk, u32, u32, u32)> { - let Some(y) = pos.y.checked_sub(self.info.min_y).and_then(|y| y.try_into().ok()) else { + let Some(y) = pos + .y + .checked_sub(self.info.min_y) + .and_then(|y| y.try_into().ok()) + else { return None; }; diff --git a/crates/valence_inventory/src/lib.rs b/crates/valence_inventory/src/lib.rs index 1739e759f..cf7f58247 100644 --- a/crates/valence_inventory/src/lib.rs +++ b/crates/valence_inventory/src/lib.rs @@ -777,16 +777,12 @@ fn handle_click_slot( for packet in packets.iter() { let Some(pkt) = packet.decode::() else { // Not the packet we're looking for. - continue + continue; }; - let Ok(( - mut client, - mut client_inv, - mut inv_state, - open_inventory, - mut cursor_item - )) = clients.get_mut(packet.client) else { + let Ok((mut client, mut client_inv, mut inv_state, open_inventory, mut cursor_item)) = + clients.get_mut(packet.client) + else { // The client does not exist, ignore. continue; }; @@ -1117,8 +1113,10 @@ fn handle_creative_inventory_action( ) { for packet in packets.iter() { if let Some(pkt) = packet.decode::() { - let Ok((mut client, mut inventory, mut inv_state, game_mode)) = clients.get_mut(packet.client) else { - continue + let Ok((mut client, mut inventory, mut inv_state, game_mode)) = + clients.get_mut(packet.client) + else { + continue; }; if *game_mode != GameMode::Creative { diff --git a/crates/valence_inventory/src/validate.rs b/crates/valence_inventory/src/validate.rs index ee14d3bc9..d07f17b26 100644 --- a/crates/valence_inventory/src/validate.rs +++ b/crates/valence_inventory/src/validate.rs @@ -206,9 +206,10 @@ pub(super) fn validate_click_slot_packet( .iter() .filter_map(|s| s.item.as_ref()) .next() - .map(|s| s.item) else { - bail!("shift click must move an item"); - }; + .map(|s| s.item) + else { + bail!("shift click must move an item"); + }; let Some(old_slot_kind) = window.slot(packet.slot_idx as u16).map(|s| s.item) else { bail!("shift click must move an item"); diff --git a/crates/valence_nbt/src/snbt.rs b/crates/valence_nbt/src/snbt.rs index e66449983..d92125ec1 100644 --- a/crates/valence_nbt/src/snbt.rs +++ b/crates/valence_nbt/src/snbt.rs @@ -642,7 +642,9 @@ mod tests { *more.get("larr").unwrap().as_long_array().unwrap(), vec![1, 2, 3] ); - let List::String(list) = cpd.get("empty").unwrap().as_list().unwrap() else { panic!() }; + let List::String(list) = cpd.get("empty").unwrap().as_list().unwrap() else { + panic!() + }; assert_eq!(list[0], "Bibabo"); assert_eq!( from_snbt_str("\"\\n\"").unwrap_err().error_type, diff --git a/crates/valence_registry/src/codec.rs b/crates/valence_registry/src/codec.rs index c53da1e4b..2c570bd94 100644 --- a/crates/valence_registry/src/codec.rs +++ b/crates/valence_registry/src/codec.rs @@ -64,7 +64,7 @@ impl Default for RegistryCodec { let Value::Compound(mut outer) = v else { error!("registry {reg_name} is not a compound"); - continue + continue; }; let values = match outer.remove("value") { @@ -79,7 +79,7 @@ impl Default for RegistryCodec { for mut value in values { let Some(Value::String(name)) = value.remove("name") else { error!("missing \"name\" string in value for {reg_name}"); - continue + continue; }; let name = match Ident::new(name) { @@ -92,7 +92,7 @@ impl Default for RegistryCodec { let Some(Value::Compound(element)) = value.remove("element") else { error!("missing \"element\" compound in value for {reg_name}"); - continue + continue; }; reg_values.push(RegistryValue { name, element }); diff --git a/examples/advancement.rs b/examples/advancement.rs index e0da009e7..8d8cf235a 100644 --- a/examples/advancement.rs +++ b/examples/advancement.rs @@ -237,7 +237,11 @@ fn sneak( if sneaking.state == SneakState::Stop { continue; } - let Ok((mut advancement_client_update, mut root_criteria_done)) = client.get_mut(sneaking.client) else { continue; }; + let Ok((mut advancement_client_update, mut root_criteria_done)) = + client.get_mut(sneaking.client) + else { + continue; + }; root_criteria_done.0 = !root_criteria_done.0; match root_criteria_done.0 { true => advancement_client_update.criteria_done(root_criteria), @@ -262,7 +266,11 @@ fn tab_change( let root2_criteria = root2_criteria.single(); let root = root.single(); for tab_change in tab_change.iter() { - let Ok((mut advancement_client_update, mut tab_change_count)) = client.get_mut(tab_change.client) else { continue; }; + let Ok((mut advancement_client_update, mut tab_change_count)) = + client.get_mut(tab_change.client) + else { + continue; + }; if let Some(ref opened) = tab_change.opened_tab { if opened.as_str() == "custom:root2" { tab_change_count.0 += 1; diff --git a/examples/block_entities.rs b/examples/block_entities.rs index 87d5e71ec..e95d2cb22 100644 --- a/examples/block_entities.rs +++ b/examples/block_entities.rs @@ -88,7 +88,7 @@ fn event_handler( } in messages.iter() { let Ok((username, _, _)) = clients.get(*client) else { - continue + continue; }; let nbt = instance.block_entity_mut(SIGN_POS).unwrap(); @@ -106,7 +106,7 @@ fn event_handler( { if *hand == Hand::Main && *position == SKULL_POS { let Ok((_, properties, uuid)) = clients.get(*client) else { - continue + continue; }; let Some(textures) = properties.textures() else { diff --git a/examples/combat.rs b/examples/combat.rs index 9c4e271a1..99211d4f7 100644 --- a/examples/combat.rs +++ b/examples/combat.rs @@ -113,9 +113,10 @@ fn handle_combat_events( .. } in interact_entity.iter() { - let Ok([mut attacker, mut victim]) = clients.get_many_mut([attacker_client, victim_client]) else { + let Ok([mut attacker, mut victim]) = clients.get_many_mut([attacker_client, victim_client]) + else { // Victim or attacker does not exist, or the attacker is attacking itself. - continue + continue; }; if server.current_tick() - victim.state.last_attacked_tick < 10 { diff --git a/examples/entity_hitbox.rs b/examples/entity_hitbox.rs index d6c044334..2802da751 100644 --- a/examples/entity_hitbox.rs +++ b/examples/entity_hitbox.rs @@ -140,7 +140,9 @@ fn intersections(query: Query<(Entity, &Hitbox)>, mut name_query: Query<&mut ent } for (entity, value) in intersections { - let Ok(mut name) = name_query.get_mut(entity) else { continue; }; + let Ok(mut name) = name_query.get_mut(entity) else { + continue; + }; name.0 = Some(format!("{value}").into()); } }