Skip to content

Commit 6d3d7c5

Browse files
Merge pull request #1405 from nextstrain/chore/upgrade-rust
2 parents 3195eca + 95cf6d5 commit 6d3d7c5

29 files changed

+93
-85
lines changed

.cargo/config.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ rustflags = [
182182
"-Wclippy::zero_sized_map_values",
183183
#
184184
# Disable some of the clippy lints
185+
"-Aclippy::absolute_paths",
186+
"-Aclippy::allow_attributes",
185187
"-Aclippy::arithmetic-side-effects",
188+
"-Aclippy::arithmetic_side_effects",
186189
"-Aclippy::as_conversions",
187190
"-Aclippy::assign_op_pattern",
188191
"-Aclippy::bool-to-int-with-if",
@@ -207,13 +210,14 @@ rustflags = [
207210
"-Aclippy::implicit_return",
208211
"-Aclippy::inconsistent_digit_grouping",
209212
"-Aclippy::indexing_slicing",
210-
"-Aclippy::integer_arithmetic",
211213
"-Aclippy::integer_division",
212214
"-Aclippy::iter_nth_zero",
213215
"-Aclippy::large_digit_groups",
216+
"-Aclippy::len_zero",
214217
"-Aclippy::let_underscore_must_use",
215218
"-Aclippy::manual-string-new",
216219
"-Aclippy::match_same_arms",
220+
"-Aclippy::min_ident_chars",
217221
"-Aclippy::missing-assert-message",
218222
"-Aclippy::missing_docs_in_private_items",
219223
"-Aclippy::missing_errors_doc",
@@ -226,6 +230,8 @@ rustflags = [
226230
"-Aclippy::modulo_arithmetic",
227231
"-Aclippy::must_use_candidate",
228232
"-Aclippy::needless_for_each",
233+
"-Aclippy::needless_raw_string_hashes",
234+
"-Aclippy::needless_raw_strings",
229235
"-Aclippy::new_without_default",
230236
"-Aclippy::non_ascii_literal",
231237
"-Aclippy::option_if_let_else",
@@ -245,9 +251,11 @@ rustflags = [
245251
"-Aclippy::shadow_unrelated",
246252
"-Aclippy::should_implement_trait",
247253
"-Aclippy::similar_names",
254+
"-Aclippy::single_call_fn",
248255
"-Aclippy::single_char_lifetime_names",
249256
"-Aclippy::std-instead-of-alloc",
250257
"-Aclippy::std_instead_of_core",
258+
"-Aclippy::struct_field_names",
251259
"-Aclippy::suboptimal_flops",
252260
"-Aclippy::too_many_arguments",
253261
"-Aclippy::too_many_lines",

clippy.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
allow-dbg-in-tests = true
2+
allow-expect-in-tests = true
3+
allow-unwrap-in-tests = true
14
avoid-breaking-exported-api = false
25
cognitive-complexity-threshold = 30

packages/nextclade-cli/src/cli/nextclade_dataset_get.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@ pub fn nextclade_dataset_get(
2727
) -> Result<(), Report> {
2828
let verbose = log::max_level() > LevelFilter::Info;
2929

30-
let mut http = HttpClient::new(server, proxy_config, verbose)?;
31-
let dataset = dataset_http_get(&mut http, name, tag)?;
30+
let http = HttpClient::new(server, proxy_config, verbose)?;
31+
let dataset = dataset_http_get(&http, name, tag)?;
3232

3333
if let Some(output_dir) = &output_dir {
34-
dataset_dir_download(&mut http, &dataset, output_dir)?;
34+
dataset_dir_download(&http, &dataset, output_dir)?;
3535
} else if let Some(output_zip) = &output_zip {
36-
dataset_zip_download(&mut http, &dataset, output_zip)?;
37-
} else {
36+
dataset_zip_download(&http, &dataset, output_zip)?;
3837
}
3938

4039
Ok(())
4140
}
4241

43-
pub fn dataset_http_get(http: &mut HttpClient, name: impl AsRef<str>, tag: &Option<String>) -> Result<Dataset, Report> {
42+
pub fn dataset_http_get(http: &HttpClient, name: impl AsRef<str>, tag: &Option<String>) -> Result<Dataset, Report> {
4443
let name = name.as_ref();
4544
let tag = tag.as_ref();
4645

@@ -100,7 +99,7 @@ pub fn dataset_http_get(http: &mut HttpClient, name: impl AsRef<str>, tag: &Opti
10099
}
101100

102101
pub fn dataset_file_http_get(
103-
http: &mut HttpClient,
102+
http: &HttpClient,
104103
dataset: &Dataset,
105104
filename: impl AsRef<str>,
106105
) -> Result<String, Report> {

packages/nextclade-cli/src/cli/nextclade_dataset_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub fn nextclade_dataset_list(
2727
) -> Result<(), Report> {
2828
let verbose = log::max_level() > LevelFilter::Info;
2929

30-
let mut http = HttpClient::new(&server, &proxy_config, verbose)?;
31-
let DatasetsIndexJson { collections, .. } = download_datasets_index_json(&mut http)?;
30+
let http = HttpClient::new(&server, &proxy_config, verbose)?;
31+
let DatasetsIndexJson { collections, .. } = download_datasets_index_json(&http)?;
3232

3333
let filtered = collections
3434
.into_iter()

packages/nextclade-cli/src/cli/nextclade_seq_sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub fn nextclade_seq_sort(args: &NextcladeSortArgs) -> Result<(), Report> {
3939
MinimizerIndexJson::from_path(input_minimizer_index_json)
4040
} else {
4141
// Otherwise fetch from dataset server
42-
let mut http = HttpClient::new(server, proxy_config, verbose)?;
43-
let index = download_datasets_index_json(&mut http)?;
42+
let http = HttpClient::new(server, proxy_config, verbose)?;
43+
let index = download_datasets_index_json(&http)?;
4444
let minimizer_index_path = index
4545
.minimizer_index
4646
.iter()

packages/nextclade-cli/src/dataset/dataset_download.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use nextclade::{make_error, make_internal_error, o};
1717
use rayon::iter::ParallelIterator;
1818
use std::collections::BTreeMap;
1919
use std::fs::File;
20-
use std::io::{BufReader, Read, Seek, Write};
20+
use std::io::{BufReader, Cursor, Read, Seek, Write};
2121
use std::path::{Path, PathBuf};
2222
use std::str::FromStr;
2323
use zip::ZipArchive;
@@ -50,19 +50,19 @@ pub fn nextclade_get_inputs(
5050
}
5151

5252
#[inline]
53-
pub fn download_datasets_index_json(http: &mut HttpClient) -> Result<DatasetsIndexJson, Report> {
53+
pub fn download_datasets_index_json(http: &HttpClient) -> Result<DatasetsIndexJson, Report> {
5454
let data_bytes = http.get("/index.json")?;
5555
let data_str = String::from_utf8(data_bytes)?;
5656
DatasetsIndexJson::from_str(data_str)
5757
}
5858

59-
pub fn dataset_zip_fetch(http: &mut HttpClient, dataset: &Dataset) -> Result<Vec<u8>, Report> {
59+
pub fn dataset_zip_fetch(http: &HttpClient, dataset: &Dataset) -> Result<Vec<u8>, Report> {
6060
http
6161
.get(&dataset.file_path("dataset.zip"))
6262
.wrap_err_with(|| format!("When fetching zip file for dataset '{}'", dataset.path))
6363
}
6464

65-
pub fn dataset_zip_download(http: &mut HttpClient, dataset: &Dataset, output_file_path: &Path) -> Result<(), Report> {
65+
pub fn dataset_zip_download(http: &HttpClient, dataset: &Dataset, output_file_path: &Path) -> Result<(), Report> {
6666
let mut file =
6767
create_file_or_stdout(output_file_path).wrap_err_with(|| format!("When opening file {output_file_path:?}"))?;
6868

@@ -127,9 +127,9 @@ pub fn dataset_zip_load(
127127
})
128128
}
129129

130-
pub fn dataset_dir_download(http: &mut HttpClient, dataset: &Dataset, output_dir: &Path) -> Result<(), Report> {
130+
pub fn dataset_dir_download(http: &HttpClient, dataset: &Dataset, output_dir: &Path) -> Result<(), Report> {
131131
let mut content = dataset_zip_fetch(http, dataset)?;
132-
let mut reader = std::io::Cursor::new(content.as_mut_slice());
132+
let mut reader = Cursor::new(content.as_mut_slice());
133133
let mut zip = ZipArchive::new(&mut reader)?;
134134

135135
ensure_dir(output_dir).wrap_err_with(|| format!("When creating directory {output_dir:#?}"))?;
@@ -278,6 +278,7 @@ pub fn dataset_individual_files_load(
278278
}
279279
}
280280

281+
#[allow(clippy::struct_field_names)]
281282
pub struct DatasetFilePaths<'a> {
282283
input_ref: &'a Path,
283284
input_tree: &'a Option<PathBuf>,
@@ -286,7 +287,7 @@ pub struct DatasetFilePaths<'a> {
286287
}
287288

288289
pub fn read_from_path_or_url(
289-
http: &mut HttpClient,
290+
http: &HttpClient,
290291
dataset: &Dataset,
291292
filepath: &Option<impl AsRef<Path>>,
292293
url: &Option<String>,
@@ -304,18 +305,18 @@ pub fn dataset_str_download_and_load(
304305
cdses: &Option<Vec<String>>,
305306
) -> Result<NextcladeParams, Report> {
306307
let verbose = log::max_level() > LevelFilter::Info;
307-
let mut http = HttpClient::new(&run_args.inputs.server, &ProxyConfig::default(), verbose)?;
308+
let http = HttpClient::new(&run_args.inputs.server, &ProxyConfig::default(), verbose)?;
308309

309310
let name = run_args
310311
.inputs
311312
.dataset_name
312313
.as_ref()
313314
.expect("Dataset name is expected, but got 'None'");
314315

315-
let dataset = dataset_http_get(&mut http, name, &None)?;
316+
let dataset = dataset_http_get(&http, name, &None)?;
316317

317318
let virus_properties = read_from_path_or_url(
318-
&mut http,
319+
&http,
319320
&dataset,
320321
&run_args.inputs.input_pathogen_json,
321322
&Some(o!("pathogen.json")),
@@ -325,7 +326,7 @@ pub fn dataset_str_download_and_load(
325326
.ok_or_else(|| eyre!("Required file not found in dataset: 'pathogen.json'. Please report it to dataset authors."))?;
326327

327328
let ref_record = read_from_path_or_url(
328-
&mut http,
329+
&http,
329330
&dataset,
330331
&run_args.inputs.input_ref,
331332
&Some(dataset.files.reference.clone()),
@@ -334,7 +335,7 @@ pub fn dataset_str_download_and_load(
334335
.wrap_err("When reading reference sequence from dataset")?;
335336

336337
let gene_map = read_from_path_or_url(
337-
&mut http,
338+
&http,
338339
&dataset,
339340
&run_args.inputs.input_annotation,
340341
&dataset.files.genome_annotation,
@@ -344,14 +345,9 @@ pub fn dataset_str_download_and_load(
344345
.map(|gene_map| filter_gene_map(gene_map, cdses))
345346
.unwrap_or_default();
346347

347-
let tree = read_from_path_or_url(
348-
&mut http,
349-
&dataset,
350-
&run_args.inputs.input_tree,
351-
&dataset.files.tree_json,
352-
)?
353-
.map_ref_fallible(AuspiceTree::from_str)
354-
.wrap_err("When reading reference tree from dataset")?;
348+
let tree = read_from_path_or_url(&http, &dataset, &run_args.inputs.input_tree, &dataset.files.tree_json)?
349+
.map_ref_fallible(AuspiceTree::from_str)
350+
.wrap_err("When reading reference tree from dataset")?;
355351

356352
Ok(NextcladeParams {
357353
ref_record,

packages/nextclade-cli/src/dataset/dataset_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String {
1717

1818
table.set_header([o!("name"), o!("attributes"), o!("versions")]);
1919

20-
for dataset in filtered.iter() {
20+
for dataset in filtered {
2121
let Dataset {
2222
path,
2323
shortcuts,

packages/nextclade-cli/src/io/http_client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use nextclade::utils::info::{this_package_name, this_package_version_str};
66
use reqwest::blocking::Client;
77
use reqwest::{Method, Proxy};
88
use std::str::FromStr;
9+
use std::time::Duration;
910
use url::Url;
1011

1112
#[derive(Parser, Debug, Default)]
@@ -62,7 +63,7 @@ impl HttpClient {
6263

6364
let client = client_builder
6465
.connection_verbose(verbose)
65-
.connect_timeout(Some(std::time::Duration::from_secs(60)))
66+
.connect_timeout(Some(Duration::from_secs(60)))
6667
.user_agent(user_agent)
6768
.build()?;
6869

packages/nextclade/benches/bench_seed_alignment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
55
use nextclade::align::params::AlignPairwiseParams;
66
use nextclade::align::seed_alignment::create_alignment_band;
77
use nextclade::align::seed_match::{get_seed_matches_maybe_reverse_complement, CodonSpacedIndex, SeedMatchesResult};
8-
use nextclade::alphabet::nuc::to_nuc_seq;
8+
use nextclade::alphabet::nuc::{Nuc, to_nuc_seq};
99

1010
pub fn bench_seed_alignment(c: &mut Criterion) {
1111
let params = AlignPairwiseParams::default();
@@ -40,7 +40,7 @@ pub fn bench_seed_alignment(c: &mut Criterion) {
4040
group.finish();
4141
}
4242

43-
fn sequence_from_path(path: PathBuf) -> Vec<nextclade::alphabet::nuc::Nuc> {
43+
fn sequence_from_path(path: PathBuf) -> Vec<Nuc> {
4444
black_box(to_nuc_seq(fs::read_to_string(path).unwrap().trim()).unwrap())
4545
}
4646

packages/nextclade/src/align/score_matrix.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub fn score_matrix<T: Letter<T>>(
2727
stripes: &[Stripe],
2828
params: &AlignPairwiseParams,
2929
) -> ScoreMatrixResult {
30+
assert!(gap_open_close.len() > 0);
31+
assert!(stripes.len() > 0);
32+
3033
let query_size = qry_seq.len();
3134
let ref_len = ref_seq.len();
3235
let n_rows = ref_len + 1;

0 commit comments

Comments
 (0)