Skip to content

Commit

Permalink
clippy: Fixing up clippy errors. (tikv#11193)
Browse files Browse the repository at this point in the history
* clippy: Fixing up clippy errors.

* Fix crate references
* Fix anonymous lifetimes references.

ref tikv#4301
Signed-off-by: Harold Dost <[email protected]>

* Test Revert of Iterations

ref tikv#4301

Signed-off-by: Harold Dost <[email protected]>

* clippy: Enable check for rust-2018-idioms

ref tikv#4301

Signed-off-by: Harold Dost <[email protected]>
  • Loading branch information
hdost authored Dec 22, 2021
1 parent b65491b commit 0655769
Show file tree
Hide file tree
Showing 134 changed files with 428 additions and 374 deletions.
2 changes: 1 addition & 1 deletion components/backup/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ pub mod tests {
// the case.2 is the expected results.
type Case<'a> = (&'a [u8], &'a [u8], Vec<(&'a [u8], &'a [u8])>);

let case: Vec<Case> = vec![
let case: Vec<Case<'_>> = vec![
(b"", b"1", vec![(b"", b"1")]),
(b"", b"2", vec![(b"", b"1"), (b"1", b"2")]),
(b"1", b"2", vec![(b"1", b"2")]),
Expand Down
2 changes: 1 addition & 1 deletion components/backup/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Service {
impl Backup for Service {
fn backup(
&mut self,
ctx: RpcContext,
ctx: RpcContext<'_>,
req: BackupRequest,
mut sink: ServerStreamingSink<BackupResponse>,
) {
Expand Down
2 changes: 1 addition & 1 deletion components/backup/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ mod tests {

type CfKvs<'a> = (engine_traits::CfName, &'a [(&'a [u8], &'a [u8])]);

fn check_sst(ssts: &[(engine_traits::CfName, &Path)], kvs: &[CfKvs]) {
fn check_sst(ssts: &[(engine_traits::CfName, &Path)], kvs: &[CfKvs<'_>]) {
let temp = TempDir::new().unwrap();
let rocks = TestEngineBuilder::new()
.path(temp.path())
Expand Down
2 changes: 0 additions & 2 deletions components/batch-system/benches/batch-system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#![feature(test)]

extern crate test;

use batch_system::test_runner::*;
use batch_system::*;
use criterion::*;
Expand Down
1 change: 0 additions & 1 deletion components/case_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.

//! Procedural macros used for case conversion.
extern crate proc_macro;
use proc_macro::{Group, Literal, TokenStream, TokenTree};

Expand Down
2 changes: 1 addition & 1 deletion components/cdc/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Service {
impl ChangeData for Service {
fn event_feed(
&mut self,
ctx: RpcContext,
ctx: RpcContext<'_>,
stream: RequestStream<ChangeDataRequest>,
mut sink: DuplexSink<ChangeDataEvent>,
) {
Expand Down
2 changes: 1 addition & 1 deletion components/coprocessor_plugin_api/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum PluginError {
}

impl fmt::Display for PluginError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PluginError::KeyNotInRegion { key, region_id, .. } => {
write!(f, "Key {:?} not found in region {:?}", key, region_id)
Expand Down
2 changes: 1 addition & 1 deletion components/encryption/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod encryption_method_serde {
impl<'de> Visitor<'de> for EncryptionMethodVisitor {
type Value = EncryptionMethod;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "valid encryption method")
}

Expand Down
22 changes: 11 additions & 11 deletions components/encryption/src/file_dict_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::path::{Path, PathBuf};

#[derive(Debug)]
enum LogRecord {
INSERT(FileInfo),
REMOVE,
Insert(FileInfo),
Remove,
}

/// FileDictionaryFile is used to store log style file dictionary.
Expand All @@ -43,7 +43,7 @@ pub struct FileDictionaryFile {
enable_log: bool,
// Determine whether compact the log.
file_rewrite_threshold: u64,
// Record the number of `REMOVE` to determine whether compact the log.
// Record the number of `Remove` to determine whether compact the log.
removed: u64,
// Record size of the file.
file_size: usize,
Expand Down Expand Up @@ -179,10 +179,10 @@ impl FileDictionaryFile {
remained.consume(used_size);
last_record_name = file_name.clone();
match mode {
LogRecord::INSERT(info) => {
LogRecord::Insert(info) => {
file_dict.files.insert(file_name, info);
}
LogRecord::REMOVE => {
LogRecord::Remove => {
let original = file_dict.files.remove(&file_name);
if original.is_none() {
return Err(box_err!(
Expand Down Expand Up @@ -221,7 +221,7 @@ impl FileDictionaryFile {
self.file_dict.files.insert(name.to_owned(), info.clone());
if self.enable_log {
let file = self.append_file.as_mut().unwrap();
let bytes = Self::convert_record_to_bytes(name, LogRecord::INSERT(info.clone()))?;
let bytes = Self::convert_record_to_bytes(name, LogRecord::Insert(info.clone()))?;

fail::fail_point!("file_dict_log_append_incomplete", |truncate_num| {
let mut bytes = bytes.clone();
Expand Down Expand Up @@ -251,7 +251,7 @@ impl FileDictionaryFile {
self.file_dict.files.remove(name);
if self.enable_log {
let file = self.append_file.as_mut().unwrap();
let bytes = Self::convert_record_to_bytes(name, LogRecord::REMOVE)?;
let bytes = Self::convert_record_to_bytes(name, LogRecord::Remove)?;
file.write_all(&bytes)?;
file.sync_all()?;

Expand Down Expand Up @@ -282,13 +282,13 @@ impl FileDictionaryFile {

let mut header_buf = [0; Self::RECORD_HEADER_SIZE];
let info_len = match record_type {
LogRecord::INSERT(info) => {
LogRecord::Insert(info) => {
header_buf[Self::RECORD_HEADER_SIZE - 1] = 1;
let info_bytes = info.write_to_bytes()?;
content.extend_from_slice(&info_bytes);
info_bytes.len() as u16
}
LogRecord::REMOVE => {
LogRecord::Remove => {
header_buf[Self::RECORD_HEADER_SIZE - 1] = 2;
0
}
Expand Down Expand Up @@ -363,11 +363,11 @@ impl FileDictionaryFile {
// return result
let used_size = Self::RECORD_HEADER_SIZE + name_len + info_len;
let record = match mode {
2 => LogRecord::REMOVE,
2 => LogRecord::Remove,
1 => {
let mut file_info = FileInfo::default();
file_info.merge_from_bytes(&remained[0..info_len])?;
LogRecord::INSERT(file_info)
LogRecord::Insert(file_info)
}
_ => return Err(box_err!("file corrupted! record type is unknown: {}", mode)),
};
Expand Down
18 changes: 15 additions & 3 deletions components/encryption/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ impl<R: Seek> Seek for EncrypterReader<R> {

impl<R: AsyncRead + Unpin> AsyncRead for EncrypterReader<R> {
#[inline]
fn poll_read(self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<IoResult<usize>> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<IoResult<usize>> {
unsafe { self.map_unchecked_mut(|r| &mut r.0) }.poll_read(cx, buf)
}
}
Expand Down Expand Up @@ -96,7 +100,11 @@ impl<R: Seek> Seek for DecrypterReader<R> {

impl<R: AsyncRead + Unpin> AsyncRead for DecrypterReader<R> {
#[inline]
fn poll_read(self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<IoResult<usize>> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<IoResult<usize>> {
unsafe { self.map_unchecked_mut(|r| &mut r.0) }.poll_read(cx, buf)
}
}
Expand Down Expand Up @@ -252,7 +260,11 @@ impl<R: Seek> Seek for CrypterReader<R> {

impl<R: AsyncRead + Unpin> AsyncRead for CrypterReader<R> {
#[inline]
fn poll_read(self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<IoResult<usize>> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<IoResult<usize>> {
let inner = Pin::into_inner(self);
let poll = Pin::new(&mut inner.reader).poll_read(cx, buf);
let read_count = match poll {
Expand Down
4 changes: 2 additions & 2 deletions components/engine_panic/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ impl Iterable for PanicEngine {
pub struct PanicEngineIterator;

impl Iterator for PanicEngineIterator {
fn seek(&mut self, key: SeekKey) -> Result<bool> {
fn seek(&mut self, key: SeekKey<'_>) -> Result<bool> {
panic!()
}
fn seek_for_prev(&mut self, key: SeekKey) -> Result<bool> {
fn seek_for_prev(&mut self, key: SeekKey<'_>) -> Result<bool> {
panic!()
}

Expand Down
9 changes: 7 additions & 2 deletions components/engine_panic/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ impl MiscExt for PanicEngine {
panic!()
}

fn delete_ranges_cf(&self, cf: &str, strategy: DeleteStrategy, ranges: &[Range]) -> Result<()> {
fn delete_ranges_cf(
&self,
cf: &str,
strategy: DeleteStrategy,
ranges: &[Range<'_>],
) -> Result<()> {
panic!()
}

fn get_approximate_memtable_stats_cf(&self, cf: &str, range: &Range) -> Result<(u64, u64)> {
fn get_approximate_memtable_stats_cf(&self, cf: &str, range: &Range<'_>) -> Result<(u64, u64)> {
panic!()
}

Expand Down
12 changes: 6 additions & 6 deletions components/engine_panic/src/range_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ use crate::engine::PanicEngine;
use engine_traits::{Range, RangePropertiesExt, Result};

impl RangePropertiesExt for PanicEngine {
fn get_range_approximate_keys(&self, range: Range, large_threshold: u64) -> Result<u64> {
fn get_range_approximate_keys(&self, range: Range<'_>, large_threshold: u64) -> Result<u64> {
panic!()
}

fn get_range_approximate_keys_cf(
&self,
cfname: &str,
range: Range,
range: Range<'_>,
large_threshold: u64,
) -> Result<u64> {
panic!()
}

fn get_range_approximate_size(&self, range: Range, large_threshold: u64) -> Result<u64> {
fn get_range_approximate_size(&self, range: Range<'_>, large_threshold: u64) -> Result<u64> {
panic!()
}

fn get_range_approximate_size_cf(
&self,
cfname: &str,
range: Range,
range: Range<'_>,
large_threshold: u64,
) -> Result<u64> {
panic!()
}

fn get_range_approximate_split_keys(
&self,
range: Range,
range: Range<'_>,
key_count: usize,
) -> Result<Vec<Vec<u8>>> {
panic!()
Expand All @@ -41,7 +41,7 @@ impl RangePropertiesExt for PanicEngine {
fn get_range_approximate_split_keys_cf(
&self,
cfname: &str,
range: Range,
range: Range<'_>,
key_count: usize,
) -> Result<Vec<Vec<u8>>> {
panic!()
Expand Down
4 changes: 2 additions & 2 deletions components/engine_panic/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl Iterable for PanicSnapshot {
pub struct PanicSnapshotIterator;

impl Iterator for PanicSnapshotIterator {
fn seek(&mut self, key: SeekKey) -> Result<bool> {
fn seek(&mut self, key: SeekKey<'_>) -> Result<bool> {
panic!()
}
fn seek_for_prev(&mut self, key: SeekKey) -> Result<bool> {
fn seek_for_prev(&mut self, key: SeekKey<'_>) -> Result<bool> {
panic!()
}

Expand Down
4 changes: 2 additions & 2 deletions components/engine_panic/src/sst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ impl Iterable for PanicSstReader {
pub struct PanicSstReaderIterator;

impl Iterator for PanicSstReaderIterator {
fn seek(&mut self, key: SeekKey) -> Result<bool> {
fn seek(&mut self, key: SeekKey<'_>) -> Result<bool> {
panic!()
}
fn seek_for_prev(&mut self, key: SeekKey) -> Result<bool> {
fn seek_for_prev(&mut self, key: SeekKey<'_>) -> Result<bool> {
panic!()
}

Expand Down
2 changes: 1 addition & 1 deletion components/engine_panic/src/table_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl engine_traits::TablePropertiesExt for PanicEngine {
fn table_properties_collection(
&self,
cf: &str,
ranges: &[Range],
ranges: &[Range<'_>],
) -> Result<Self::TablePropertiesCollection> {
panic!()
}
Expand Down
4 changes: 2 additions & 2 deletions components/engine_rocks/src/compact_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct RocksCompactedEvent {

impl RocksCompactedEvent {
pub fn new(
info: &RocksCompactionJobInfo,
info: &RocksCompactionJobInfo<'_>,
start_key: Vec<u8>,
end_key: Vec<u8>,
input_props: Vec<RangeProperties>,
Expand Down Expand Up @@ -197,7 +197,7 @@ impl CompactedEvent for RocksCompactedEvent {
}
}

pub type Filter = fn(&RocksCompactionJobInfo) -> bool;
pub type Filter = fn(&RocksCompactionJobInfo<'_>) -> bool;

pub struct CompactionListener {
ch: Box<dyn Fn(RocksCompactedEvent) + Send + Sync>,
Expand Down
2 changes: 1 addition & 1 deletion components/engine_rocks/src/db_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Deref for RocksDBVector {
}

impl Debug for RocksDBVector {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
write!(formatter, "{:?}", &**self)
}
}
Expand Down
8 changes: 4 additions & 4 deletions components/engine_rocks/src/engine_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ impl RocksEngineIterator {
}

impl engine_traits::Iterator for RocksEngineIterator {
fn seek(&mut self, key: engine_traits::SeekKey) -> Result<bool> {
let k: RocksSeekKey = key.into();
fn seek(&mut self, key: engine_traits::SeekKey<'_>) -> Result<bool> {
let k: RocksSeekKey<'_> = key.into();
self.0.seek(k.into_raw()).map_err(Error::Engine)
}

fn seek_for_prev(&mut self, key: engine_traits::SeekKey) -> Result<bool> {
let k: RocksSeekKey = key.into();
fn seek_for_prev(&mut self, key: engine_traits::SeekKey<'_>) -> Result<bool> {
let k: RocksSeekKey<'_> = key.into();
self.0.seek_for_prev(k.into_raw()).map_err(Error::Engine)
}

Expand Down
Loading

0 comments on commit 0655769

Please sign in to comment.