Skip to content

Commit 8f5bfb1

Browse files
authored
Enable our standard lints (#28)
Enables our standard lints from EmbarkStudios/rust-ecosystem#59 and fixes up the code for it. Pretty trivial changes.
1 parent a959916 commit 8f5bfb1

File tree

18 files changed

+138
-49
lines changed

18 files changed

+138
-49
lines changed

.cargo/config.toml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# add the below section to `.cargo/config.toml`
2+
3+
[target.'cfg(all())']
4+
rustflags = [
5+
# BEGIN - Embark standard lints v6 for Rust 1.55+
6+
# do not change or add/remove here, but one can add exceptions after this section
7+
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
8+
"-Dunsafe_code",
9+
"-Wclippy::all",
10+
"-Wclippy::await_holding_lock",
11+
"-Wclippy::char_lit_as_u8",
12+
"-Wclippy::checked_conversions",
13+
"-Wclippy::dbg_macro",
14+
"-Wclippy::debug_assert_with_mut_call",
15+
"-Wclippy::doc_markdown",
16+
"-Wclippy::empty_enum",
17+
"-Wclippy::enum_glob_use",
18+
"-Wclippy::exit",
19+
"-Wclippy::expl_impl_clone_on_copy",
20+
"-Wclippy::explicit_deref_methods",
21+
"-Wclippy::explicit_into_iter_loop",
22+
"-Wclippy::fallible_impl_from",
23+
"-Wclippy::filter_map_next",
24+
"-Wclippy::flat_map_option",
25+
"-Wclippy::float_cmp_const",
26+
"-Wclippy::fn_params_excessive_bools",
27+
"-Wclippy::from_iter_instead_of_collect",
28+
"-Wclippy::if_let_mutex",
29+
"-Wclippy::implicit_clone",
30+
"-Wclippy::imprecise_flops",
31+
"-Wclippy::inefficient_to_string",
32+
"-Wclippy::invalid_upcast_comparisons",
33+
"-Wclippy::large_digit_groups",
34+
"-Wclippy::large_stack_arrays",
35+
"-Wclippy::large_types_passed_by_value",
36+
"-Wclippy::let_unit_value",
37+
"-Wclippy::linkedlist",
38+
"-Wclippy::lossy_float_literal",
39+
"-Wclippy::macro_use_imports",
40+
"-Wclippy::manual_ok_or",
41+
"-Wclippy::map_err_ignore",
42+
"-Wclippy::map_flatten",
43+
"-Wclippy::map_unwrap_or",
44+
"-Wclippy::match_on_vec_items",
45+
"-Wclippy::match_same_arms",
46+
"-Wclippy::match_wild_err_arm",
47+
"-Wclippy::match_wildcard_for_single_variants",
48+
"-Wclippy::mem_forget",
49+
"-Wclippy::mismatched_target_os",
50+
"-Wclippy::missing_enforced_import_renames",
51+
"-Wclippy::mut_mut",
52+
"-Wclippy::mutex_integer",
53+
"-Wclippy::needless_borrow",
54+
"-Wclippy::needless_continue",
55+
"-Wclippy::needless_for_each",
56+
"-Wclippy::option_option",
57+
"-Wclippy::path_buf_push_overwrite",
58+
"-Wclippy::ptr_as_ptr",
59+
"-Wclippy::rc_mutex",
60+
"-Wclippy::ref_option_ref",
61+
"-Wclippy::rest_pat_in_fully_bound_structs",
62+
"-Wclippy::same_functions_in_if_condition",
63+
"-Wclippy::semicolon_if_nothing_returned",
64+
"-Wclippy::single_match_else",
65+
"-Wclippy::string_add_assign",
66+
"-Wclippy::string_add",
67+
"-Wclippy::string_lit_as_bytes",
68+
"-Wclippy::string_to_string",
69+
"-Wclippy::todo",
70+
"-Wclippy::trait_duplication_in_bounds",
71+
"-Wclippy::unimplemented",
72+
"-Wclippy::unnested_or_patterns",
73+
"-Wclippy::unused_self",
74+
"-Wclippy::useless_transmute",
75+
"-Wclippy::verbose_file_reads",
76+
"-Wclippy::zero_sized_map_values",
77+
"-Wfuture_incompatible",
78+
"-Wnonstandard_style",
79+
"-Wrust_2018_idioms",
80+
# END - Embark standard lints v6 for Rust 1.55+
81+
]

crates/cervo-asset/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::io::{Cursor, Read, Write};
2626
/// Magic used to ensure assets are valid.
2727
pub const MAGIC: [u8; 4] = [b'C', b'R', b'V', b'O'];
2828

29-
/// AssetKind denotes what kind of policy is contained inside an [`AssetData`].
29+
/// `AssetKind` denotes what kind of policy is contained inside an [`AssetData`].
3030
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3131
#[repr(u8)]
3232
pub enum AssetKind {
@@ -66,7 +66,7 @@ pub struct AssetData {
6666
}
6767

6868
impl AssetData {
69-
/// Create a new AssetData from parts.
69+
/// Create a new `AssetData` from parts.
7070
///
7171
/// Note: Does not validate the data.
7272
pub fn new<Data: Into<Vec<u8>>>(kind: AssetKind, data: Data) -> Self {
@@ -76,7 +76,7 @@ impl AssetData {
7676
}
7777
}
7878

79-
/// Create a new AssetData from a reader and a kind.
79+
/// Create a new `AssetData` from a reader and a kind.
8080
///
8181
/// Note: Does not validate the data.
8282
pub fn from_reader<Reader: Read>(kind: AssetKind, mut reader: Reader) -> Result<Self> {
@@ -146,7 +146,7 @@ impl AssetData {
146146

147147
/// Load a simple unbatching inferer from this asset.
148148
///
149-
/// See ['BasicInferer'] for more details.
149+
/// See ['`BasicInferer`'] for more details.
150150
pub fn load_basic(&self) -> Result<BasicInferer> {
151151
let mut cursor = Cursor::new(&self.data);
152152
match self.kind {

crates/cervo-asset/tests/helpers.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ pub fn get_file(name: &'static str) -> std::io::Result<File> {
2020
std::fs::File::open(path)
2121
}
2222

23-
pub fn build_inputs_from_desc(count: u64, inputs: &[(String, Vec<usize>)]) -> HashMap<u64, State> {
23+
pub fn build_inputs_from_desc(
24+
count: u64,
25+
inputs: &[(String, Vec<usize>)],
26+
) -> HashMap<u64, State<'_>> {
2427
(0..count)
2528
.map(|idx| {
2629
(

crates/cervo-core/src/batcher.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ impl Batcher {
117117
}
118118
}
119119

120-
Ok(HashMap::from_iter(
121-
self.scratch.ids.drain(..).zip(outputs.into_iter()),
122-
))
120+
Ok(self
121+
.scratch
122+
.ids
123+
.drain(..)
124+
.zip(outputs.into_iter())
125+
.collect::<_>())
123126
}
124127

125128
/// Check if there is any data to run on here.

crates/cervo-core/src/batcher/scratch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ impl ScratchPad {
8383
.iter()
8484
.map(|(name, shape)| {
8585
let count = shape.iter().product();
86-
ScratchPadData::new(name.to_owned(), count, capacity)
86+
ScratchPadData::new(name.clone(), count, capacity)
8787
})
8888
.collect();
8989

9090
let outputs = outputs
9191
.iter()
9292
.map(|(name, shape)| {
9393
let count = shape.iter().product();
94-
ScratchPadData::new(name.to_owned(), count, capacity)
94+
ScratchPadData::new(name.clone(), count, capacity)
9595
})
9696
.collect();
9797

crates/cervo-core/src/batcher/wrapper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::collections::HashMap;
1010
/// data-insertion and execution, which generally improves
1111
/// performance.
1212
///
13-
/// Can be easily constructed using [InfererExt::into_batched](crate::prelude::InfererExt::into_batched).
13+
/// Can be easily constructed using [`InfererExt::into_batched`](crate::prelude::InfererExt::into_batched).
1414
pub struct Batched<Inf: Inferer> {
1515
inner: Inf,
1616
batcher: Batcher,

crates/cervo-core/src/epsilon.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use perchance::PerchanceContext;
1414
use rand::thread_rng;
1515
use rand_distr::{Distribution, StandardNormal};
1616

17-
/// NoiseGenerators are consumed by the [`EpsilonInjector`] by generating noise sampled for a standard normal
17+
/// `NoiseGenerators` are consumed by the [`EpsilonInjector`] by generating noise sampled for a standard normal
1818
/// distribution. Custom noise-generators can be implemented and passed via [`EpsilonInjector::with_generator`].
1919
pub trait NoiseGenerator {
2020
fn generate(&self, count: usize, out: &mut [f32]);
@@ -89,7 +89,7 @@ impl NoiseGenerator for LowQualityNoiseGenerator {
8989
/// use-cases.
9090
///
9191
/// This implementation uses [`rand::thread_rng`] internally as the entropy source, and uses the optimized
92-
/// StandardNormal distribution for sampling.
92+
/// `StandardNormal` distribution for sampling.
9393
pub struct HighQualityNoiseGenerator {
9494
normal_distribution: StandardNormal,
9595
}

crates/cervo-core/src/inferer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ pub trait InfererExt: Inferer + Sized {
195195
}
196196

197197
/// Execute the model on the provided pre-batched data.
198-
fn infer_single<'this>(&'this self, input: State<'_>) -> Result<Response<'this>, anyhow::Error>
199-
where
200-
Self: Sized,
201-
{
198+
fn infer_single<'this>(
199+
&'this self,
200+
input: State<'_>,
201+
) -> Result<Response<'this>, anyhow::Error> {
202202
let mut batcher = Batcher::new_sized(self, 1);
203203
batcher.push(0, input)?;
204204

crates/cervo-core/src/model_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use tract_core::{model::TypedModel, tract_data::TractResult};
1010
use tract_hir::{infer::Factoid, prelude::InferenceModel};
1111

12-
/// The ModelApi describes the inputs and outputs for a model.
12+
/// The `ModelApi` describes the inputs and outputs for a model.
1313
pub struct ModelApi {
1414
/// The named model inputs.
1515
pub inputs: Vec<(String, Vec<usize>)>,

crates/cervo-core/tests/batcher.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use cervo_core::prelude::{Batcher, Inferer, InfererExt, State};
88

99
struct TestInferer<
1010
B: Fn(usize) -> usize,
11-
R: Fn(cervo_core::batcher::ScratchPadView) -> anyhow::Result<(), anyhow::Error>,
11+
R: Fn(cervo_core::batcher::ScratchPadView<'_>) -> anyhow::Result<(), anyhow::Error>,
1212
> {
1313
batch_size: B,
1414
raw: R,
@@ -19,15 +19,15 @@ struct TestInferer<
1919
impl<B, R> Inferer for TestInferer<B, R>
2020
where
2121
B: Fn(usize) -> usize,
22-
R: Fn(cervo_core::batcher::ScratchPadView) -> anyhow::Result<(), anyhow::Error>,
22+
R: Fn(cervo_core::batcher::ScratchPadView<'_>) -> anyhow::Result<(), anyhow::Error>,
2323
{
2424
fn select_batch_size(&self, max_count: usize) -> usize {
2525
(self.batch_size)(max_count)
2626
}
2727

2828
fn infer_raw(
2929
&self,
30-
batch: cervo_core::batcher::ScratchPadView,
30+
batch: cervo_core::batcher::ScratchPadView<'_>,
3131
) -> anyhow::Result<(), anyhow::Error> {
3232
(self.raw)(batch)
3333
}
@@ -278,7 +278,7 @@ fn test_values() {
278278

279279
let r = batcher.execute(&inf).unwrap();
280280
assert_eq!(r.len(), 4);
281-
dbg!(&r);
281+
let _ = &r;
282282
for (id, vals) in r {
283283
assert_eq!(vals.data["out"].len(), 11);
284284
assert_eq!(vals.data["out"][0], id as f32);

crates/cervo-nnef/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lazy_static::lazy_static! {
4545
/// ahead of time.
4646
pub fn init() {
4747
use lazy_static::LazyStatic;
48-
NNEF::initialize(&NNEF)
48+
NNEF::initialize(&NNEF);
4949
}
5050

5151
/// Utility function to check if a file name is `.nnef.tar`.

crates/cervo-nnef/tests/helpers.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ pub fn get_file(name: &'static str) -> std::io::Result<File> {
1919
std::fs::File::open(path)
2020
}
2121

22-
pub fn build_inputs_from_desc(count: u64, inputs: &[(String, Vec<usize>)]) -> HashMap<u64, State> {
22+
pub fn build_inputs_from_desc(
23+
count: u64,
24+
inputs: &[(String, Vec<usize>)],
25+
) -> HashMap<u64, State<'_>> {
2326
(0..count)
2427
.map(|idx| {
2528
(

crates/cervo-onnx/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ pub fn builder<T: Read>(read: T) -> InfererBuilder<OnnxData<T>> {
9090
pub fn to_nnef(reader: &mut dyn Read, batch_size: Option<usize>) -> Result<Vec<u8>> {
9191
let mut model = model_for_reader(reader)?;
9292

93-
let batch = batch_size
94-
.map(|v| v.to_dim())
95-
.unwrap_or_else(|| Symbol::from('N').to_dim());
93+
let batch = batch_size.map_or_else(|| Symbol::from('N').to_dim(), |v| v.to_dim());
9694

9795
let input_outlets = model.input_outlets()?.to_vec();
9896

crates/cervo-onnx/tests/helpers.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ pub fn get_file(name: &'static str) -> std::io::Result<File> {
2020
std::fs::File::open(path)
2121
}
2222

23-
pub fn build_inputs_from_desc(count: u64, inputs: &[(String, Vec<usize>)]) -> HashMap<u64, State> {
23+
pub fn build_inputs_from_desc(
24+
count: u64,
25+
inputs: &[(String, Vec<usize>)],
26+
) -> HashMap<u64, State<'_>> {
2427
(0..count)
2528
.map(|idx| {
2629
(

crates/cervo-runtime/src/runtime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Runtime {
135135
match res {
136136
Some(res) => {
137137
result.insert(ticket.1, res);
138-
executed.push(ticket.1)
138+
executed.push(ticket.1);
139139
}
140140
None => {
141141
non_executed.push(ticket);
@@ -420,7 +420,7 @@ mod tests {
420420
let err = res.unwrap_err();
421421

422422
if let CervoError::OrphanedData(keys) = err {
423-
assert_eq!(keys, vec![k])
423+
assert_eq!(keys, vec![k]);
424424
} else {
425425
panic!("expected CervoError::OrphanedData")
426426
}
@@ -439,7 +439,7 @@ mod tests {
439439
let err = res.unwrap_err();
440440

441441
if let CervoError::OrphanedData(keys) = err {
442-
assert_eq!(keys, vec![k])
442+
assert_eq!(keys, vec![k]);
443443
} else {
444444
panic!("expected CervoError::OrphanedData")
445445
}

crates/cervo-runtime/src/state.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,11 @@ impl ModelState {
9696

9797
let elapsed = start.elapsed();
9898
let mut timings = self.timings.borrow_mut();
99-
match timings.iter_mut().find(|b| b.size == 1) {
100-
Some(bucket) => bucket.add(elapsed),
101-
None => {
102-
timings.push(TimingBucket::new(1, elapsed));
103-
timings.sort_by_key(|b| b.size);
104-
}
99+
if let Some(bucket) = timings.iter_mut().find(|b| b.size == 1) {
100+
bucket.add(elapsed);
101+
} else {
102+
timings.push(TimingBucket::new(1, elapsed));
103+
timings.sort_by_key(|b| b.size);
105104
}
106105

107106
Ok(res)
@@ -123,12 +122,11 @@ impl ModelState {
123122

124123
let elapsed = start.elapsed();
125124
let mut timings = self.timings.borrow_mut();
126-
match timings.iter_mut().find(|b| b.size == batch_size) {
127-
Some(bucket) => bucket.add(elapsed),
128-
None => {
129-
timings.push(TimingBucket::new(batch_size, elapsed));
130-
timings.sort_by_key(|b| b.size);
131-
}
125+
if let Some(bucket) = timings.iter_mut().find(|b| b.size == batch_size) {
126+
bucket.add(elapsed);
127+
} else {
128+
timings.push(TimingBucket::new(batch_size, elapsed));
129+
timings.sort_by_key(|b| b.size);
132130
}
133131

134132
Ok(res)

crates/cervo-runtime/src/timing.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mod tests {
7878
#[test]
7979
fn initial_mean_initial_value() {
8080
let state = WelfordState::new(Duration::from_secs_f32(1.0));
81-
assert!(is_close(state.mean().as_secs_f32(), 1.0))
81+
assert!(is_close(state.mean().as_secs_f32(), 1.0));
8282
}
8383

8484
#[test]
@@ -89,7 +89,7 @@ mod tests {
8989
state.update(Duration::from_secs_f32(1.0));
9090
}
9191

92-
assert_eq!(state.mean().as_secs_f32(), 1.0)
92+
assert_eq!(state.mean().as_secs_f32(), 1.0);
9393
}
9494

9595
#[test]
@@ -100,7 +100,7 @@ mod tests {
100100
state.update(Duration::from_secs_f32(v as f32));
101101
}
102102

103-
assert_eq!(state.mean().as_secs_f32(), 4.5)
103+
assert_eq!(state.mean().as_secs_f32(), 4.5);
104104
}
105105

106106
#[test]
@@ -111,6 +111,6 @@ mod tests {
111111
state.update(Duration::from_secs_f32(v as f32));
112112
}
113113

114-
assert_eq!(state.mean().as_secs_f32(), 49.5)
114+
assert_eq!(state.mean().as_secs_f32(), 49.5);
115115
}
116116
}

0 commit comments

Comments
 (0)