Skip to content

Commit 93b707a

Browse files
committed
lint: use expect instead of allow
Avoid stale lint. Only keep one allows due to macro codegen.
1 parent aabbd3a commit 93b707a

16 files changed

+34
-41
lines changed

src/base_cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl BaseCell {
140140
.iter()
141141
.position(|&cell| u8::from(neighbor) == cell)
142142
.map(|dir| {
143-
#[allow(
143+
#[expect(
144144
clippy::cast_possible_truncation,
145145
reason = "Cast safe thx to bounds"
146146
)]
@@ -200,7 +200,7 @@ impl fmt::Display for BaseCell {
200200
///
201201
/// To reduce the footprints of the lookup table, we use a bitset where the
202202
/// rotation is encoded on 3-bit, where `111` means no rotation for this face.
203-
#[allow(
203+
#[expect(
204204
clippy::unusual_byte_groupings,
205205
reason = "Grouping by 3 is more explicit here"
206206
)]

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, reason = "on purpose")]
31+
#[expect(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

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ 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(
41+
#[expect(
4242
clippy::cast_sign_loss,
4343
reason = "safe because components values are in [0; 2]"
4444
)]
@@ -537,7 +537,7 @@ impl FaceIJK {
537537
/// current base cell.
538538
///
539539
/// Returns the adjusted `IJK` coordinates.
540-
#[allow(
540+
#[expect(
541541
clippy::inline_always,
542542
reason = "4-5% boost, up to 13% at resolution 1."
543543
)]

src/coord/ijk.rs

+3-3
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, reason = "on purpose")]
130+
#[expect(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, reason = "on purpose")]
145+
#[expect(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,7 +290,7 @@ 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-
#[allow(
293+
#[expect(
294294
clippy::cast_possible_truncation,
295295
clippy::cast_sign_loss,
296296
reason = "cannot truncate thx to check above (unit vector)"

src/coord/localij.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl TryFrom<LocalIJK> for CellIndex {
191191
/// current base cell.
192192
///
193193
/// Returns the adjusted `IJK` coordinates.
194-
#[allow(
194+
#[expect(
195195
clippy::inline_always,
196196
reason = "4-5% boost, up to 13% at resolution 1"
197197
)]

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, reason = "on purpose")]
158+
#[expect(clippy::cast_possible_truncation, reason = "on purpose")]
159159
let m1 = x1 as i32;
160-
#[allow(clippy::cast_possible_truncation, reason = "on purpose")]
160+
#[expect(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, reason = "not gonna change any time soon")]
52+
#[expect(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, reason = "only used internally")]
110+
#[expect(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

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ macro_rules! invalid_value_error {
66
#[doc = concat!("Invalid ", $name, ".")]
77
#[derive(Clone, Copy, Debug, PartialEq)]
88
#[allow(
9+
clippy::allow_attributes,
910
clippy::derive_partial_eq_without_eq,
1011
reason = "value type may not be `Eq` (e.g. f64)"
1112
)]

src/face.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ impl Face {
2020
/// # Safety
2121
///
2222
/// The value must be a valid face.
23-
#[allow(clippy::cast_possible_truncation, reason = "cannot because assert")]
23+
#[expect(
24+
clippy::cast_possible_truncation,
25+
reason = "cannot because assert"
26+
)]
2427
pub(crate) const fn new_unchecked(value: usize) -> Self {
2528
debug_assert!(value < NUM_ICOSA_FACES, "face out of range");
2629
Self(value as u8)
@@ -134,7 +137,7 @@ impl FaceSet {
134137
/// ```
135138
pub fn iter(self) -> impl Iterator<Item = Face> {
136139
(0..NUM_ICOSA_FACES).filter_map(move |offset| {
137-
#[allow(
140+
#[expect(
138141
clippy::cast_possible_truncation,
139142
reason = "bounded by NUM_ICOSA_FACES"
140143
)]

src/geom/ring_hierarchy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl RingHierarchy {
131131
/// Note that in case of nested polygons, you may need to call this function
132132
/// several time to extract outer rings at every nesting level.
133133
fn peel_outers(&mut self) -> Option<Vec<(usize, LineString<f64>)>> {
134-
#[allow(
134+
#[expect(
135135
clippy::filter_map_bool_then,
136136
reason = "borrow issue if filter+map"
137137
)]
@@ -160,7 +160,7 @@ impl RingHierarchy {
160160
fn inners(&mut self, outer_id: usize) -> Vec<LineString<f64>> {
161161
// Walk by column to find candidate and then check their parents using
162162
// the row-order
163-
#[allow(
163+
#[expect(
164164
clippy::filter_map_bool_then,
165165
reason = "borrow issue if filter+map"
166166
)]

src/geom/tiler.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl Tiler {
254254
) -> Vec<(CellIndex, bool)> {
255255
// IIUC, the collect is necessary to consume the iterator and release
256256
// the mutable borrow on `already_seen`.
257-
#[allow(
257+
#[expect(
258258
clippy::needless_collect,
259259
reason = "needed because mutable borrow"
260260
)]
@@ -556,7 +556,7 @@ fn get_edge_cells(
556556
let count = line_hex_estimate(&line, resolution);
557557

558558
assert!(count <= 1 << f64::MANTISSA_DIGITS);
559-
#[allow(
559+
#[expect(
560560
clippy::cast_precision_loss,
561561
reason = "cannot happen thanks to assert above"
562562
)]
@@ -607,7 +607,7 @@ fn line_hex_estimate(line: &Line, resolution: Resolution) -> u64 {
607607
let dist_ceil = (distance / pentagon_diameter).ceil();
608608
assert!(dist_ceil.is_finite());
609609

610-
#[allow(
610+
#[expect(
611611
clippy::cast_possible_truncation,
612612
clippy::cast_sign_loss,
613613
reason = "truncate on purpose"
@@ -658,13 +658,13 @@ pub fn bbox_hex_estimate(bbox: &Rect, resolution: Resolution) -> usize {
658658
let (width, length) = if d1 < d2 { (d1, d2) } else { (d2, d1) };
659659
// Derived constant based on: https://math.stackexchange.com/a/1921940
660660
// Clamped to 3 as higher values tend to rapidly drag the estimate to zero.
661-
#[allow(clippy::suspicious_operation_groupings, reason = "false positive")]
661+
#[expect(clippy::suspicious_operation_groupings, reason = "false positive")]
662662
let area = (diagonal * diagonal) / (length / width);
663663

664664
// Divide the two to get an estimate of the number of hexagons needed.
665665
let estimate = (area / pentagon_area_rads2).ceil();
666666

667-
#[allow(
667+
#[expect(
668668
clippy::cast_possible_truncation,
669669
clippy::cast_sign_loss,
670670
reason = "truncate on purpose"

src/index/bits.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ 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, reason = "cast safe thx to masking")]
2423
#[must_use]
2524
pub const fn get_mode(bits: u64) -> u8 {
2625
((bits & MODE_MASK) >> MODE_OFFSET) as u8
@@ -39,7 +38,6 @@ pub const fn set_mode(bits: u64, mode: IndexMode) -> u64 {
3938
}
4039

4140
/// Returns the H3 index cell edge bits.
42-
#[allow(clippy::cast_possible_truncation, reason = "cast safe thx to masking")]
4341
#[must_use]
4442
pub const fn get_edge(bits: u64) -> u8 {
4543
((bits & EDGE_MASK) >> EDGE_OFFSET) as u8
@@ -58,7 +56,6 @@ pub const fn clr_edge(bits: u64) -> u64 {
5856
}
5957

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

136133
// +1 because the first direction is at resolution 1, not 0.
137-
#[allow(clippy::cast_possible_truncation, reason = "values are in range")]
134+
#[expect(clippy::cast_possible_truncation, reason = "values are in range")]
138135
let resolution = cmp::min(
139136
((bit_index / h3o_bit::DIRECTION_BITSIZE as u32) + 1) as u8,
140137
resolution.into(),

src/index/cell.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ const PENTAGON_ROTATIONS: [[u8; 7]; 7] = [
113113
/// due to failure cases. It's possible this could be restricted to a narrower
114114
/// set of a failure cases. Currently, the logic is any unfolding across more
115115
/// than one icosahedron face is not permitted.
116-
#[allow(
117-
clippy::unusual_byte_groupings,
118-
reason = "grouping by 7 is more explicit here"
119-
)]
120116
const FAILED_DIRECTIONS: u64 =
121117
// 6 5 4 3 2 1 0
122118
0b0101000_1000100_0001100_1010000_0110000_0000000_0000000;
@@ -458,7 +454,7 @@ impl CellIndex {
458454
// In this case, `mut-let-if` is faster than the idiomatic `let-if-else`.
459455
// Actually 12.5% faster for hexagons and 3.5% slower for pentagons.
460456
// Given that hexagons are way more common than pentagons, worth it.
461-
#[allow(clippy::useless_let_if_seq, reason = "12.5% faster")]
457+
#[expect(clippy::useless_let_if_seq, reason = "12.5% faster")]
462458
pub fn children_count(self, resolution: Resolution) -> u64 {
463459
let resolution = usize::from(resolution);
464460
let curr_resolution = usize::from(bits::get_resolution(self.0.get()));
@@ -574,7 +570,7 @@ impl CellIndex {
574570
mut position: u64,
575571
resolution: Resolution,
576572
) -> Option<Self> {
577-
#[allow(
573+
#[expect(
578574
clippy::cast_possible_truncation,
579575
reason = "safe thx to assert"
580576
)]
@@ -2002,7 +1998,6 @@ impl<'a> arbitrary::Arbitrary<'a> for CellIndex {
20021998
/// Checks if there is at least one unused direction in the given directions.
20031999
#[inline(always)]
20042000
#[rustfmt::skip] // Keep constants aligned for readability.
2005-
#[allow(clippy::unusual_byte_groupings, reason = "grouping by 3-bit is better here")]
20062001
const fn has_unused_direction(dirs: u64) -> bool {
20072002
// Unused directions are represented by `0b111`, so we actually want to
20082003
// check the absence of this pattern.

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
clippy::all,
153153
clippy::cargo,
154154
clippy::pedantic,
155+
clippy::allow_attributes,
155156
clippy::allow_attributes_without_reason,
156157
clippy::as_underscore,
157158
clippy::branches_sharing_code,

src/resolution.rs

+3-7
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, reason = "not gonna change any time soon")]
7+
#[expect(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, reason = "safe because of the iterator")]
128+
#[expect(unsafe_code, reason = "safe because of the iterator")]
129129
#[must_use]
130130
pub fn range(
131131
start: Self,
@@ -295,10 +295,6 @@ impl Resolution {
295295
/// let avg_edge_len = h3o::Resolution::Three.edge_length_m();
296296
/// ```
297297
#[must_use]
298-
#[allow(
299-
clippy::inconsistent_digit_grouping,
300-
reason = "don't want to group digits of the decimal part"
301-
)]
302298
pub const fn edge_length_m(self) -> f64 {
303299
match self {
304300
Self::Zero => 1281256.0107413644,
@@ -389,7 +385,7 @@ impl Resolution {
389385
/// # Safety
390386
///
391387
/// The value must be a valid resolution.
392-
#[allow(unsafe_code, reason = "safe because assert")]
388+
#[expect(unsafe_code, reason = "safe because assert")]
393389
pub(crate) const fn new_unchecked(value: u8) -> Self {
394390
assert!(value <= h3o_bit::MAX_RESOLUTION, "resolution out of range");
395391
// SAFETY: range is checked above!

tests/api/latlng.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn debug() {
4343
}
4444

4545
#[test]
46-
#[allow(clippy::float_cmp, reason = "on purpose")]
46+
#[expect(clippy::float_cmp, reason = "on purpose")]
4747
fn lat_lng() {
4848
let lat = 2.349014;
4949
let lng = 48.864716;

0 commit comments

Comments
 (0)