Skip to content

Commit 8e7bd80

Browse files
authored
Increase lint level (#126)
* update deps * tangram_id, Eq, remove transmute from libmodelfox * modelfox_build * modelfox_charts * modelfox_dev * modelfox_finite * modelfox_kill_chip * modelfox_license * finite, kill_chip, license, number_formatter * modelfox_serve * modelfox_table
1 parent 666343a commit 8e7bd80

File tree

36 files changed

+703
-462
lines changed

36 files changed

+703
-462
lines changed

Cargo.lock

Lines changed: 174 additions & 188 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ base64 = "0.13"
2828
bitvec = "1.0"
2929
buffalo = { version = "0.4", features = ["bitvec", "ndarray"] }
3030
bytes = "1.1"
31-
cbindgen = "0.23"
31+
cbindgen = "0.24"
3232
chrono = { version = "0.4", features = ["serde"] }
3333
chrono-tz = { version = "0.6", features = ["serde"] }
3434
clap = { version = "3.1", features = ["derive"] }

crates/app/core/alert_sender.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ async fn handle_alert_send_with_decay(
187187
Ok(())
188188
}
189189

190-
#[derive(Debug, Clone, Copy, PartialEq)]
190+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
191191
pub enum AlertSendStatus {
192192
Unsent,
193193
Sending,

crates/app/layouts/model_layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async fn delete_model(
170170
Ok(response)
171171
}
172172

173-
#[derive(PartialEq)]
173+
#[derive(PartialEq, Eq)]
174174
pub enum ModelNavItem {
175175
Overview,
176176
TrainingGrid,

crates/app/routes/login/server/page.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct Page {
88
pub error: Option<String>,
99
}
1010

11-
#[derive(PartialEq)]
11+
#[derive(PartialEq, Eq)]
1212
pub enum Stage {
1313
Email,
1414
Code,

crates/app/routes/repos/_/models/_/production_predictions/index/server/get.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub async fn get(request: &mut http::Request<hyper::Body>) -> Result<http::Respo
6060
let before = search_params.as_ref().and_then(|s| s.before);
6161
let rows = match (after, before) {
6262
(Some(after), None) => {
63-
let rows = sqlx::query(
63+
sqlx::query(
6464
"
6565
select
6666
id,
@@ -89,8 +89,7 @@ pub async fn get(request: &mut http::Request<hyper::Body>) -> Result<http::Respo
8989
.bind(after)
9090
.bind(PRODUCTION_PREDICTIONS_NUM_PREDICTIONS_PER_PAGE_TABLE)
9191
.fetch_all(db.borrow_mut())
92-
.await?;
93-
rows
92+
.await?
9493
}
9594
(None, Some(before)) => {
9695
sqlx::query(

crates/app/routes/repos/new/server/post.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub async fn post(request: &mut http::Request<hyper::Body>) -> Result<http::Resp
3737
let repo_id = if let Some(owner) = &owner {
3838
let repo_id = Id::generate();
3939
let owner_parts: Vec<&str> = owner.split(':').collect();
40-
let owner_type = match owner_parts.get(0) {
40+
let owner_type = match owner_parts.first() {
4141
Some(owner_type) => owner_type,
4242
None => return Ok(bad_request()),
4343
};

crates/app/ui/column_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[derive(PartialEq, Clone, Copy)]
1+
#[derive(PartialEq, Eq, Clone, Copy)]
22
pub enum ColumnType {
33
Unknown,
44
Number,

crates/build/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ name = "modelfox_build"
1717
path = "main.rs"
1818

1919
[dependencies]
20-
anyhow = { workspace = true }
2120
cbindgen = { workspace = true }
2221
chrono = { workspace = true }
2322
clap = { workspace = true }

crates/build/main.rs

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use anyhow::Result;
1+
#![warn(clippy::pedantic)]
2+
23
use clap::Parser;
34
use digest::Digest;
45
use duct::cmd;
@@ -207,7 +208,7 @@ fn build_rpms(version: &str) {
207208
PathBuf::from(format!("modelfox-{version}/modelfox", version = version));
208209
let sources_path = rpm_path.join("SOURCES");
209210
let tar_path = sources_path.join("modelfox.tar.gz");
210-
tar(vec![(modelfox_cli_path, modelfox_path_in_tar)], &tar_path);
211+
tar(&[(modelfox_cli_path, modelfox_path_in_tar)], &tar_path);
211212
// Write the spec file.
212213
let spec = formatdoc!(
213214
r#"
@@ -321,6 +322,9 @@ fn build_containers(version: &str) {
321322
}
322323
}
323324

325+
/// # Panics
326+
///
327+
/// This function will panic if shelling out to `gpg --decrypt` fails.
324328
pub fn build_pkgs(version: &str, pkgs_url: &str) {
325329
let root_path = std::env::current_dir().unwrap();
326330
let pkgs_path = root_path.join("dist").join("pkgs");
@@ -364,30 +368,27 @@ pub fn build_pkgs(version: &str, pkgs_url: &str) {
364368
version,
365369
&alpine_public_key_path,
366370
&alpine_private_key_path,
367-
)
368-
.unwrap();
371+
);
369372
deb(
370373
pkgs_url,
371374
version,
372375
&deb_public_key_path,
373376
&deb_private_key_path,
374-
)
375-
.unwrap();
377+
);
376378
rpm(
377379
pkgs_url,
378380
version,
379381
&rpm_public_key_path,
380382
&rpm_private_key_path,
381-
)
382-
.unwrap();
383+
);
383384
}
384385

385386
fn alpine(
386387
_pkgs_url: &str,
387388
version: &str,
388389
alpine_public_key_path: &Path,
389390
alpine_private_key_path: &Path,
390-
) -> Result<()> {
391+
) {
391392
let root_path = std::env::current_dir().unwrap();
392393
let compile_path = root_path.join("dist").join("compile");
393394
let pkgs_path = root_path.join("dist").join("pkgs");
@@ -447,18 +448,10 @@ fn alpine(
447448
.run()
448449
.unwrap();
449450
}
450-
Ok(())
451451
}
452452

453-
fn deb(
454-
pkgs_url: &str,
455-
version: &str,
456-
deb_public_key_path: &Path,
457-
deb_private_key_path: &Path,
458-
) -> Result<()> {
459-
let root_path = std::env::current_dir().unwrap();
460-
let pkgs_path = root_path.join("dist").join("pkgs");
461-
let debs_path = root_path.join("dist").join("debs");
453+
#[allow(clippy::too_many_lines)]
454+
fn deb(pkgs_url: &str, version: &str, deb_public_key_path: &Path, deb_private_key_path: &Path) {
462455
struct Deb<'a> {
463456
arch: DebArch,
464457
version: &'a str,
@@ -477,10 +470,13 @@ fn deb(
477470
}
478471
}
479472
}
473+
let root_path = std::env::current_dir().unwrap();
474+
let pkgs_path = root_path.join("dist").join("pkgs");
475+
let debs_path = root_path.join("dist").join("debs");
480476
let archs = [DebArch::Amd64, DebArch::Arm64];
481477
let debs: Vec<Deb> = archs
482478
.iter()
483-
.cloned()
479+
.copied()
484480
.map(|arch| {
485481
let path = debs_path.join(format!(
486482
"modelfox_{version}_{arch}.deb",
@@ -532,7 +528,7 @@ fn deb(
532528
let pool_path = repo_path.join("pool");
533529
std::fs::create_dir_all(&pool_path).unwrap();
534530
// Copy all the .debs into the pool.
535-
for deb in debs.iter() {
531+
for deb in &debs {
536532
std::fs::copy(&deb.path, pool_path.join(&deb.path.file_name().unwrap())).unwrap();
537533
}
538534
let dists_path = repo_path.join("dists");
@@ -656,19 +652,9 @@ fn deb(
656652
);
657653
}
658654
}
659-
Ok(())
660655
}
661656

662-
fn rpm(
663-
pkgs_url: &str,
664-
version: &str,
665-
rpm_public_key_path: &Path,
666-
rpm_private_key_path: &Path,
667-
) -> Result<()> {
668-
let root_path = std::env::current_dir().unwrap();
669-
let pkgs_path = root_path.join("dist").join("pkgs");
670-
let rpms_path = root_path.join("dist").join("rpms");
671-
// Find all the .rpms in args.rpms.
657+
fn rpm(pkgs_url: &str, version: &str, rpm_public_key_path: &Path, rpm_private_key_path: &Path) {
672658
struct Rpm {
673659
target: RpmTarget,
674660
path: PathBuf,
@@ -686,10 +672,14 @@ fn rpm(
686672
}
687673
}
688674
}
675+
let root_path = std::env::current_dir().unwrap();
676+
let pkgs_path = root_path.join("dist").join("pkgs");
677+
let rpms_path = root_path.join("dist").join("rpms");
678+
// Find all the .rpms in args.rpms.
689679
let targets = [RpmTarget::X8664, RpmTarget::AArch64];
690680
let rpms: Vec<Rpm> = targets
691681
.iter()
692-
.cloned()
682+
.copied()
693683
.map(|target| {
694684
let path = rpms_path.join(format!(
695685
"modelfox_{version}_{target}.rpm",
@@ -713,9 +703,8 @@ fn rpm(
713703
std::fs::create_dir_all(&repo_path).unwrap();
714704
// Create the .repo file.
715705
let repo_file_path = repo_path.join("modelfox.repo");
716-
let distribution_version_with_leading_slash = distribution_version
717-
.map(|v| format!("/{v}", v = v))
718-
.unwrap_or_else(|| "".to_owned());
706+
let distribution_version_with_leading_slash =
707+
distribution_version.map_or_else(|| "".to_owned(), |v| format!("/{v}", v = v));
719708
let repo_file = formatdoc!(
720709
r#"
721710
[modelfox]
@@ -740,7 +729,7 @@ fn rpm(
740729
let repo_target_path = repo_path.join(target.to_string());
741730
std::fs::create_dir_all(&repo_target_path).unwrap();
742731
// Copy the .rpm.
743-
for rpm in rpms.iter() {
732+
for rpm in &rpms {
744733
if rpm.target == target {
745734
std::fs::copy(
746735
&rpm.path,
@@ -760,7 +749,6 @@ fn rpm(
760749
);
761750
}
762751
}
763-
Ok(())
764752
}
765753

766754
fn build_release(version: &str) {
@@ -784,7 +772,7 @@ fn build_release(version: &str) {
784772
modelfox_cli_path.clone(),
785773
PathBuf::from(modelfox_cli_file_name),
786774
)];
787-
tar(inputs, &output_path);
775+
tar(&inputs, &output_path);
788776
}
789777
// libmodelfox
790778
for target in TARGETS {
@@ -810,7 +798,7 @@ fn build_release(version: &str) {
810798
PathBuf::from(target_file_names.libmodelfox_static_file_name),
811799
),
812800
];
813-
tar(inputs, &output_path);
801+
tar(&inputs, &output_path);
814802
}
815803
}
816804

@@ -830,7 +818,7 @@ pub enum Arch {
830818
X8664,
831819
}
832820

833-
#[derive(Clone, Copy, Debug, PartialEq)]
821+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
834822
pub enum Target {
835823
AArch64LinuxGnu,
836824
AArch64LinuxMusl,
@@ -843,6 +831,7 @@ pub enum Target {
843831
}
844832

845833
impl Target {
834+
#[must_use]
846835
pub fn arch(&self) -> Arch {
847836
match self {
848837
Target::AArch64LinuxGnu | Target::AArch64LinuxMusl | Target::AArch64MacOs => {
@@ -856,6 +845,7 @@ impl Target {
856845
}
857846
}
858847

848+
#[must_use]
859849
pub fn target_name(&self) -> &'static str {
860850
match self {
861851
Target::AArch64LinuxGnu => "aarch64-linux-gnu",
@@ -869,6 +859,7 @@ impl Target {
869859
}
870860
}
871861

862+
#[must_use]
872863
pub fn rust_target_name(&self) -> &'static str {
873864
match self {
874865
Target::AArch64LinuxGnu => "aarch64-unknown-linux-gnu",
@@ -882,6 +873,7 @@ impl Target {
882873
}
883874
}
884875

876+
#[must_use]
885877
pub fn rust_target(&self) -> &'static str {
886878
match self {
887879
Target::AArch64LinuxGnu => "aarch64-unknown-linux-gnu",
@@ -907,6 +899,7 @@ pub struct TargetFileNames {
907899
}
908900

909901
impl TargetFileNames {
902+
#[must_use]
910903
pub fn for_target(target: Target) -> TargetFileNames {
911904
match target {
912905
Target::X8664LinuxGnu
@@ -959,16 +952,17 @@ fn clean_and_create(path: &Path) {
959952
std::fs::create_dir_all(path).unwrap();
960953
}
961954

962-
fn tar(input_paths: Vec<(PathBuf, PathBuf)>, output_path: &Path) {
955+
fn tar(input_paths: &[(PathBuf, PathBuf)], output_path: &Path) {
963956
let output_file = std::fs::File::create(output_path).unwrap();
964957
let gz = flate2::write::GzEncoder::new(output_file, flate2::Compression::default());
965958
let mut tar = tar::Builder::new(gz);
966-
for (path, name) in input_paths.iter() {
959+
for (path, name) in input_paths {
967960
tar.append_path_with_name(path, name).unwrap();
968961
}
969962
tar.finish().unwrap();
970963
}
971964

965+
#[derive(Clone, Copy)]
972966
enum SignatureType {
973967
Cleartext,
974968
Detached,

0 commit comments

Comments
 (0)