Skip to content

Commit 00e255c

Browse files
committed
clippy
1 parent 66db0e1 commit 00e255c

18 files changed

+98
-51
lines changed

src/base_cell.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ impl BaseCell {
140140
.iter()
141141
.position(|&cell| u8::from(neighbor) == cell)
142142
.map(|dir| {
143-
// Cast safe thx to bounds.
144-
#[allow(clippy::cast_possible_truncation)]
143+
#[allow(
144+
clippy::cast_possible_truncation,
145+
reason = "Cast safe thx to bounds"
146+
)]
145147
// SAFETY: `i` is bounded in [0; 6].
146148
Direction::new_unchecked(dir as u8)
147149
})
@@ -198,7 +200,10 @@ impl fmt::Display for BaseCell {
198200
///
199201
/// To reduce the footprints of the lookup table, we use a bitset where the
200202
/// rotation is encoded on 3-bit, where `111` means no rotation for this face.
201-
#[allow(clippy::unusual_byte_groupings)] // Grouping by 3 is more explicit here.
203+
#[allow(
204+
clippy::unusual_byte_groupings,
205+
reason = "Grouping by 3 is more explicit here"
206+
)]
202207
const BASE_CELL_ROTATIONS: [u64; BaseCell::count() as usize] = [
203208
// face 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
204209
0b1111_111_111_111_111_111_111_111_111_111_111_111_111_111_111_111_111_111_001_000_101,

src/coord/cube.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl CoordCube {
2828
let j = f64::from(self.j) + offsets.1;
2929
let k = f64::from(self.k) + offsets.2;
3030

31-
#[allow(clippy::cast_possible_truncation)] // on purpose
31+
#[allow(clippy::cast_possible_truncation, reason = "on purpose")]
3232
let (mut ri, mut rj, mut rk) =
3333
{ (round(i) as i32, round(j) as i32, round(k) as i32) };
3434

src/coord/faceijk.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl FaceIJK {
3838

3939
/// Returns the number of 60° counterclockwise rotations to rotate into the
4040
/// coordinate system of the base cell at that coordinates.
41-
#[allow(clippy::cast_sign_loss)] // Safe because components values are in [0; 2].
41+
#[allow(
42+
clippy::cast_sign_loss,
43+
reason = "safe because components values are in [0; 2]"
44+
)]
4245
pub fn base_cell_rotation(&self) -> Rotation {
4346
// Should always be the case, or we have a nasty bug to fix.
4447
debug_assert!(
@@ -534,7 +537,10 @@ impl FaceIJK {
534537
/// current base cell.
535538
///
536539
/// Returns the adjusted `IJK` coordinates.
537-
#[allow(clippy::inline_always)] // 4-5% boost, up to 13% at resolution 1.
540+
#[allow(
541+
clippy::inline_always,
542+
reason = "4-5% boost, up to 13% at resolution 1."
543+
)]
538544
#[inline(always)]
539545
fn directions_bits_from_ijk(
540546
mut ijk: CoordIJK,

src/coord/ijk.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl CoordIJK {
127127

128128
/// Returns the normalized `IJK` coordinates of the indexing parent of a
129129
/// cell in an aperture 7 grid.
130-
#[allow(clippy::cast_possible_truncation)] // On purpose.
130+
#[allow(clippy::cast_possible_truncation, reason = "on purpose")]
131131
pub fn up_aperture7<const CCW: bool>(&self) -> Self {
132132
let CoordIJ { i, j } = self.into();
133133

@@ -142,7 +142,7 @@ impl CoordIJK {
142142

143143
/// Returns the normalized `IJK` coordinates of the indexing parent of a
144144
/// cell in an aperture 7 grid.
145-
#[allow(clippy::cast_possible_truncation)] // On purpose.
145+
#[allow(clippy::cast_possible_truncation, reason = "on purpose")]
146146
pub fn checked_up_aperture7<const CCW: bool>(&self) -> Option<Self> {
147147
let CoordIJ { i, j } = self.into();
148148

@@ -290,8 +290,11 @@ impl TryFrom<CoordIJK> for Direction {
290290

291291
// First, make sure we have a unit vector in `ijk`.
292292
if (value.i | value.j | value.k) & !1 == 0 {
293-
// Cannot truncate thx to check above (unit vector).
294-
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
293+
#[allow(
294+
clippy::cast_possible_truncation,
295+
clippy::cast_sign_loss,
296+
reason = "cannot truncate thx to check above (unit vector)"
297+
)]
295298
let bits = (value.i << 2 | value.j << 1 | value.k) as u8;
296299

297300
// SAFETY: thx to `normalize` we are guaranteed to have at most two

src/coord/localij.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ impl TryFrom<LocalIJK> for CellIndex {
191191
/// current base cell.
192192
///
193193
/// Returns the adjusted `IJK` coordinates.
194-
#[allow(clippy::inline_always)] // 4-5% boost, up to 13% at resolution 1.
194+
#[allow(
195+
clippy::inline_always,
196+
reason = "4-5% boost, up to 13% at resolution 1"
197+
)]
195198
#[inline(always)]
196199
pub fn checked_directions_bits_from_ijk(
197200
mut ijk: CoordIJK,

src/coord/vec2d.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ impl From<Vec2d> for CoordIJK {
155155
let x1 = a1 + x2 / 2.;
156156

157157
// Check if we have the center of a hex.
158-
#[allow(clippy::cast_possible_truncation)] // on purpose.
158+
#[allow(clippy::cast_possible_truncation, reason = "on purpose")]
159159
let m1 = x1 as i32;
160-
#[allow(clippy::cast_possible_truncation)] // on purpose.
160+
#[allow(clippy::cast_possible_truncation, reason = "on purpose")]
161161
let m2 = x2 as i32;
162162

163163
// Otherwise round correctly.

src/direction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const TO_VERTEX_PENTAGON: [Vertex; NUM_PENT_VERTS as usize] = [
4949
/// ```
5050
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
5151
#[repr(u8)]
52-
#[allow(clippy::exhaustive_enums)] // Not gonna change any time soon.
52+
#[allow(clippy::exhaustive_enums, reason = "not gonna change any time soon")]
5353
#[cfg_attr(
5454
feature = "serde",
5555
derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr)
@@ -107,7 +107,7 @@ impl Direction {
107107
/// # Safety
108108
///
109109
/// The value must be a valid direction.
110-
#[allow(unsafe_code)]
110+
#[allow(unsafe_code, reason = "only used internally")]
111111
pub(crate) const fn new_unchecked(value: u8) -> Self {
112112
assert!(value <= MAX, "direction out of range");
113113
// SAFETY: range checked above.

src/error/invalid_value.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ macro_rules! invalid_value_error {
55
($name:literal, $error:ident, $value_type:ty) => {
66
#[doc = concat!("Invalid ", $name, ".")]
77
#[derive(Clone, Copy, Debug, PartialEq)]
8-
// Value type may not be `Eq` (e.g. f64).
9-
#[allow(clippy::derive_partial_eq_without_eq)]
8+
#[allow(
9+
clippy::derive_partial_eq_without_eq,
10+
reason = "value type may not be `Eq` (e.g. f64)"
11+
)]
1012
pub struct $error {
1113
/// The invalid value.
1214
pub value: $value_type,

src/face.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Face {
2020
/// # Safety
2121
///
2222
/// The value must be a valid face.
23-
#[allow(clippy::cast_possible_truncation)]
23+
#[allow(clippy::cast_possible_truncation, reason = "cannot because assert")]
2424
pub(crate) const fn new_unchecked(value: usize) -> Self {
2525
debug_assert!(value < NUM_ICOSA_FACES, "face out of range");
2626
Self(value as u8)
@@ -134,8 +134,10 @@ impl FaceSet {
134134
/// ```
135135
pub fn iter(self) -> impl Iterator<Item = Face> {
136136
(0..NUM_ICOSA_FACES).filter_map(move |offset| {
137-
#[allow(clippy::cast_possible_truncation)]
138-
// bounded by NUM_ICOSA_FACES.
137+
#[allow(
138+
clippy::cast_possible_truncation,
139+
reason = "bounded by NUM_ICOSA_FACES"
140+
)]
139141
(self.0 >> offset & 1 == 1).then_some(Face(offset as u8))
140142
})
141143
}

src/geom/geometry/bbox.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ pub fn hex_estimate(bbox: &Rect, resolution: Resolution) -> usize {
8686
let (width, length) = if d1 < d2 { (d1, d2) } else { (d2, d1) };
8787
// Derived constant based on: https://math.stackexchange.com/a/1921940
8888
// Clamped to 3 as higher values tend to rapidly drag the estimate to zero.
89-
#[allow(clippy::suspicious_operation_groupings)] // False positive.
89+
#[allow(clippy::suspicious_operation_groupings, reason = "false positive")]
9090
let area = (diagonal * diagonal) / (length / width);
9191

9292
// Divide the two to get an estimate of the number of hexagons needed.
9393
let estimate = (area / pentagon_area_rads2).ceil();
9494

95-
// Truncate on purpose.
96-
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
95+
#[allow(
96+
clippy::cast_possible_truncation,
97+
clippy::cast_sign_loss,
98+
reason = "truncate on purpose"
99+
)]
97100
let estimate = estimate as usize;
98101

99102
core::cmp::max(estimate, 1)

src/geom/geometry/polygon.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ impl Polygon {
163163
) -> Vec<CellIndex> {
164164
// IIUC, the collect is necessary to consume the iterator and release
165165
// the mutable borrow on `already_seen`.
166-
#[allow(clippy::needless_collect)]
166+
#[allow(
167+
clippy::needless_collect,
168+
reason = "needed because mutable borrow"
169+
)]
167170
// Compute the set of cells making the outlines of the polygon.
168171
let outlines = self
169172
.interiors()
@@ -441,8 +444,10 @@ fn get_edge_cells(
441444
let count = line_hex_estimate(&line, resolution);
442445

443446
assert!(count <= 1 << f64::MANTISSA_DIGITS);
444-
#[allow(clippy::cast_precision_loss)]
445-
// Nope thanks to assert above.
447+
#[allow(
448+
clippy::cast_precision_loss,
449+
reason = "cannot happen thanks to assert above"
450+
)]
446451
(0..count).map(move |i| {
447452
let i = i as f64;
448453
let count = count as f64;
@@ -517,8 +522,11 @@ fn line_hex_estimate(line: &geo::Line<f64>, resolution: Resolution) -> u64 {
517522
let dist_ceil = (distance / pentagon_diameter).ceil();
518523
assert!(dist_ceil.is_finite());
519524

520-
// Truncate on purpose.
521-
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
525+
#[allow(
526+
clippy::cast_possible_truncation,
527+
clippy::cast_sign_loss,
528+
reason = "truncate on purpose"
529+
)]
522530
let estimate = dist_ceil as u64;
523531

524532
cmp::max(estimate, 1)

src/geom/ring_hierarchy.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ impl RingHierarchy {
132132
/// Note that in case of nested polygons, you may need to call this function
133133
/// several time to extract outer rings at every nesting level.
134134
fn peel_outers(&mut self) -> Option<Vec<(usize, LineString<f64>)>> {
135-
#[allow(clippy::filter_map_bool_then)] // Borrow issue if filter+map
135+
#[allow(
136+
clippy::filter_map_bool_then,
137+
reason = "borrow issue if filter+map"
138+
)]
136139
let outers = (0..self.rings.len())
137140
.filter_map(|i| {
138141
// Skip assigned rings and non-outer ones.
@@ -158,7 +161,10 @@ impl RingHierarchy {
158161
fn inners(&mut self, outer_id: usize) -> Vec<LineString<f64>> {
159162
// Walk by column to find candidate and then check their parents using
160163
// the row-order
161-
#[allow(clippy::filter_map_bool_then)] // Borrow issue if filter+map
164+
#[allow(
165+
clippy::filter_map_bool_then,
166+
reason = "borrow issue if filter+map"
167+
)]
162168
let (ids, rings) = (0..self.rings.len())
163169
.filter_map(|inner_id| {
164170
(!self.is_assigned[inner_id]

src/index/bits.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const VERTEX_MASK: u64 = 0b111 << VERTEX_OFFSET;
2020
pub const DIRECTIONS_MASK: u64 = 0x0000_1fff_ffff_ffff;
2121

2222
/// Returns the H3 index mode bits.
23-
#[allow(clippy::cast_possible_truncation)] // Cast safe thx to masking.
23+
#[allow(clippy::cast_possible_truncation, reason = "cast safe thx to masking")]
2424
#[must_use]
2525
pub const fn get_mode(bits: u64) -> u8 {
2626
((bits & MODE_MASK) >> MODE_OFFSET) as u8
@@ -39,7 +39,7 @@ pub const fn set_mode(bits: u64, mode: IndexMode) -> u64 {
3939
}
4040

4141
/// Returns the H3 index cell edge bits.
42-
#[allow(clippy::cast_possible_truncation)] // Cast safe thx to masking.
42+
#[allow(clippy::cast_possible_truncation, reason = "cast safe thx to masking")]
4343
#[must_use]
4444
pub const fn get_edge(bits: u64) -> u8 {
4545
((bits & EDGE_MASK) >> EDGE_OFFSET) as u8
@@ -58,7 +58,7 @@ pub const fn clr_edge(bits: u64) -> u64 {
5858
}
5959

6060
/// Returns the H3 index cell vertex bits.
61-
#[allow(clippy::cast_possible_truncation)] // Cast safe thx to masking.
61+
#[allow(clippy::cast_possible_truncation, reason = "cast safe thx to masking")]
6262
#[must_use]
6363
pub const fn get_vertex(bits: u64) -> u8 {
6464
((bits & VERTEX_MASK) >> VERTEX_OFFSET) as u8
@@ -134,7 +134,7 @@ pub fn first_axe(bits: u64) -> Option<NonZeroU8> {
134134
let bit_index = (bits & DIRECTIONS_MASK).leading_zeros() - PREFIX_LENGTH;
135135

136136
// +1 because the first direction is at resolution 1, not 0.
137-
#[allow(clippy::cast_possible_truncation)] // Values are in range.
137+
#[allow(clippy::cast_possible_truncation, reason = "values are in range")]
138138
let resolution = cmp::min(
139139
((bit_index / h3o_bit::DIRECTION_BITSIZE as u32) + 1) as u8,
140140
resolution.into(),

src/index/cell.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ const PENTAGON_ROTATIONS: [[u8; 7]; 7] = [
112112
/// due to failure cases. It's possible this could be restricted to a narrower
113113
/// set of a failure cases. Currently, the logic is any unfolding across more
114114
/// than one icosahedron face is not permitted.
115-
#[allow(clippy::unusual_byte_groupings)] // Grouping by 7 is more explicit here.
115+
#[allow(
116+
clippy::unusual_byte_groupings,
117+
reason = "grouping by 7 is more explicit here"
118+
)]
116119
const FAILED_DIRECTIONS: u64 =
117120
// 6 5 4 3 2 1 0
118121
0b0101000_1000100_0001100_1010000_0110000_0000000_0000000;
@@ -454,7 +457,7 @@ impl CellIndex {
454457
// In this case, `mut-let-if` is faster than the idiomatic `let-if-else`.
455458
// Actually 12.5% faster for hexagons and 3.5% slower for pentagons.
456459
// Given that hexagons are way more common than pentagons, worth it.
457-
#[allow(clippy::useless_let_if_seq)]
460+
#[allow(clippy::useless_let_if_seq, reason = "12.5% faster")]
458461
pub fn children_count(self, resolution: Resolution) -> u64 {
459462
let resolution = usize::from(resolution);
460463
let curr_resolution = usize::from(bits::get_resolution(self.0.get()));
@@ -570,7 +573,10 @@ impl CellIndex {
570573
mut position: u64,
571574
resolution: Resolution,
572575
) -> Option<Self> {
573-
#[allow(clippy::cast_possible_truncation)] // Safe thx to assert.
576+
#[allow(
577+
clippy::cast_possible_truncation,
578+
reason = "safe thx to assert"
579+
)]
574580
fn set_direction(bits: u64, digit: u64, resolution: Resolution) -> u64 {
575581
assert!(digit < 7);
576582
bits::set_direction(bits, digit as u8, resolution)
@@ -1947,7 +1953,7 @@ impl<'a> arbitrary::Arbitrary<'a> for CellIndex {
19471953
/// Checks if there is at least one unused direction in the given directions.
19481954
#[inline(always)]
19491955
#[rustfmt::skip] // Keep constants aligned for readability.
1950-
#[allow(clippy::unusual_byte_groupings)] // Grouping by 3-bit is better here.
1956+
#[allow(clippy::unusual_byte_groupings, reason = "grouping by 3-bit is better here")]
19511957
const fn has_unused_direction(dirs: u64) -> bool {
19521958
// Unused directions are represented by `0b111`, so we actually want to
19531959
// check the absence of this pattern.

src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
//! ## Crate features
99
//!
1010
//! * **std** -
11-
//! When enabled, this will cause `h3o` to use the standard library. In terms of
12-
//! APIs, `std` causes error types to implement the `std::error::Error` trait.
13-
//! Enabling `std` will also result in performance optimizations.
11+
//! When enabled, this will cause `h3o` to use the standard library. In terms of
12+
//! APIs, `std` causes error types to implement the `std::error::Error` trait.
13+
//! Enabling `std` will also result in performance optimizations.
1414
//!
1515
//! * **geo** -
16-
//! When enabled, you'll be able to convert lists of H3 cell indexes from and
17-
//! into geometric shapes. Also enables the `GeoJSON` support. Requires `std`.
16+
//! When enabled, you'll be able to convert lists of H3 cell indexes from and
17+
//! into geometric shapes. Also enables the `GeoJSON` support. Requires `std`.
1818
//!
1919
//! * **serde** -
20-
//! When enabled, H3 index types (cell, vertex and edge) derive serde traits.
20+
//! When enabled, H3 index types (cell, vertex and edge) derive serde traits.
2121
//!
2222
//! ## H3 to H3O mapping
2323
//!
@@ -243,6 +243,7 @@
243243
clippy::unreadable_literal,
244244
// Too many irrelevant warning (about internal invariants).
245245
clippy::missing_panics_doc,
246+
reason = "allow some exceptions"
246247
)]
247248
// }}}
248249

src/resolution.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::{ffi::c_int, fmt, iter::DoubleEndedIterator, str::FromStr};
44
/// Cell resolution, from 0 to 15.
55
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
66
#[repr(u8)]
7-
#[allow(clippy::exhaustive_enums)] // Not gonna change any time soon.
7+
#[allow(clippy::exhaustive_enums, reason = "not gonna change any time soon")]
88
#[cfg_attr(
99
feature = "serde",
1010
derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr)
@@ -125,7 +125,7 @@ impl Resolution {
125125
/// .collect::<Vec<_>>();
126126
/// assert_eq!(res, vec![Resolution::Two, Resolution::One, Resolution::Zero]);
127127
/// ```
128-
#[allow(unsafe_code)]
128+
#[allow(unsafe_code, reason = "safe because of the iterator")]
129129
#[must_use]
130130
pub fn range(
131131
start: Self,
@@ -295,8 +295,10 @@ impl Resolution {
295295
/// let avg_edge_len = h3o::Resolution::Three.edge_length_m();
296296
/// ```
297297
#[must_use]
298-
// I don't want to group digits of the decimal part.
299-
#[allow(clippy::inconsistent_digit_grouping)]
298+
#[allow(
299+
clippy::inconsistent_digit_grouping,
300+
reason = "don't want to group digits of the decimal part"
301+
)]
300302
pub const fn edge_length_m(self) -> f64 {
301303
match self {
302304
Self::Zero => 1281256.0107413644,
@@ -387,7 +389,7 @@ impl Resolution {
387389
/// # Safety
388390
///
389391
/// The value must be a valid resolution.
390-
#[allow(unsafe_code)]
392+
#[allow(unsafe_code, reason = "safe because assert")]
391393
pub(crate) const fn new_unchecked(value: u8) -> Self {
392394
assert!(value <= h3o_bit::MAX_RESOLUTION, "resolution out of range");
393395
// SAFETY: range is checked above!

0 commit comments

Comments
 (0)