Skip to content

Commit

Permalink
enable many clippy lints, and fix lint errors (#400)
Browse files Browse the repository at this point in the history
* Delete unused variables.
* Tighten up all lint warnings to errors.
* Add -Drust_2018_idioms and fix errors.
* Add a few pedantic clippy lints and auto-fix errors.
* Add clippy::filter_map_next and manually fix errors.
* Add clippy::implicit_clone and auto-fix errors.
* Add clippy::inefficient_to_string and auto-fix.
* Add clippy::manual_string_new and auto-fix.
* Add clippy::semicolon_if_nothing_returned and auto-fix.
* Add clippy::used_underscore_binding and manually fix.
* Add clippy::redundant_else and manually fix.
* Add clippy::complexity which surprisingly requires no fixes.
* Leave a few notes in the lint rules.
  • Loading branch information
macklin-10x authored Mar 20, 2024
1 parent 3a2f1e6 commit 2fe59f3
Show file tree
Hide file tree
Showing 71 changed files with 447 additions and 498 deletions.
61 changes: 50 additions & 11 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
[build]
rustflags = [
# --- lint deny ---
# rustc lints
"-Dfuture_incompatible",
"-Dnonstandard_style",
"-Drust_2018_idioms",
"-Dunused",
"-D", "rust_2018_compatibility",
"-D", "rust_2021_compatibility",

# clippy categorical
"-Dclippy::complexity",
"-D", "clippy::perf",
"-D", "clippy::style",
"-D", "clippy::suspicious",
"-A", "clippy::comparison_chain",
"-W", "future_incompatible",
"-W", "nonstandard_style",
"-W", "rust_2018_compatibility",
"-W", "rust_2021_compatibility",
"-W", "unused",

# clippy pedantic
"-Dclippy::cloned_instead_of_copied",
"-D", "clippy::enum_glob_use",
"-Dclippy::explicit_deref_methods",
"-Dclippy::explicit_into_iter_loop",
"-Dclippy::explicit_iter_loop",
"-Dclippy::filter_map_next",
"-Dclippy::flat_map_option",
"-Dclippy::from_iter_instead_of_collect",
"-Dclippy::implicit_clone",
"-Dclippy::inefficient_to_string",
# we should audit the codebase for panics that should be errors before turning
# this lint on
# "-Dclippy::manual_assert",
"-Dclippy::manual_let_else",
"-Dclippy::manual_string_new",
"-Dclippy::map_unwrap_or",
"-Dclippy::match_wildcard_for_single_variants",
"-Dclippy::mut_mut",
"-Dclippy::needless_bitwise_bool",
"-Dclippy::needless_continue",
"-Dclippy::needless_for_each",

"-Dclippy::semicolon_if_nothing_returned",
"-Dclippy::uninlined_format_args",
"-Dclippy::unused_self",
"-Dclippy::used_underscore_binding",
"-Dclippy::redundant_else",
"-D", "clippy::needless_lifetimes",
"-D", "clippy::redundant_closure_for_method_calls",
"-D", "clippy::unused_io_amount",
"-D", "clippy::wildcard_imports",
"-D", "clippy::unnecessary_unwrap",
"-D", "clippy::uninlined_format_args",
"-W", "clippy::disallowed_names",
"-W", "clippy::enum_variant_names",
"-W", "clippy::large-enum-variant",
"-W", "clippy::missing_safety_doc",
"-D", "clippy::disallowed_names",
"-D", "clippy::enum_variant_names",
"-D", "clippy::large-enum-variant",
"-D", "clippy::missing_safety_doc",
"-D", "clippy::result_unit_err",
# clippy nursery
"-Dclippy::needless_collect",
"-Dclippy::or_fun_call",
# --- lint allow ---
"-A", "clippy::comparison_chain",
# TODO: burn down these allow exceptions and then deny them
"-A", "clippy::type_complexity",
"-A", "clippy::too_many_arguments",
"-A", "clippy::needless_range_loop",
"-W", "clippy::result_unit_err",
]

[target.x86_64-unknown-linux-gnu]
Expand Down
2 changes: 1 addition & 1 deletion align_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub fn vis_align(s1: &[u8], s2: &[u8], ops: &[AlignmentOperation], width: usize)
let mut start = 0;
while start < n {
let stop = min(start + width, n);
for seq in [&d, &t1, &t2].iter() {
for seq in &[&d, &t1, &t2] {
x.append(&mut seq[start..stop].to_vec().clone());
x.push(b'\n');
}
Expand Down
6 changes: 3 additions & 3 deletions ansi_escape/src/ansi_to_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub fn compress_ansi_escapes(x: &str) -> String {

// Emit bold, then color, then background.

for e in escapes.iter() {
for e in &escapes {
if e.solo() && e[0] == 1 {
if reset || new_state.bold != old_state.bold {
out += strme(&pack_ansi_escape(e));
Expand Down Expand Up @@ -395,7 +395,7 @@ impl ColorState {
write!(s, "background-color:{};", self.background).unwrap();
}
if self.bold {
s += "font-weight:bold;"
s += "font-weight:bold;";
}
s += "\">";
s
Expand All @@ -413,7 +413,7 @@ impl ColorState {
write!(s, "fill: {};", self.color).unwrap();
}
if self.bold {
s += "font-weight: bold;"
s += "font-weight: bold;";
}
s += "\">";
s
Expand Down
2 changes: 1 addition & 1 deletion bio_edit/src/alignment/pairwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ impl TracebackCell {
"Expected a value <= TB_MAX while setting traceback bits"
);
self.v = (self.v & !bits) // First clear the bits
| (value << pos) // And set the bits
| (value << pos); // And set the bits
}

#[inline(always)]
Expand Down
13 changes: 6 additions & 7 deletions enclone/src/allele.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use itertools::Itertools;
use rayon::prelude::*;
use stats_utils::percent_ratio;
use std::cmp::{max, min, PartialOrd};
use std::time::Instant;

use vector_utils::{erase_if, next_diff, next_diff1_2, next_diff1_3, reverse_sort, unique_sort};

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn find_alleles(
}
}
let mut results = Vec::<(usize, Vec<(usize, usize, DnaString, usize, bool)>)>::new();
for v in vs.iter() {
for v in &vs {
results.push((*v, Vec::new()));
}
results.par_iter_mut().for_each(|res| {
Expand Down Expand Up @@ -372,9 +372,9 @@ pub fn find_alleles(
);
println!("{id} = |{}| = {}", refdata.id[id], refdata.name[id]);
println!("ps = {}", ps.iter().format(","));
for x in keep.iter() {
for x in &keep {
let mut bases = String::new();
for z in x.0.iter() {
for z in &x.0 {
bases.push(*z as char);
}
print!("{bases} [{}] {:.1}", x.1, x.2);
Expand Down Expand Up @@ -425,7 +425,7 @@ pub fn find_alleles(
}
}
erase_if(&mut ps, &to_delete);
for j in keep.iter_mut() {
for j in &mut keep {
erase_if(&mut j.0, &to_delete);
}
let mut keep0 = Vec::<Vec<u8>>::new();
Expand All @@ -437,7 +437,7 @@ pub fn find_alleles(

// Save alternate references.

for x in keep.iter() {
for x in &keep {
if !x.3 || analysis_mode {
let mut b = refdata.refs[id].clone();
for (&x0, &ps) in x.0.iter().zip(ps.iter()) {
Expand Down Expand Up @@ -512,7 +512,6 @@ pub fn sub_alts(
info: &mut Vec<CloneInfo>,
exact_clonotypes: &mut [ExactClonotype],
) {
let t = Instant::now();
for i in 0..info.len() {
for j in 0..info[i].vs.len() {
if info[i].vs[j].len() - ctl.heur.ref_v_trim <= info[i].tigs[j].len() {
Expand Down
2 changes: 1 addition & 1 deletion enclone/src/bin/post_process_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
for line in stdin.lock().lines() {
let line = line.unwrap();
let mut rejected = false;
for r in reject.iter() {
for r in &reject {
if line.contains(r) {
rejected = true;
}
Expand Down
2 changes: 1 addition & 1 deletion enclone/src/innate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub fn mark_innate(refdata: &RefData, ex: &mut Vec<ExactClonotype>) {
}
}
}
for share in e.share.iter_mut() {
for share in &mut e.share {
share.inkt_alpha_chain_gene_match = have_inkt_tra;
share.inkt_alpha_chain_junction_match = have_inkt_tra_cdr3;
share.inkt_beta_chain_gene_match = have_inkt_trb;
Expand Down
17 changes: 7 additions & 10 deletions enclone/src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rayon::prelude::*;
use std::cmp::min;
use std::collections::HashMap;
use std::io::Write;
use std::time::Instant;

use vector_utils::{bin_member, erase_if, next_diff1_2};

pub fn join_exacts(
Expand All @@ -42,7 +42,6 @@ pub fn join_exacts(
//
// Run special option for joining by barcode identity.

let timer1 = Instant::now();
if ctl.join_alg_opt.bcjoin {
let mut eq: EquivRel = EquivRel::new(info.len() as i32);
let mut bcx = Vec::<(String, usize)>::new(); // {(barcode, info_index)}
Expand Down Expand Up @@ -105,8 +104,6 @@ pub fn join_exacts(
println!("comparing {} simple clonotypes", info.len());
}

let timer2 = Instant::now();

let joinf = |r: &mut (
usize,
usize,
Expand All @@ -119,7 +116,7 @@ pub fn join_exacts(
let joins = &mut r.2;
let errors = &mut r.3;
let logplus = &mut r.4;
let mut pot = Vec::<PotentialJoin>::new();
let mut pot = Vec::<PotentialJoin<'_>>::new();

// Main join logic. If you change par_iter_mut to iter_mut above, and run happening,
// a lot of time shows up on the following line. If further you manually inline join_core
Expand Down Expand Up @@ -186,7 +183,7 @@ pub fn join_exacts(
{
let (k1, k2) = (x[0] as usize + i, x[1] as usize + i);
let k = min(k1, k2);
for pj in to_pot[k - i].iter() {
for pj in &to_pot[k - i] {
let cd = pot[*pj].cd;
let shares = &pot[*pj].shares;

Expand Down Expand Up @@ -256,10 +253,10 @@ pub fn join_exacts(
fwriteln!(log, "\nJOIN ERROR");
}
let (mut lena1, mut lena2) = (Vec::<String>::new(), Vec::<String>::new());
for l1 in info[k1].origin.iter() {
for l1 in &info[k1].origin {
lena1.push(ctl.origin_info.dataset_id[*l1].clone());
}
for l2 in info[k2].origin.iter() {
for l2 in &info[k2].origin {
lena2.push(ctl.origin_info.dataset_id[*l2].clone());
}
fwriteln!(
Expand Down Expand Up @@ -287,15 +284,15 @@ pub fn join_exacts(
fwrite!(log, "{}={}", t, refdata.transcript[*t]);
}
fwriteln!(log, "");
for l1 in info[k1].origin.iter() {
for l1 in &info[k1].origin {
fwriteln!(
log,
"{} = {}",
ctl.origin_info.dataset_id[*l1],
ctl.origin_info.descrips[*l1]
);
}
for l2 in info[k2].origin.iter() {
for l2 in &info[k2].origin {
fwriteln!(
log,
"{} = {}",
Expand Down
3 changes: 1 addition & 2 deletions enclone/src/join2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use enclone_core::defs::{CloneInfo, EncloneControl};
use equiv::EquivRel;
use stats_utils::percent_ratio;
use std::time::Instant;

use vector_utils::next_diff1_2;

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
Expand All @@ -26,7 +26,6 @@ pub fn finish_join(
// Tally results.

let (mut joins, mut errors) = (0, 0);
let timer3 = Instant::now();
for r in results {
joins += r.2;
errors += r.3;
Expand Down
2 changes: 1 addition & 1 deletion enclone/src/misc1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn lookup_heavy_chain_reuse(
for z1 in 0..25 {
for z2 in z1 + 1..25 {
let mut xcdr3 = cdr3.clone();
for cdr in xcdr3.iter_mut() {
for cdr in &mut xcdr3 {
if cdr.0.len() > z2 {
let mut t = cdr.0.as_bytes().to_vec();
t[z1] = b'*';
Expand Down
16 changes: 3 additions & 13 deletions enclone/src/misc2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::collections::HashMap;

use std::fmt::Write as _;
use std::io::Write;
use std::time::Instant;

use string_utils::strme;
use vdj_ann::refx::RefData;
use vector_utils::{
Expand Down Expand Up @@ -278,7 +278,6 @@ pub fn find_exact_subclonotypes(
let mut exact_clonotypes = Vec::<ExactClonotype>::new();
let mut r = 0;
let mut groups = Vec::<(usize, usize)>::new();
let t = Instant::now();
while r < tig_bc.len() {
let mut s = r + 1;
while s < tig_bc.len() {
Expand Down Expand Up @@ -322,7 +321,6 @@ pub fn find_exact_subclonotypes(
r = s;
}

let t = Instant::now();
let mut results = Vec::<(
usize,
Vec<ExactClonotype>,
Expand Down Expand Up @@ -400,15 +398,8 @@ pub fn find_exact_subclonotypes(

// Explore consensus.

let mut _count = 0;
study_consensus(
&mut _count,
ctl,
&share,
&clones,
&exact_clonotypes,
refdata,
);
let mut count = 0;
study_consensus(&mut count, ctl, &share, &clones, &exact_clonotypes, refdata);

// Filter out putative gel bead contamination.

Expand All @@ -424,7 +415,6 @@ pub fn find_exact_subclonotypes(
}
});

let t = Instant::now();
let mut max_exact = 0;
for i in 0..results.len() {
if !results[i].1.is_empty() {
Expand Down
Loading

0 comments on commit 2fe59f3

Please sign in to comment.