Skip to content

Commit d89c3a8

Browse files
authored
stricter clippy (#97)
1 parent 06bd0bb commit d89c3a8

File tree

10 files changed

+41
-21
lines changed

10 files changed

+41
-21
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
pass_filenames: false
2222
- id: clippy
2323
name: Clippy
24-
entry: cargo clippy -F python -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout
24+
entry: cargo clippy -F python -- -D warnings
2525
types: [rust]
2626
language: system
2727
pass_filenames: false

crates/jiter/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,25 @@ harness = false
4949
# get docs.rs to include python docs
5050
[package.metadata.docs.rs]
5151
all-features = true
52+
53+
[lints.clippy]
54+
dbg_macro = "deny"
55+
print_stdout = "deny"
56+
print_stderr = "deny"
57+
# in general we lint against the pedantic group, but we will whitelist
58+
# certain lints which we don't want to enforce (for now)
59+
pedantic = { level = "deny", priority = -1 }
60+
missing_errors_doc = "allow"
61+
module_name_repetitions = "allow"
62+
must_use_candidate = "allow"
63+
if_not_else = "allow"
64+
cast_lossless = "allow"
65+
cast_possible_wrap = "allow"
66+
cast_possible_truncation = "allow"
67+
cast_precision_loss = "allow"
68+
match_bool = "allow"
69+
doc_markdown = "allow"
70+
implicit_clone = "allow"
71+
iter_without_into_iter = "allow"
72+
inline_always = "allow" # TODO remove?
73+
match_same_arms = "allow" # TODO remove?

crates/jiter/src/errors.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt;
2-
31
/// Enum representing all possible errors in JSON syntax.
42
///
53
/// Almost all of `JsonErrorType` is copied from [serde_json](https://github.com/serde-rs) so errors match
@@ -196,9 +194,9 @@ pub enum JiterErrorType {
196194
impl std::fmt::Display for JiterErrorType {
197195
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
198196
match self {
199-
Self::JsonError(error_type) => write!(f, "{}", error_type),
197+
Self::JsonError(error_type) => write!(f, "{error_type}"),
200198
Self::WrongType { expected, actual } => {
201-
write!(f, "expected {} but found {}", expected, actual)
199+
write!(f, "expected {expected} but found {actual}")
202200
}
203201
}
204202
}
@@ -254,8 +252,8 @@ pub struct LinePosition {
254252
pub column: usize,
255253
}
256254

257-
impl fmt::Display for LinePosition {
258-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
255+
impl std::fmt::Display for LinePosition {
256+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
259257
write!(f, "line {} column {}", self.line, self.column)
260258
}
261259
}

crates/jiter/src/number_decoder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl IntParse {
194194
index += 1;
195195
return match data.get(index) {
196196
Some(b'.') => Ok((Self::Float, index)),
197-
Some(b'e') | Some(b'E') => Ok((Self::Float, index)),
197+
Some(b'e' | b'E') => Ok((Self::Float, index)),
198198
Some(digit) if digit.is_ascii_digit() => json_err!(InvalidNumber, index),
199199
_ => Ok((Self::Int(NumberInt::Int(0)), index)),
200200
};
@@ -213,7 +213,7 @@ impl IntParse {
213213
IntChunk::Done(value) => {
214214
let mut value_i64 = value as i64;
215215
if !positive {
216-
value_i64 = -value_i64
216+
value_i64 = -value_i64;
217217
}
218218
return Ok((Self::Int(NumberInt::Int(value_i64)), new_index));
219219
}
@@ -379,7 +379,7 @@ impl AbstractNumberDecoder for NumberRange {
379379
let end = consume_decimal(data, index)?;
380380
Ok((start..end, end))
381381
}
382-
Some(b'e') | Some(b'E') => {
382+
Some(b'e' | b'E') => {
383383
index += 1;
384384
let end = consume_exponential(data, index)?;
385385
Ok((start..end, end))
@@ -420,6 +420,7 @@ impl AbstractNumberDecoder for NumberRange {
420420
if (new_index - start) > 4300 {
421421
return json_err!(NumberOutOfRange, start + 4301);
422422
}
423+
#[allow(clippy::single_match_else)]
423424
match chunk {
424425
IntChunk::Ongoing(_) => {
425426
index = new_index;
@@ -446,7 +447,7 @@ impl AbstractNumberDecoder for NumberRange {
446447

447448
fn consume_exponential(data: &[u8], mut index: usize) -> JsonResult<usize> {
448449
match data.get(index) {
449-
Some(b'-') | Some(b'+') => {
450+
Some(b'-' | b'+') => {
450451
index += 1;
451452
}
452453
Some(v) if v.is_ascii_digit() => (),

crates/jiter/src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ pub(crate) fn consume_nan(data: &[u8], index: usize) -> JsonResult<usize> {
266266
}
267267

268268
fn consume_ident<const SIZE: usize>(data: &[u8], mut index: usize, expected: [u8; SIZE]) -> JsonResult<usize> {
269-
match data.get(index + 1..index + SIZE + 1) {
269+
match data.get(index + 1..=index + SIZE) {
270270
Some(s) if s == expected => Ok(index + SIZE + 1),
271271
// TODO very sadly iterating over expected cause extra branches in the generated assembly
272272
// and is significantly slower than just returning an error
273273
_ => {
274274
index += 1;
275-
for c in expected.iter() {
275+
for c in &expected {
276276
match data.get(index) {
277277
Some(v) if v == c => index += 1,
278278
Some(_) => return json_err!(ExpectedSomeIdent, index),

crates/jiter/src/py_string_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn cache_usage(py: Python) -> usize {
9595
}
9696

9797
pub fn cache_clear(py: Python) {
98-
get_string_cache!(py).borrow_mut().clear()
98+
get_string_cache!(py).borrow_mut().clear();
9999
}
100100

101101
pub fn cached_py_string<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bound<'py, PyString> {

crates/jiter/src/python.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ impl<'j, StringCache: StringMaybeCache, KeyCheck: MaybeKeyCheck> PythonParser<'j
183183
// AFAIK this shouldn't happen since the key will always be a string which is hashable
184184
// we panic here rather than returning a result and using `?` below as it's up to 14% faster
185185
// presumably because there are fewer branches
186-
if r == -1 {
187-
panic!("PyDict_SetItem failed")
188-
}
186+
assert_ne!(r, -1, "PyDict_SetItem failed");
189187
};
190188
let mut check_keys = KeyCheck::default();
191189
if let Some(first_key) = self.parser.object_first::<StringDecoder>(&mut self.tape)? {

crates/jiter/src/simd_aarch64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ unsafe fn full_calc(byte_vec: SimdVecu8_16, last_digit: u32) -> u64 {
177177
// transmute the 2x64-bit lane into an array;
178178
let t: [u64; 2] = transmute(x);
179179
// since the data started out as digits, it's safe to assume the result fits in a u64
180-
t[0].wrapping_mul(100000000).wrapping_add(t[1])
180+
t[0].wrapping_mul(100_000_000).wrapping_add(t[1])
181181
}
182182

183183
fn next_is_float(data: &[u8], index: usize) -> bool {
@@ -207,6 +207,7 @@ pub fn decode_string_chunk(
207207
} else {
208208
// this chunk contains either a stop character or a non-ascii character
209209
let a: [u8; 16] = unsafe { transmute(byte_vec) };
210+
#[allow(clippy::redundant_else)]
210211
if let Some(r) = StringChunk::decode_array(a, &mut index, ascii_only) {
211212
return r;
212213
} else {

crates/jiter/src/string_decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ fn parse_u4(data: &[u8], mut index: usize) -> JsonResult<(u16, usize)> {
314314
.get(index + 1..index + 5)
315315
.ok_or_else(|| json_error!(EofWhileParsingString, data.len()))?;
316316

317-
for c in u4.iter() {
317+
for c in u4 {
318318
index += 1;
319319
let hex = match c {
320320
b'0'..=b'9' => (c & 0x0f) as u16,

crates/jiter/tests/python.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use pyo3::prelude::*;
2-
use pyo3::types::{PyDict, PyList, PyString};
2+
use pyo3::types::PyString;
33

4-
use jiter::{cache_clear, cache_usage, map_json_error, pystring_fast_new, python_parse, JsonValue, StringCacheMode};
4+
use jiter::{pystring_fast_new, JsonValue, StringCacheMode};
55

66
#[test]
77
fn test_to_py_object_numeric() {

0 commit comments

Comments
 (0)