Skip to content

Commit

Permalink
Fix Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Sep 7, 2024
1 parent 3ed269f commit c3566eb
Show file tree
Hide file tree
Showing 102 changed files with 1,738 additions and 1,721 deletions.
2 changes: 1 addition & 1 deletion src/problem_0037_sudoku_solver/backtracking_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Solution {
}
}

#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn solve_sudoku(board: &mut Vec<Vec<char>>) {
Self::solve_sudoku_helper(board, 0).unwrap_err();
}
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0037_sudoku_solver/backtracking_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Solution {
}
}

#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn solve_sudoku(board: &mut Vec<Vec<char>>) {
let mut row_hits = [false; 81];
let mut column_hits = [false; 81];
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0048_rotate_image/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn rotate(matrix: &mut Vec<Vec<i32>>) {
let n = matrix.len();

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0048_rotate_image/reverse_then_transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn rotate(matrix: &mut Vec<Vec<i32>>) {
let n = matrix.len();

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0069_sqrtx/newtons_method_with_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ impl Solution {
pub fn my_sqrt(x: i32) -> i32 {
let x = x as u32;

#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss, reason = "optimal")]
let mut guess = f32::from_bits((x as f32).to_bits() / 2 + 0x1FC0_0000) as u32;

if guess * guess > x {
Expand Down
1 change: 0 additions & 1 deletion src/problem_0073_set_matrix_zeroes/two_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
pub fn set_zeroes(matrix: &mut Vec<Vec<i32>>) {
if let Some((first_row, rest_rows)) = matrix.split_first_mut() {
if let Some((first_row_first_cell, first_row_rest_cells)) = first_row.split_first_mut() {
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0073_set_matrix_zeroes/two_passes_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn set_zeroes(matrix: &mut Vec<Vec<i32>>) {
if let Some((first_row, rest_rows)) = matrix.split_first_mut() {
let first_row_has_zero = first_row.iter().any(|x| *x == 0);
Expand Down
1 change: 0 additions & 1 deletion src/problem_0075_sort_colors/counting_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
pub fn sort_colors(nums: &mut Vec<i32>) {
let mut counts = [0; 3];

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0088_merge_sorted_array/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Solution {
}
}

#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn merge(nums1: &mut Vec<i32>, m: i32, nums2: &mut Vec<i32>, n: i32) {
let mut m = m as usize;
let n = n as usize;
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0088_merge_sorted_array/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Solution {
}
}

#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn merge(nums1: &mut Vec<i32>, m: i32, nums2: &mut Vec<i32>, n: i32) {
let m = m as usize;
let n = n as usize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Solution {
let mut stack = Vec::new();

loop {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
if let Some(node) = root {
root = node.borrow().left.clone();
stack.push(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::rc::Rc;

impl Solution {
fn inorder_traversal_helper(mut root: Option<Rc<RefCell<TreeNode>>>, result: &mut Vec<i32>) {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
while let Some(node) = root {
let node_ref = node.borrow();

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0104_maximum_depth_of_binary_tree/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Solution {
let mut root = root;

loop {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
if let Some(node) = root {
let node = node.borrow();

Expand Down
1 change: 0 additions & 1 deletion src/problem_0130_surrounded_regions/bfs_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl Solution {
}
}

#[allow(clippy::ptr_arg)] // Expected.
pub fn solve(board: &mut Vec<Vec<char>>) {
let rows = board.len();
let columns = board.first().map_or(0, Vec::len);
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0140_word_break_ii/memoized_recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Node {
}

impl Solution {
#[allow(clippy::option_if_let_else)] // False positive.
#[expect(clippy::option_if_let_else, reason = "false positive")]
fn word_break_helper(s: &[u8], root: &Node, cache: &mut HashMap<*const u8, Rc<[String]>>) -> Rc<[String]> {
Rc::clone(if let Some(result) = cache.get(&s.as_ptr()) {
result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Solution {
let mut root = root;

loop {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
if let Some(node) = root {
let node_ref = node.borrow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::rc::Rc;

impl Solution {
fn preorder_traversal_helper(mut root: Option<Rc<RefCell<TreeNode>>>, result: &mut Vec<i32>) {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
while let Some(node) = root {
let node_ref = node.borrow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Solution {
let mut root = root;

'r: loop {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
if let Some(node) = root {
root = node.borrow().left.clone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Solution {
let mut root = root;

'r: loop {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
if let Some(node) = root {
root = node.borrow().left.clone();

Expand Down
4 changes: 2 additions & 2 deletions src/problem_0173_binary_search_tree_iterator/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl BSTIterator {
fn new(mut root: Option<Rc<RefCell<TreeNode>>>) -> Self {
let mut stack = Vec::new();

#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
while let Some(node) = root {
root = node.borrow().left.clone();

Expand All @@ -28,7 +28,7 @@ impl BSTIterator {
let node_ref = node.borrow();
let mut root = node_ref.right.clone();

#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
while let Some(node) = root {
root = node.borrow().left.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0173_binary_search_tree_iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests {
use super::BSTIterator;
use crate::test_utilities;

#[allow(variant_size_differences)]
#[expect(variant_size_differences, reason = "optimal")]
enum Operation {
Next(i32),
HasNext(bool),
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0189_rotate_array/cheating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn rotate(nums: &mut Vec<i32>, k: i32) {
let k = k as usize;
let length = nums.len();
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0189_rotate_array/cyclic_replacements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Solution {
x
}

#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn rotate(nums: &mut Vec<i32>, k: i32) {
let length = nums.len();
let k = (k as usize) % length;
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0189_rotate_array/triple_reverses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn rotate(nums: &mut Vec<i32>, k: i32) {
let length = nums.len();
let k = (k as usize) % length;
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0190_reverse_bits/divide_and_conquer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ impl Solution {
pub fn reverse_bits(n: u32) -> u32 {
let mut n = n;

n = (n >> 16) | (n << 16);
n = n.rotate_left(16);
n = ((n & 0xff00_ff00) >> 8) | ((n & 0x00ff_00ff) << 8);
n = ((n & 0xf0f0_f0f0) >> 4) | ((n & 0x0f0f_0f0f) << 4);
n = ((n & 0xcccc_cccc) >> 2) | ((n & 0x3333_3333) << 2);
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0191_number_of_1_bits/cheating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(non_snake_case)] // Expected.
#[expect(non_snake_case, reason = "required")]
pub fn hammingWeight(n: u32) -> i32 {
n.count_ones() as _
}
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0191_number_of_1_bits/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(non_snake_case)] // Expected.
#[expect(non_snake_case, reason = "required")]
pub fn hammingWeight(n: u32) -> i32 {
let mut result = 0;
let mut n = n;
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0191_number_of_1_bits/iterative_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(non_snake_case)] // Expected.
#[expect(non_snake_case, reason = "required")]
pub fn hammingWeight(n: u32) -> i32 {
let mut result = 0;
let mut n = n;
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0222_count_complete_tree_nodes/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Solution {
fn get_left_height(mut root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
let mut result = 0;

#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
while let Some(node) = root {
result += 1;

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0223_rectangle_area/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod normalize;

pub trait Solution {
#[allow(clippy::many_single_char_names, clippy::too_many_arguments)] // Expected.
#[expect(clippy::too_many_arguments, reason = "required")]
fn compute_area(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) -> i32;
}

Expand Down
4 changes: 2 additions & 2 deletions src/problem_0223_rectangle_area/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::many_single_char_names, clippy::too_many_arguments)] // Expected.
#[expect(clippy::many_single_char_names, clippy::too_many_arguments, reason = "required")]
pub fn compute_area(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) -> i32 {
let left = a.max(e);
let right = c.min(g);
Expand All @@ -26,7 +26,7 @@ impl Solution {
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl super::Solution for Solution {
#[allow(clippy::many_single_char_names, clippy::too_many_arguments)] // Expected.
#[expect(clippy::many_single_char_names, reason = "required")]
fn compute_area(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) -> i32 {
Self::compute_area(a, b, c, d, e, f, g, h)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Solution {
let mut k = k;

loop {
#[allow(clippy::assigning_clones)] // False positive.
#[expect(clippy::assigning_clones, reason = "false positive")]
if let Some(node) = root {
root = node.borrow().left.clone();
stack.push(node);
Expand Down
1 change: 0 additions & 1 deletion src/problem_0278_first_bad_version/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl super::Solution for Solution {
Self { bad }
}

#[allow(non_snake_case)] // Expected.
fn isBadVersion(&self, version: i32) -> bool {
version >= self.bad
}
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0278_first_bad_version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod binary_search;
pub trait Solution {
fn new(bad: i32) -> Self;

#[allow(non_snake_case)] // Expected.
#[expect(non_snake_case, reason = "required")]
fn isBadVersion(&self, version: i32) -> bool;

fn first_bad_version(&self, n: i32) -> i32;
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0283_move_zeroes/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn move_zeroes(nums: &mut Vec<i32>) {
let mut i = 0;
let mut tail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Codec {
Self
}

#[allow(clippy::unused_self)] // Expected.
#[expect(clippy::unused_self, reason = "required")]
fn serialize(&self, root: Option<Rc<RefCell<TreeNode>>>) -> String {
use std::fmt::Write;

Expand Down Expand Up @@ -58,7 +58,7 @@ impl Codec {
result
}

#[allow(clippy::unused_self)] // Expected.
#[expect(clippy::unused_self, reason = "required")]
fn deserialize(&self, data: String) -> Option<Rc<RefCell<TreeNode>>> {
let mut iter = data[1..data.len() - 1].split_terminator(',');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Codec {
}
}

#[allow(clippy::unused_self)] // Expected.
#[expect(clippy::unused_self, reason = "required")]
fn serialize(&self, root: Option<Rc<RefCell<TreeNode>>>) -> String {
let mut result = String::new();

Expand All @@ -47,7 +47,7 @@ impl Codec {
})
}

#[allow(clippy::unused_self)] // Expected.
#[expect(clippy::unused_self, reason = "required")]
fn deserialize(&self, data: String) -> Option<Rc<RefCell<TreeNode>>> {
Self::deserialize_helper(&mut data.split(' '))
}
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0324_wiggle_sort_ii/find_median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rand::{Rng, SeedableRng};
use std::cmp::Ordering;

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn wiggle_sort(nums: &mut Vec<i32>) {
let mut start = 0;
let mut end = nums.len();
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0344_reverse_string/cheating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn reverse_string(s: &mut Vec<char>) {
s.reverse();
}
Expand Down
2 changes: 1 addition & 1 deletion src/problem_0344_reverse_string/indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
#[allow(clippy::ptr_arg)] // Expected.
#[expect(clippy::ptr_arg, reason = "required")]
pub fn reverse_string(s: &mut Vec<char>) {
let length = s.len();

Expand Down
Loading

0 comments on commit c3566eb

Please sign in to comment.