Fix all clippy warnings · feather-rs/feather@56e6479 · GitHub
Skip to content

Commit 56e6479

Browse files
committed
Fix all clippy warnings
1 parent 5cbf5d8 commit 56e6479

29 files changed

Lines changed: 137 additions & 63 deletions

File tree

crates/base/src/anvil/player.rs

Lines changed: 1 addition & 4 deletions

crates/base/src/anvil/region.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl RegionHandle {
235235
for index in 0..1024 {
236236
let id = level.biomes[index];
237237
chunk.biomes_mut().as_slice_mut()[index] =
238-
Biome::from_id(id as u32).ok_or_else(|| Error::InvalidBiomeId(id))?;
238+
Biome::from_id(id as u32).ok_or(Error::InvalidBiomeId(id))?;
239239
}
240240

241241
// chunk.recalculate_heightmap();
@@ -381,8 +381,8 @@ fn read_section_into_chunk(section: &mut LevelSection, chunk: &mut Chunk) -> Res
381381
let block_light = convert_light_data(&section.block_light);
382382
let sky_light = convert_light_data(&section.sky_light);
383383

384-
let light = LightStore::from_packed_arrays(block_light, sky_light)
385-
.ok_or_else(|| Error::IndexOutOfBounds)?;
384+
let light =
385+
LightStore::from_packed_arrays(block_light, sky_light).ok_or(Error::IndexOutOfBounds)?;
386386
let blocks = BlockStore::from_raw_parts(Some(palette), data);
387387

388388
let chunk_section = ChunkSection::new(blocks, light);

crates/base/src/chunk.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ impl Chunk {
161161
.recalculate(Self::block_at_fn(&self.sections))
162162
}
163163

164-
fn block_at_fn<'a>(
165-
sections: &'a [Option<ChunkSection>],
166-
) -> impl Fn(usize, usize, usize) -> BlockId + 'a {
164+
fn block_at_fn(
165+
sections: &[Option<ChunkSection>],
166+
) -> impl Fn(usize, usize, usize) -> BlockId + '_ {
167167
move |x, y, z| {
168168
let section = &sections[(y / SECTION_HEIGHT) + 1];
169169
match section {
@@ -393,7 +393,7 @@ mod tests {
393393

394394
chunk.set_block_at(0, 0, 0, BlockId::andesite());
395395
assert_eq!(chunk.block_at(0, 0, 0).unwrap(), BlockId::andesite());
396-
assert!(chunk.section(0).is_some());
396+
assert!(chunk.section(1).is_some());
397397
}
398398

399399
#[test]
@@ -446,7 +446,7 @@ mod tests {
446446
assert_eq!(chunk.block_at(x, (section * 16) + y, z), Some(block));
447447
if counter != 0 {
448448
assert!(
449-
chunk.section(section).is_some(),
449+
chunk.section(section + 1).is_some(),
450450
"Section {} failed",
451451
section
452452
);
@@ -459,14 +459,14 @@ mod tests {
459459

460460
// Go through again to be sure
461461
for section in 0..16 {
462-
assert!(chunk.section(section).is_some());
462+
assert!(chunk.section(section + 1).is_some());
463463
let mut counter = 0;
464464
for x in 0..16 {
465465
for y in 0..16 {
466466
for z in 0..16 {
467467
let block = BlockId::from_vanilla_id(counter);
468468
assert_eq!(chunk.block_at(x, (section * 16) + y, z), Some(block));
469-
assert!(chunk.section(section).is_some());
469+
assert!(chunk.section(section + 1).is_some());
470470
counter += 1;
471471
}
472472
}

crates/base/src/chunk/blocks.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub struct BlockStore {
2020
air_block_count: u32,
2121
}
2222

23+
impl Default for BlockStore {
24+
fn default() -> Self {
25+
Self::new()
26+
}
27+
}
28+
2329
impl BlockStore {
2430
/// Creates a new `BlockStore` containing air.
2531
pub fn new() -> Self {

crates/base/src/chunk/heightmap.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub struct HeightmapStore {
1616
pub world_surface: Heightmap<WorldSurface>,
1717
}
1818

19+
impl Default for HeightmapStore {
20+
fn default() -> Self {
21+
Self::new()
22+
}
23+
}
24+
1925
impl HeightmapStore {
2026
pub fn new() -> Self {
2127
Self {
@@ -111,6 +117,15 @@ pub struct Heightmap<F> {
111117
_marker: PhantomData<F>,
112118
}
113119

120+
impl<F> Default for Heightmap<F>
121+
where
122+
F: HeightmapFunction,
123+
{
124+
fn default() -> Self {
125+
Self::new()
126+
}
127+
}
128+
114129
impl<F> Heightmap<F>
115130
where
116131
F: HeightmapFunction,

crates/base/src/chunk/light.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pub struct LightStore {
99
sky_light: PackedArray,
1010
}
1111

12+
impl Default for LightStore {
13+
fn default() -> Self {
14+
Self::new()
15+
}
16+
}
17+
1218
impl LightStore {
1319
/// Creates a `LightStore` with all light set to 15.
1420
pub fn new() -> Self {

crates/base/src/chunk/packed_array.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl PackedArray {
7474
}
7575

7676
/// Returns an iterator over values in this array.
77-
pub fn iter<'a>(&'a self) -> impl Iterator<Item = u64> + 'a {
77+
pub fn iter(&self) -> impl Iterator<Item = u64> + '_ {
7878
let values_per_u64 = self.values_per_u64();
7979
let bits_per_value = self.bits_per_value() as u64;
8080
let mask = self.mask();
@@ -83,7 +83,7 @@ impl PackedArray {
8383
self.bits
8484
.iter()
8585
.flat_map(move |&u64| {
86-
(0..values_per_u64).map(move |i| (u64 >> i as u64 * bits_per_value) & mask)
86+
(0..values_per_u64).map(move |i| (u64 >> (i as u64 * bits_per_value)) & mask)
8787
})
8888
.take(length)
8989
}
@@ -219,12 +219,12 @@ mod tests {
219219
assert_eq!(array.get(i), Some(value));
220220
}
221221

222-
for i in 0..array.len() {
223-
assert_eq!(array.get(i), Some(oracle[i]));
222+
for (i, &oracle_value) in oracle.iter().enumerate() {
223+
assert_eq!(array.get(i), Some(oracle_value));
224224
}
225225

226-
for (i, value) in array.iter().enumerate() {
227-
assert_eq!(value, oracle[i]);
226+
for (value, &oracle_value) in array.iter().zip(oracle.iter()) {
227+
assert_eq!(value, oracle_value);
228228
}
229229
}
230230

@@ -243,14 +243,14 @@ mod tests {
243243
oracle.push(value);
244244
}
245245

246-
for i in 0..array.len() {
247-
assert_eq!(array.get(i), Some(oracle[i]));
246+
for (i, &oracle_value) in oracle.iter().enumerate() {
247+
assert_eq!(array.get(i), Some(oracle_value));
248248
}
249249

250250
array = array.resized(new_bits_per_value);
251251

252-
for i in 0..array.len() {
253-
assert_eq!(array.get(i), Some(oracle[i]));
252+
for (i, &oracle_value) in oracle.iter().enumerate() {
253+
assert_eq!(array.get(i), Some(oracle_value));
254254
}
255255

256256
oracle.clear();

crates/base/src/chunk/palette.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ pub struct Palette {
1111
free_indices: Vec<usize>,
1212
}
1313

14+
impl Default for Palette {
15+
fn default() -> Self {
16+
Self::new()
17+
}
18+
}
19+
20+
#[allow(clippy::clippy::len_without_is_empty)] // palette is never empty
1421
impl Palette {
1522
/// Creates an empty palette.
1623
pub fn new() -> Self {

crates/base/src/text/markdown/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn tokens_to_text(tokens: Vec<LexToken>) -> Token {
9191
}
9292

9393
let trimmed = s.trim();
94-
if s.starts_with(' ') && trimmed != "" {
94+
if s.starts_with(' ') && !trimmed.is_empty() {
9595
let first_span = &tokens[1].span;
9696
let t = TokenType::Text(trimmed.to_string());
9797
let span = DynamicSpan::new(

crates/blocks/src/directions.rs

Lines changed: 1 addition & 4 deletions

0 commit comments

Comments
 (0)