Skip to content

Commit 686b35b

Browse files
committed
ecs: Resolve Clippy lints
There was one false positive never_loop lint.
1 parent 1ec4e78 commit 686b35b

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

quill/ecs/src/borrow.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,38 @@ impl<'a, T> Drop for RefMut<'a, T> {
116116
self.flag.unborrow_mut();
117117
}
118118
}
119+
120+
#[cfg(test)]
121+
mod tests {
122+
use super::*;
123+
124+
#[test]
125+
fn borrow_unborrow() {
126+
let flag = BorrowFlag::default();
127+
flag.borrow().unwrap();
128+
assert!(flag.borrow_mut().is_err());
129+
flag.borrow().unwrap();
130+
assert!(flag.borrow_mut().is_err());
131+
132+
flag.unborrow();
133+
assert!(flag.borrow_mut().is_err());
134+
flag.unborrow();
135+
136+
flag.borrow_mut().unwrap();
137+
assert!(flag.borrow().is_err());
138+
assert!(flag.borrow_mut().is_err());
139+
140+
flag.unborrow_mut();
141+
flag.borrow().unwrap();
142+
}
143+
144+
#[test]
145+
fn borrow_max_amount() {
146+
let flag = BorrowFlag::default();
147+
for _ in 0..254 {
148+
flag.borrow().unwrap();
149+
assert!(flag.borrow_mut().is_err());
150+
}
151+
assert!(flag.borrow().is_err());
152+
}
153+
}

quill/ecs/src/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct QueryDriverIter<'w, 'q> {
6565
}
6666

6767
impl<'w, 'q> QueryDriverIter<'w, 'q> {
68+
#[allow(clippy::never_loop)] // looks like a false positive - the loop has a `continue`
6869
pub fn next(&mut self) -> Option<QueryItem> {
6970
loop {
7071
let (sparse_index, lead_dense_index) = self.lead_iter.next()?;

quill/ecs/src/storage/component_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl ComponentVec {
141141
.arrays
142142
.last()
143143
.map(|array| array.capacity())
144-
.unwrap_or(2usize.pow(START_CAP_LOG2 as u32));
144+
.unwrap_or_else(|| 2usize.pow(START_CAP_LOG2 as u32));
145145
let next_capacity = previous_capacity.checked_mul(2).expect("capacity overflow");
146146
let array = BlobArray::new(self.component_meta.layout, next_capacity);
147147
self.arrays.push(array);

quill/ecs/src/storage/sparse_set.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ impl SparseSetStorage {
5757
}
5858
}
5959

60+
/// # Safety
61+
/// `component` must point to a valid (but not necessarily aligned) instance of the component
62+
/// stored in this sparse set.
6063
pub unsafe fn insert_raw(&mut self, index: u32, component: *const u8) {
6164
self.grow_sparse_for(index);
6265

@@ -183,6 +186,10 @@ impl<'a> SparseSetRef<'a> {
183186
self.dense.len()
184187
}
185188

189+
pub fn is_empty(&self) -> bool {
190+
self.len() == 0
191+
}
192+
186193
/// Returns an iterator over (sparse_index, dense_index) within this sparse set.
187194
pub fn iter(&self) -> Iter<'a> {
188195
Iter {

quill/ecs/tests/ecs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ fn spawn_many_entities() {
2323
let mut entities = Vec::new();
2424
for i in 0..10_000 {
2525
let entity = EntityBuilder::new()
26-
.add(10.0f32)
26+
.add(10i32)
2727
.add(format!("Entity #{}", i))
2828
.spawn_into(&mut ecs);
2929
entities.push(entity);
3030
}
3131

3232
for (i, entity) in entities.into_iter().enumerate() {
33-
assert_eq!(*ecs.get::<f32>(entity).unwrap(), 10.0);
33+
assert_eq!(*ecs.get::<i32>(entity).unwrap(), 10);
3434
assert_eq!(
3535
*ecs.get::<String>(entity).unwrap(),
3636
format!("Entity #{}", i)

0 commit comments

Comments
 (0)