Skip to content

Commit

Permalink
Run nightly cargo fmt for let-else syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
rj00a committed Jul 24, 2023
1 parent 9c599dd commit dbfa336
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 48 deletions.
4 changes: 3 additions & 1 deletion crates/valence_advancement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(), ()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
32 changes: 16 additions & 16 deletions crates/valence_anvil/src/parse_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub(crate) fn parse_chunk(
biome_map: &BTreeMap<Ident<String>, BiomeId>, // TODO: replace with biome registry arg.
) -> Result<UnloadedChunk, ParseChunkError> {
let Some(Value::List(List::Compound(sections))) = nbt.remove("sections") else {
return Err(ParseChunkError::MissingSections)
return Err(ParseChunkError::MissingSections);
};

if sections.is_empty() {
Expand All @@ -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;
Expand All @@ -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()) {
Expand All @@ -121,27 +121,27 @@ 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();

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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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()) {
Expand All @@ -211,7 +211,7 @@ pub(crate) fn parse_chunk(

for biome_name in palette {
let Ok(ident) = Ident::<Cow<str>>::new(biome_name) else {
return Err(ParseChunkError::BadBiomeName)
return Err(ParseChunkError::BadBiomeName);
};

converted_biome_palette
Expand All @@ -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);
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions crates/valence_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Client>();
continue
continue;
};

let dimension_names: Vec<Ident<Cow<str>>> = codec
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion crates/valence_core_macros/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub(super) fn derive_packet(item: TokenStream) -> Result<TokenStream> {
};

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));
Expand Down
12 changes: 10 additions & 2 deletions crates/valence_instance/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
};

Expand Down
18 changes: 8 additions & 10 deletions crates/valence_inventory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,16 +777,12 @@ fn handle_click_slot(
for packet in packets.iter() {
let Some(pkt) = packet.decode::<ClickSlotC2s>() 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;
};
Expand Down Expand Up @@ -1117,8 +1113,10 @@ fn handle_creative_inventory_action(
) {
for packet in packets.iter() {
if let Some(pkt) = packet.decode::<CreativeInventoryActionC2s>() {
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 {
Expand Down
7 changes: 4 additions & 3 deletions crates/valence_inventory/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion crates/valence_nbt/src/snbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/valence_registry/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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) {
Expand All @@ -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 });
Expand Down
12 changes: 10 additions & 2 deletions examples/advancement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/block_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions examples/combat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion examples/entity_hitbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit dbfa336

Please sign in to comment.