Skip to content

Commit

Permalink
Fix Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Jun 19, 2024
1 parent a1186d6 commit 3077e4a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 24 deletions.
12 changes: 3 additions & 9 deletions crates/controller/src/hud/minimap/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ struct CameraPoint<'w, 's> {
impl<'w, 's> CameraPoint<'w, 's> {
fn point(&self, ndc: Vec2) -> Option<Vec2> {
let ray = self.ray.ray(ndc);
let Some(intersection) = self.terrain.cast_ray_msl(&ray, f32::INFINITY) else {
return None;
};
let intersection = self.terrain.cast_ray_msl(&ray, f32::INFINITY)?;
let point = ray.origin + ray.dir * intersection.toi;
Some(self.ui_coords.flat_to_rel(point.to_flat()))
}
Expand Down Expand Up @@ -148,16 +146,12 @@ fn endpoints_to_line(start: Option<Vec2>, end: Option<Vec2>) -> Option<(Vec2, Ve
let aabb = Aabb::new(Point::new(0., 0.), Point::new(1., 1.));
if !aabb.contains_local_point(&start) {
let ray = Ray::new(start, end - start);
let Some(toi) = aabb.cast_local_ray(&ray, 1., false) else {
return None;
};
let toi = aabb.cast_local_ray(&ray, 1., false)?;
start = ray.origin + toi * ray.dir;
}
if !aabb.contains_local_point(&end) {
let ray = Ray::new(end, start - end);
let Some(toi) = aabb.cast_local_ray(&ray, 1., false) else {
return None;
};
let toi = aabb.cast_local_ray(&ray, 1., false)?;
end = ray.origin + toi * ray.dir;
}

Expand Down
4 changes: 2 additions & 2 deletions crates/lobby_model/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ mod tests {
"Password must have at least 6 characters."
);

user.password = "Long-enough-pwd".to_owned();
user.password = "Long-enough-pwd".to_string();
assert!(user.validate().is_ok());

user.user.username = "Indy ".to_owned();
user.user.username = "Indy ".to_string();
assert_eq!(
user.validate().err().unwrap().to_string(),
"Username starting or ending with whitespace is not allowed."
Expand Down
5 changes: 1 addition & 4 deletions crates/multiplayer/src/playermsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ impl EntityIdMapRes {
/// This should not be called unless the player leaves the multiplayer
/// game.
fn remove_player(&mut self, player: Player) -> Option<PlayerNetToLocal> {
let Some(map) = self.remote_to_local.remove(&player) else {
return None;
};

let map = self.remote_to_local.remove(&player)?;
for local in map.locals() {
self.local_to_remote.remove(&local).unwrap();
}
Expand Down
9 changes: 3 additions & 6 deletions crates/net/src/connection/databuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ impl DataBuf {
///
/// Panics if `buf` len is smaller than length of found data.
pub(super) fn get(&self, id: PackageId, buf: &mut [u8]) -> Option<usize> {
let Some(slot_index) = self.slot_index(id) else {
return None;
};
let slot_index = self.slot_index(id)?;

let front = self.slots.front().unwrap();
let slot = self.slots.get(slot_index).unwrap();
Expand Down Expand Up @@ -111,9 +109,8 @@ impl DataBuf {

/// Get index (withing slots deque) of the slot with ID `id`.
fn slot_index(&self, id: PackageId) -> Option<usize> {
let Some(&ordinal) = self.ordinals.get(&id) else {
return None;
};
let ordinal = self.ordinals.get(&id)?;

// Slots can't be empty since the ordinal was found.
let front = self.slots.front().unwrap();
Some(ordinal.wrapping_sub(front.ordinal))
Expand Down
4 changes: 1 addition & 3 deletions crates/pathing/src/polyanya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ pub(crate) fn find_path(
));
}

let Some(mut best) = open_set.peek().cloned() else {
return None;
};
let mut best = open_set.peek().cloned()?;

let mut counter = 0;
while let Some(node) = open_set.pop() {
Expand Down

0 comments on commit 3077e4a

Please sign in to comment.