Skip to content

Commit d4023f2

Browse files
author
Oleksandr Anyshchenko
authored
Add clippy linter in CI (rust-rocksdb#417)
1 parent 8f7124b commit d4023f2

31 files changed

+218
-179
lines changed

.travis.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ dist: bionic
44
os:
55
- linux
66
- osx
7-
- windows
87

98
rust:
109
- stable
1110

12-
jobs:
13-
allow_failures:
14-
- os: windows
15-
1611
install:
1712
- rustup component add rustfmt
1813
- rustfmt -V
14+
- rustup component add clippy
15+
- cargo clippy --version
1916

2017
script:
21-
- cargo fmt --all -- --check
22-
- cargo test --manifest-path=librocksdb-sys/Cargo.toml
23-
- cargo test -- --skip test_iterator_outlive_db
18+
- .travis/lints.sh
19+
- .travis/tests.sh

.travis/lints.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# Run cargo fmt and cargo clippy only on OSX host
4+
5+
if [[ ${TRAVIS_OS_NAME} == "osx" ]]; then
6+
cargo fmt --all -- --check
7+
cargo clippy --all --tests -- -D warnings
8+
fi

.travis/tests.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
cargo test --manifest-path=librocksdb-sys/Cargo.toml
4+
cargo test -- --skip test_iterator_outlive_db

LICENSE

+1-5
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2014 Tyler Neely
191-
Copyright 2015 Tyler Neely
192-
Copyright 2016 Tyler Neely
193-
Copyright 2017 Tyler Neely
194-
Copyright 2018 Tyler Neely
190+
Copyright [yyyy] [name of copyright owner]
195191

196192
Licensed under the Apache License, Version 2.0 (the "License");
197193
you may not use this file except in compliance with the License.

librocksdb-sys/build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ fn build_rocksdb() {
183183
fn build_snappy() {
184184
let target = env::var("TARGET").unwrap();
185185
let endianness = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap();
186-
187186
let mut config = cc::Build::new();
187+
188188
config.include("snappy/");
189189
config.include(".");
190-
191190
config.define("NDEBUG", Some("1"));
191+
config.extra_warnings(false);
192192

193193
if target.contains("msvc") {
194194
config.flag("-EHsc");
@@ -250,6 +250,7 @@ fn build_zstd() {
250250
}
251251

252252
compiler.opt_level(3);
253+
compiler.extra_warnings(false);
253254

254255
compiler.define("ZSTD_LIB_DEPRECATED", Some("0"));
255256
compiler.compile("libzstd.a");
@@ -269,6 +270,7 @@ fn build_zlib() {
269270

270271
compiler.flag_if_supported("-Wno-implicit-function-declaration");
271272
compiler.opt_level(3);
273+
compiler.extra_warnings(false);
272274
compiler.compile("libz.a");
273275
}
274276

@@ -290,6 +292,7 @@ fn build_bzip2() {
290292

291293
compiler.extra_warnings(false);
292294
compiler.opt_level(3);
295+
compiler.extra_warnings(false);
293296
compiler.compile("libbz2.a");
294297
}
295298

librocksdb-sys/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Tyler Neely, Alex Regueiro
1+
// Copyright 2020 Tyler Neely, Alex Regueiro
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![allow(clippy::all)]
1516
#![allow(non_camel_case_types)]
1617
#![allow(non_snake_case)]
1718
#![allow(non_upper_case_globals)]

librocksdb-sys/src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Tyler Neely
1+
// Copyright 2020 Tyler Neely
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

src/backup.rs

+21-24
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ impl BackupEngine {
3838
path: P,
3939
) -> Result<BackupEngine, Error> {
4040
let path = path.as_ref();
41-
let cpath = match CString::new(path.to_string_lossy().as_bytes()) {
42-
Ok(c) => c,
43-
Err(_) => {
44-
return Err(Error::new(
45-
"Failed to convert path to CString \
41+
let cpath = if let Ok(e) = CString::new(path.to_string_lossy().as_bytes()) {
42+
e
43+
} else {
44+
return Err(Error::new(
45+
"Failed to convert path to CString \
4646
when opening backup engine"
47-
.to_owned(),
48-
));
49-
}
47+
.to_owned(),
48+
));
5049
};
5150

5251
let be: *mut ffi::rocksdb_backup_engine_t;
@@ -107,27 +106,25 @@ impl BackupEngine {
107106
opts: &RestoreOptions,
108107
) -> Result<(), Error> {
109108
let db_dir = db_dir.as_ref();
110-
let c_db_dir = match CString::new(db_dir.to_string_lossy().as_bytes()) {
111-
Ok(c) => c,
112-
Err(_) => {
113-
return Err(Error::new(
114-
"Failed to convert db_dir to CString \
109+
let c_db_dir = if let Ok(c) = CString::new(db_dir.to_string_lossy().as_bytes()) {
110+
c
111+
} else {
112+
return Err(Error::new(
113+
"Failed to convert db_dir to CString \
115114
when restoring from latest backup"
116-
.to_owned(),
117-
));
118-
}
115+
.to_owned(),
116+
));
119117
};
120118

121119
let wal_dir = wal_dir.as_ref();
122-
let c_wal_dir = match CString::new(wal_dir.to_string_lossy().as_bytes()) {
123-
Ok(c) => c,
124-
Err(_) => {
125-
return Err(Error::new(
126-
"Failed to convert wal_dir to CString \
120+
let c_wal_dir = if let Ok(c) = CString::new(wal_dir.to_string_lossy().as_bytes()) {
121+
c
122+
} else {
123+
return Err(Error::new(
124+
"Failed to convert wal_dir to CString \
127125
when restoring from latest backup"
128-
.to_owned(),
129-
));
130-
}
126+
.to_owned(),
127+
));
131128
};
132129

133130
unsafe {

src/checkpoint.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ impl Checkpoint {
5050
/// Creates new physical DB checkpoint in directory specified by `path`.
5151
pub fn create_checkpoint<P: AsRef<Path>>(&self, path: P) -> Result<(), Error> {
5252
let path = path.as_ref();
53-
let cpath = match CString::new(path.to_string_lossy().as_bytes()) {
54-
Ok(c) => c,
55-
Err(_) => {
56-
return Err(Error::new(
57-
"Failed to convert path to CString when creating DB checkpoint".to_owned(),
58-
));
59-
}
53+
let cpath = if let Ok(c) = CString::new(path.to_string_lossy().as_bytes()) {
54+
c
55+
} else {
56+
return Err(Error::new(
57+
"Failed to convert path to CString when creating DB checkpoint".to_owned(),
58+
));
6059
};
6160

6261
unsafe {

src/compaction_filter.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Tyler Neely
1+
// Copyright 2020 Tyler Neely
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -41,12 +41,7 @@ pub enum Decision {
4141
///
4242
/// [set_compaction_filter]: ../struct.Options.html#method.set_compaction_filter
4343
pub trait CompactionFilterFn: FnMut(u32, &[u8], &[u8]) -> Decision {}
44-
impl<F> CompactionFilterFn for F
45-
where
46-
F: FnMut(u32, &[u8], &[u8]) -> Decision,
47-
F: Send + 'static,
48-
{
49-
}
44+
impl<F> CompactionFilterFn for F where F: FnMut(u32, &[u8], &[u8]) -> Decision + Send + 'static {}
5045

5146
pub struct CompactionFilterCallback<F>
5247
where
@@ -85,7 +80,7 @@ pub unsafe extern "C" fn filter_callback<F>(
8580
where
8681
F: CompactionFilterFn,
8782
{
88-
use self::Decision::*;
83+
use self::Decision::{Change, Keep, Remove};
8984

9085
let cb = &mut *(raw_cb as *mut CompactionFilterCallback<F>);
9186
let key = slice::from_raw_parts(raw_key as *const u8, key_length as usize);
@@ -106,7 +101,7 @@ where
106101
#[cfg(test)]
107102
#[allow(unused_variables)]
108103
fn test_filter(level: u32, key: &[u8], value: &[u8]) -> Decision {
109-
use self::Decision::*;
104+
use self::Decision::{Change, Keep, Remove};
110105
match key.first() {
111106
Some(&b'_') => Remove,
112107
Some(&b'%') => Change(b"secret"),

src/comparator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 Tyler Neely
1+
// Copyright 2020 Tyler Neely
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)