Skip to content

Commit

Permalink
chore: Error on clippy::cast_lossless
Browse files Browse the repository at this point in the history
This fires when there is a guaranteed lossless type conversion that could replace a cast.
  • Loading branch information
huitseeker committed Aug 15, 2023
1 parent 531d0f2 commit ae5e5b0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ xclippy = [
"-Wclippy::all",
"-Wclippy::disallowed_methods",
"-Wclippy::match_same_arms",
"-Wclippy::cast_lossless",
]
2 changes: 1 addition & 1 deletion fcomm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ impl<'a> Proof<'a, S1> {

let chunk_frame_count = self.reduction_count.count();
let expected_steps =
(iterations / chunk_frame_count) + (iterations % chunk_frame_count != 0) as usize;
(iterations / chunk_frame_count) + usize::from(iterations % chunk_frame_count != 0);

expected_steps == num_steps
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/circuit/circuit_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'a, F: LurkField, T: Clone + Copy + std::cmp::PartialEq, W: Copy, C: Coproc
) -> Vec<Self> {
// `count` is the number of `Frames` to include per `MultiFrame`.
let total_frames = frames.len();
let n = total_frames / count + (total_frames % count != 0) as usize;
let n = total_frames / count + usize::from(total_frames % count != 0);
let mut multi_frames = Vec::with_capacity(n);

for chunk in frames.chunks(count) {
Expand Down Expand Up @@ -5857,7 +5857,7 @@ mod tests {
.unwrap();
let popcount_result =
AllocatedNum::alloc(&mut cs.namespace(|| format!("alloc popcount {x}")), || {
Ok(Fr::from(x.count_ones() as u64))
Ok(Fr::from(u64::from(x.count_ones())))
})
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/coprocessor/trie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl<'a, F: LurkField, const ARITY: usize, const HEIGHT: usize> Trie<'a, F, ARIT
None => {
let field_significant_bits = F::NUM_BITS as usize;
let height_needed_for_field = field_significant_bits / arity_bits
+ ((field_significant_bits % arity_bits != 0) as usize);
+ usize::from(field_significant_bits % arity_bits != 0);

// HEIGHT must be exactly the minimum required so that every field element has a unique path.
assert_eq!(height_needed_for_field, HEIGHT);
Expand Down
6 changes: 3 additions & 3 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ pub trait LurkField: PrimeField + PrimeFieldBits {

/// Constructs a field element from a u32
fn from_u32(x: u32) -> Self {
(x as u64).into()
u64::from(x).into()
}
/// Constructs a field element from a u16
fn from_u16(x: u16) -> Self {
(x as u64).into()
u64::from(x).into()
}
/// Constructs a field element from a char
fn from_char(x: char) -> Self {
Expand Down Expand Up @@ -377,7 +377,7 @@ pub mod tests {
let mut res = F::ZERO;
let mut bs = bs.iter().rev().peekable();
while let Some(b) = bs.next() {
let b: F = (*b as u64).into();
let b: F = u64::from(*b).into();
if bs.peek().is_none() {
res.add_assign(b)
} else {
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#![deny(unreachable_pub)]
#![allow(clippy::uninlined_format_args)]
#![warn(rust_2018_idioms, unreachable_pub)]

#![deny(rust_2018_idioms, unreachable_pub)]
#[macro_use]
extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion src/parser/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn f_from_le_bytes<F: LurkField>(bs: &[u8]) -> F {
let mut res = F::ZERO;
let mut bs = bs.iter().rev().peekable();
while let Some(b) = bs.next() {
let b: F = (*b as u64).into();
let b: F = u64::from(*b).into();
if bs.peek().is_none() {
res.add_assign(b)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub trait Prover<'a, 'b, F: LurkField, C: Coprocessor<F>> {
let full_multiframe_count = raw_iterations / cfc;
let unfull_multiframe_frame_count = raw_iterations % cfc;
let raw_multiframe_count =
full_multiframe_count + (unfull_multiframe_frame_count != 0) as usize;
full_multiframe_count + usize::from(unfull_multiframe_frame_count != 0);
raw_multiframe_count + self.multiframe_padding_count(raw_multiframe_count)
}

Expand Down

0 comments on commit ae5e5b0

Please sign in to comment.