Skip to content

Commit 524add8

Browse files
author
Stephan Dilly
authored
more lints (#648)
1 parent 2a3071f commit 524add8

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed

Cargo.lock

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

asyncgit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ log = "0.4"
2020
thiserror = "1.0"
2121
url = "2.2"
2222
unicode-truncate = "0.2.0"
23+
easy-cast = "0.4"
2324

2425
[dev-dependencies]
2526
tempfile = "3.2"

asyncgit/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub enum Error {
3232

3333
#[error("TryFromInt error:{0}")]
3434
IntConversion(#[from] TryFromIntError),
35+
36+
#[error("EasyCast error:{0}")]
37+
EasyCast(#[from] easy_cast::Error),
3538
}
3639

3740
pub type Result<T> = std::result::Result<T, Error>;

asyncgit/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616
#![deny(clippy::needless_update)]
1717
#![allow(clippy::module_name_repetitions)]
1818
#![allow(clippy::must_use_candidate)]
19+
#![allow(clippy::missing_errors_doc)]
1920
//TODO: get this in someday since expect still leads us to crashes sometimes
2021
// #![deny(clippy::expect_used)]
21-
//TODO:
22-
#![allow(clippy::missing_errors_doc)]
23-
#![allow(clippy::too_many_lines)]
24-
#![allow(clippy::cast_possible_wrap)]
25-
#![allow(clippy::cast_sign_loss)]
26-
#![allow(clippy::cast_possible_truncation)]
27-
#![allow(clippy::cast_precision_loss)]
2822

2923
pub mod cached;
3024
mod commit_files;

asyncgit/src/progress.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//!
22
3+
use easy_cast::{Conv, ConvFloat};
34
use std::cmp;
45

56
///
@@ -12,9 +13,9 @@ pub struct ProgressPercent {
1213
impl ProgressPercent {
1314
///
1415
pub fn new(current: usize, total: usize) -> Self {
15-
let total = cmp::max(current, total) as f32;
16-
let progress = current as f32 / total * 100.0;
17-
let progress = progress as u8;
16+
let total = f64::conv(cmp::max(current, total));
17+
let progress = f64::conv(current) / total * 100.0;
18+
let progress = u8::conv_nearest(progress);
1819
Self { progress }
1920
}
2021
///

asyncgit/src/status.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use std::{
1414
time::{SystemTime, UNIX_EPOCH},
1515
};
1616

17-
fn current_tick() -> u64 {
17+
fn current_tick() -> u128 {
1818
SystemTime::now()
1919
.duration_since(UNIX_EPOCH)
2020
.expect("time before unix epoch!")
21-
.as_millis() as u64
21+
.as_millis()
2222
}
2323

2424
#[derive(Default, Hash, Clone)]
@@ -29,7 +29,7 @@ pub struct Status {
2929
///
3030
#[derive(Default, Hash, Copy, Clone, PartialEq)]
3131
pub struct StatusParams {
32-
tick: u64,
32+
tick: u128,
3333
status_type: StatusType,
3434
include_untracked: bool,
3535
}

asyncgit/src/sync/diff.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::{
66
CommitId,
77
};
88
use crate::{error::Error, error::Result, hash};
9+
use easy_cast::Conv;
910
use git2::{
1011
Delta, Diff, DiffDelta, DiffFormat, DiffHunk, DiffOptions, Patch,
1112
Repository,
@@ -186,6 +187,8 @@ pub fn get_diff_commit(
186187
}
187188

188189
///
190+
//TODO: refactor into helper type with the inline closures as dedicated functions
191+
#[allow(clippy::too_many_lines)]
189192
fn raw_diff_to_file_diff<'a>(
190193
diff: &'a Diff,
191194
work_dir: &Path,
@@ -216,8 +219,9 @@ fn raw_diff_to_file_diff<'a>(
216219
delta.old_file().size(),
217220
delta.new_file().size(),
218221
);
219-
res.size_delta = (res.sizes.1 as i64)
220-
.saturating_sub(res.sizes.0 as i64);
222+
//TODO: use try_conv
223+
res.size_delta = (i64::conv(res.sizes.1))
224+
.saturating_sub(i64::conv(res.sizes.0));
221225
}
222226
if let Some(hunk) = hunk {
223227
let hunk_header = HunkHeader::from(hunk);

asyncgit/src/sync/staging/stage_tracked.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
patches::get_file_diff_patch_and_hunklines, utils::repo,
77
},
88
};
9+
use easy_cast::Conv;
910
use scopetime::scope_time;
1011
use std::path::Path;
1112

@@ -49,7 +50,7 @@ pub fn stage_lines(
4950
let blob_id = repo.blob(new_content.as_bytes())?;
5051

5152
idx.id = blob_id;
52-
idx.file_size = new_content.as_bytes().len() as u32;
53+
idx.file_size = u32::try_conv(new_content.as_bytes().len())?;
5354
//TODO: can we simply use add_frombuffer?
5455
index.add(&idx)?;
5556

0 commit comments

Comments
 (0)