Skip to content

Commit 5dbbb4d

Browse files
committed
chore: fix all Clippy warnings
There are lost of new Clippy warnings, fix all of them or silence them in case the change would be too big.
1 parent 6857a14 commit 5dbbb4d

File tree

12 files changed

+85
-100
lines changed

12 files changed

+85
-100
lines changed

src/aggregates.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl AggregateFun {
9797
base
9898
}
9999

100-
fn sum(existing: &mut JsonValue, new: JsonValue, user_arg: Option<&JsonValue>) {
100+
fn sum(existing: &mut JsonValue, new: JsonValue, _user_arg: Option<&JsonValue>) {
101101
match new {
102102
JsonValue::Number(new) => {
103103
if let JsonValue::Number(ref mut existing) = *existing {
@@ -106,7 +106,7 @@ impl AggregateFun {
106106
}
107107
JsonValue::Array(vec) => {
108108
for v in vec {
109-
AggregateFun::sum(existing, v, user_arg);
109+
AggregateFun::sum(existing, v, _user_arg);
110110
}
111111
}
112112
_ => (),
@@ -134,10 +134,10 @@ impl AggregateFun {
134134
val
135135
}
136136

137-
fn max_array(existing: &mut JsonValue, new: JsonValue, user_arg: Option<&JsonValue>) {
137+
fn max_array(existing: &mut JsonValue, new: JsonValue, _user_arg: Option<&JsonValue>) {
138138
if let JsonValue::Array(vec) = new {
139139
for v in vec {
140-
AggregateFun::max_array(existing, v, user_arg);
140+
AggregateFun::max_array(existing, v, _user_arg);
141141
}
142142
} else if let JsonValue::Array(_) = *existing {
143143
*existing = new;
@@ -155,10 +155,10 @@ impl AggregateFun {
155155
val
156156
}
157157

158-
fn min_array(existing: &mut JsonValue, new: JsonValue, user_arg: Option<&JsonValue>) {
158+
fn min_array(existing: &mut JsonValue, new: JsonValue, _user_arg: Option<&JsonValue>) {
159159
if let JsonValue::Array(vec) = new {
160160
for v in vec {
161-
AggregateFun::min_array(existing, v, user_arg);
161+
AggregateFun::min_array(existing, v, _user_arg);
162162
}
163163
} else if let JsonValue::Array(_) = *existing {
164164
*existing = new;
@@ -183,10 +183,10 @@ impl AggregateFun {
183183
new
184184
}
185185

186-
fn array_flat(existing: &mut JsonValue, new: JsonValue, user_arg: Option<&JsonValue>) {
186+
fn array_flat(existing: &mut JsonValue, new: JsonValue, _user_arg: Option<&JsonValue>) {
187187
if let JsonValue::Array(vec) = new {
188188
for v in vec.into_iter() {
189-
AggregateFun::array_flat(existing, v, user_arg);
189+
AggregateFun::array_flat(existing, v, _user_arg);
190190
}
191191
} else if let JsonValue::Array(ref mut existing) = *existing {
192192
existing.push(new);
@@ -204,7 +204,7 @@ impl AggregateFun {
204204
fn concat(existing: &mut JsonValue, new: JsonValue, user_arg: Option<&JsonValue>) {
205205
if let JsonValue::String(ref mut existing) = *existing {
206206
if let JsonValue::String(new) = new {
207-
if let Some(&JsonValue::String(ref user_arg)) = user_arg {
207+
if let Some(JsonValue::String(user_arg)) = user_arg {
208208
existing.push_str(user_arg);
209209
existing.push_str(&new);
210210
}
@@ -224,7 +224,7 @@ impl AggregateFun {
224224
}
225225
}
226226

227-
fn avg(existing: &mut JsonValue, new: JsonValue, user_arg: Option<&JsonValue>) {
227+
fn avg(existing: &mut JsonValue, new: JsonValue, _user_arg: Option<&JsonValue>) {
228228
if let JsonValue::Number(new) = new {
229229
if let JsonValue::Array(ref mut array) = *existing {
230230
let mut avg = if let JsonValue::Number(ref avg) = array[0] {
@@ -248,7 +248,7 @@ impl AggregateFun {
248248
}
249249
} else if let JsonValue::Array(vec) = new {
250250
for v in vec.into_iter() {
251-
AggregateFun::avg(existing, v, user_arg);
251+
AggregateFun::avg(existing, v, _user_arg);
252252
}
253253
}
254254
}

src/error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ pub enum Error {
1616

1717
impl PartialEq for Error {
1818
fn eq(&self, other: &Error) -> bool {
19-
self == other
19+
match (self, other) {
20+
(Error::Parse(a), Error::Parse(b)) => a == b,
21+
(Error::Shred(a), Error::Shred(b)) => a == b,
22+
(Error::Rocks(a), Error::Rocks(b)) => a.to_string() == b.to_string(),
23+
(Error::Write(a), Error::Write(b)) => a == b,
24+
(Error::Io(a), Error::Io(b)) => a.to_string() == b.to_string(),
25+
_ => false,
26+
}
2027
}
2128
}
2229

src/filters.rs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::BTreeMap;
55
use std::collections::HashSet;
66
use std::io::Cursor;
77
use std::rc::Rc;
8-
use std::{self, mem, str};
8+
use std::{self, str};
99

1010
use self::varint::VarintRead;
1111

@@ -314,15 +314,15 @@ impl ExactMatchFilter {
314314

315315
if let Some((key, value)) = self.iter.next() {
316316
debug_assert!(key.starts_with(value_key.as_bytes())); // must always be true!
317-
if let JsonValue::String(string) = JsonFetcher::bytes_to_json_value(&*value) {
317+
if let JsonValue::String(string) = JsonFetcher::bytes_to_json_value(&value) {
318318
let matches = if self.case_sensitive {
319319
self.phrase == string
320320
} else {
321321
self.phrase == string.to_lowercase()
322322
};
323323
if matches {
324-
if self.term_ordinal.is_some() {
325-
dr.add_score(self.term_ordinal.unwrap(), 1.0);
324+
if let Some(to) = self.term_ordinal {
325+
dr.add_score(to, 1.0);
326326
}
327327
return Some(dr);
328328
} else {
@@ -444,16 +444,16 @@ impl QueryRuntimeFilter for RangeFilter {
444444
|| self.min == Some(RangeOperator::Null)
445445
{
446446
let mut dr = KeyBuilder::parse_doc_result_from_kp_word_key(key_str);
447-
if self.term_ordinal.is_some() {
448-
dr.add_score(self.term_ordinal.unwrap(), 1.0);
447+
if let Some(to) = self.term_ordinal {
448+
dr.add_score(to, 1.0);
449449
}
450450
return Some(dr);
451451
}
452452
// Else it's a range query on numbers
453453

454454
let number = unsafe {
455455
let array = *(value[..].as_ptr() as *const [_; 8]);
456-
mem::transmute::<[u8; 8], f64>(array)
456+
f64::from_ne_bytes(array)
457457
};
458458

459459
let min_condition = match self.min {
@@ -473,8 +473,8 @@ impl QueryRuntimeFilter for RangeFilter {
473473

474474
if min_condition && max_condition {
475475
let mut dr = KeyBuilder::parse_doc_result_from_kp_word_key(key_str);
476-
if self.term_ordinal.is_some() {
477-
dr.add_score(self.term_ordinal.unwrap(), 1.0);
476+
if let Some(to) = self.term_ordinal {
477+
dr.add_score(to, 1.0);
478478
}
479479
return Some(dr);
480480
}
@@ -538,9 +538,7 @@ impl<'a> BboxFilter<'a> {
538538

539539
impl<'a> QueryRuntimeFilter for BboxFilter<'a> {
540540
fn first_result(&mut self, start: &DocResult) -> Option<DocResult> {
541-
let query = self
542-
.kb
543-
.rtree_query_key(start.seq, std::u64::MAX, &self.bbox);
541+
let query = self.kb.rtree_query_key(start.seq, u64::MAX, &self.bbox);
544542
self.iter = Some(self.snapshot.new_rtree_iterator(&query));
545543
self.next_result()
546544
}
@@ -556,14 +554,14 @@ impl<'a> QueryRuntimeFilter for BboxFilter<'a> {
556554

557555
let iid = unsafe {
558556
let array = *(key[offset + key_len as usize..].as_ptr() as *const [_; 8]);
559-
mem::transmute::<[u8; 8], u64>(array)
557+
u64::from_ne_bytes(array)
560558
};
561559

562560
let mut dr = DocResult::new();
563561
dr.seq = iid;
564562
dr.arraypath = BboxFilter::from_u8_slice(&value);
565-
if self.term_ordinal.is_some() {
566-
dr.add_score(self.term_ordinal.unwrap(), 1.0);
563+
if let Some(to) = self.term_ordinal {
564+
dr.add_score(to, 1.0);
567565
}
568566
Some(dr)
569567
} else {
@@ -828,32 +826,22 @@ impl<'a> FilterWithResult<'a> {
828826
if self.result.is_none() || self.result.as_ref().unwrap().less(start, self.array_depth) {
829827
self.result = self.filter.first_result(start);
830828
}
831-
if self.result.is_none() {
832-
self.is_done = true;
833-
} else {
834-
self.result
835-
.as_mut()
836-
.unwrap()
837-
.arraypath
838-
.resize(self.array_depth, 0);
829+
match self.result.as_mut() {
830+
Some(result) => result.arraypath.resize(self.array_depth, 0),
831+
None => self.is_done = true,
839832
}
840833
}
841834

842835
fn prime_next_result(&mut self) {
843836
if self.is_done {
844837
return;
845838
}
846-
if self.result.is_none() {
847-
self.result = self.filter.next_result();
848-
}
849-
if self.result.is_none() {
850-
self.is_done = true;
851-
} else {
852-
self.result
853-
.as_mut()
854-
.unwrap()
855-
.arraypath
856-
.resize(self.array_depth, 0);
839+
match self.result.as_mut() {
840+
Some(result) => result.arraypath.resize(self.array_depth, 0),
841+
None => {
842+
self.is_done = true;
843+
self.result = self.filter.next_result();
844+
}
857845
}
858846
}
859847
}

src/index.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Index {
119119
&self.name
120120
}
121121

122-
pub fn new_snapshot(&self) -> Snapshot {
122+
pub fn new_snapshot(&self) -> Snapshot<'_> {
123123
Snapshot::new(RocksSnapshot::new(&self.rocks))
124124
}
125125

@@ -179,7 +179,11 @@ impl Index {
179179
}
180180

181181
/// Query the index with the string and use the parameters for values if passed.
182-
pub fn query(&self, query: &str, parameters: Option<String>) -> Result<QueryResults, Error> {
182+
pub fn query(
183+
&self,
184+
query: &str,
185+
parameters: Option<String>,
186+
) -> Result<QueryResults<'_>, Error> {
183187
QueryResults::new_query_results(query, parameters, self.new_snapshot())
184188
}
185189

@@ -239,7 +243,7 @@ impl Index {
239243
for (n, b) in bytes.iter().enumerate() {
240244
buffer[n] = *b;
241245
}
242-
unsafe { mem::transmute(buffer) }
246+
u64::from_ne_bytes(buffer)
243247
}
244248

245249
pub fn convert_bytes_to_i32(bytes: &[u8]) -> i32 {
@@ -354,11 +358,11 @@ impl Index {
354358
// Keypaths are the same, compare the Internal Ids value
355359
let seq_aa = unsafe {
356360
let array = *(aa[(offset_aa)..].as_ptr() as *const [_; 8]);
357-
mem::transmute::<[u8; 8], u64>(array)
361+
u64::from_ne_bytes(array)
358362
};
359363
let seq_bb = unsafe {
360364
let array = *(bb[(offset_bb)..].as_ptr() as *const [_; 8]);
361-
mem::transmute::<[u8; 8], u64>(array)
365+
u64::from_ne_bytes(array)
362366
};
363367
let seq_compare = seq_aa.cmp(&seq_bb);
364368
if seq_compare != Ordering::Equal {
@@ -406,7 +410,7 @@ impl<T> MvccRwLock<T> {
406410
unsafe { &*self.raw }
407411
}
408412

409-
pub fn write(&self) -> LockResult<MutexGuard<Box<T>>> {
413+
pub fn write(&self) -> LockResult<MutexGuard<'_, Box<T>>> {
410414
self.lock.lock()
411415
}
412416
}
@@ -503,7 +507,7 @@ mod tests {
503507
for (key, value) in index.rocks.iterator(rocksdb::IteratorMode::Start) {
504508
if key[0] as char == 'V' {
505509
let key_string = unsafe { str::from_utf8_unchecked(&key) }.to_string();
506-
results.push((key_string, JsonFetcher::bytes_to_json_value(&*value)));
510+
results.push((key_string, JsonFetcher::bytes_to_json_value(&value)));
507511
}
508512
}
509513

@@ -532,7 +536,7 @@ mod tests {
532536
for (key, value) in index.rocks.iterator(rocksdb::IteratorMode::Start) {
533537
if key[0] as char == 'V' {
534538
let key_string = unsafe { str::from_utf8_unchecked(&key) }.to_string();
535-
results.push((key_string, JsonFetcher::bytes_to_json_value(&*value)));
539+
results.push((key_string, JsonFetcher::bytes_to_json_value(&value)));
536540
}
537541
}
538542
let expected = vec![

src/json_shred.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ impl Shredder {
8282
// Based on https://stackoverflow.com/questions/29037033/how-to-slice-a-large-veci32-as-u8
8383
// (2017-07-26)
8484
fn as_u8_slice(v: &[u64]) -> &[u8] {
85-
unsafe {
86-
std::slice::from_raw_parts(
87-
v.as_ptr() as *const u8,
88-
v.len() * std::mem::size_of::<u64>(),
89-
)
90-
}
85+
unsafe { std::slice::from_raw_parts(v.as_ptr() as *const u8, std::mem::size_of_val(v)) }
9186
}
9287

9388
fn add_rtree_entries(
@@ -492,7 +487,7 @@ impl Shredder {
492487
loop {
493488
// Get the next token, so that in case of an `ObjectStart` the key is already
494489
// on the stack.
495-
match parser.next().take() {
490+
match parser.next() {
496491
Some(JsonEvent::ObjectStart) => {
497492
self.maybe_push_key(parser.stack().top())?;
498493
// Just push something to make `ObjectEnd` happy
@@ -618,7 +613,7 @@ mod tests {
618613
for (key, value) in rocks.iterator(rocksdb::IteratorMode::Start) {
619614
if key[0] as char == 'V' {
620615
let key_string = unsafe { str::from_utf8_unchecked(&key) }.to_string();
621-
result.push((key_string, JsonFetcher::bytes_to_json_value(&*value)));
616+
result.push((key_string, JsonFetcher::bytes_to_json_value(&value)));
622617
}
623618
}
624619
result

src/json_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl JsonValue {
167167
pretty.push();
168168

169169
let mut iter = object.iter().peekable();
170-
while let Some(&(ref key, ref json)) = iter.next() {
170+
while let Some((key, json)) = iter.next() {
171171
write.write_all(pretty.prefix())?;
172172
write.write_all(JsonValue::str_to_literal(key).as_bytes())?;
173173
write.write_all(":".as_bytes())?;

src/key_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl KeyBuilder {
365365
Some('$') => {
366366
let mut i = String::new();
367367
for c in chars {
368-
if ('0'..='9').contains(&c) {
368+
if c.is_ascii_digit() {
369369
i.push(c);
370370
} else {
371371
break;

0 commit comments

Comments
 (0)