Skip to content

Commit fb88840

Browse files
authored
Fix clippy warnings (TheAlgorithms#113)
* Fix clippy idiomatic rust warnings * Fix clippy lint in heap.rs Allows MinHeap and MaxHeap new methods to return Heap Fixes incorrect is_empty() implementation. is_empty should return true when self.len() == 0. * Fix clippy lint This changes to use -= instead of manually implementing. Removes a lifetime that can be elided. * Turn on clippy warning failure in travis.yml
1 parent acb87d7 commit fb88840

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ before_script:
55
- rustup component add clippy
66
script:
77
- cargo fmt --all -- --check
8-
- cargo clippy
8+
- cargo clippy --all -- -D warnings
99
- cargo test

src/data_structures/b_tree.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ impl BTreeProps {
6868
}
6969
None => Vec::with_capacity(self.max_keys),
7070
};
71-
let mut right_children = None;
72-
if !child.is_leaf() {
73-
right_children = Some(child.children.split_off(self.mid_key_index + 1));
74-
}
71+
let right_children = if !child.is_leaf() {
72+
Some(child.children.split_off(self.mid_key_index + 1))
73+
} else {
74+
None
75+
};
7576
let new_child_node: Node<T> = Node::new(self.degree, Some(right_keys), right_children);
7677

7778
parent.keys.insert(child_index, middle_key);

src/data_structures/heap.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
}
3535

3636
pub fn is_empty(&self) -> bool {
37-
self.len() > 0
37+
self.len() == 0
3838
}
3939

4040
pub fn add(&mut self, value: T) {
@@ -135,6 +135,7 @@ where
135135
pub struct MinHeap;
136136

137137
impl MinHeap {
138+
#[allow(clippy::new_ret_no_self)]
138139
pub fn new<T>() -> Heap<T>
139140
where
140141
T: Default + Ord,
@@ -146,6 +147,7 @@ impl MinHeap {
146147
pub struct MaxHeap;
147148

148149
impl MaxHeap {
150+
#[allow(clippy::new_ret_no_self)]
149151
pub fn new<T>() -> Heap<T>
150152
where
151153
T: Default + Ord,

src/data_structures/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<T> LinkedList<T> {
5858
self.get_ith_node(self.start, index)
5959
}
6060

61-
fn get_ith_node<'a>(&'a mut self, node: Option<NonNull<Node<T>>>, index: i32) -> Option<&'a T> {
61+
fn get_ith_node(&mut self, node: Option<NonNull<Node<T>>>, index: i32) -> Option<&T> {
6262
match node {
6363
None => None,
6464
Some(next_ptr) => match index {

src/dynamic_programming/longest_common_subsequence.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ pub fn longest_common_subsequence(a: &str, b: &str) -> String {
3030
while i > 0 && j > 0 {
3131
if a[i - 1] == b[j - 1] {
3232
result.push(a[i - 1]);
33-
i = i - 1;
34-
j = j - 1;
33+
i -= 1;
34+
j -= 1;
3535
} else if solutions[i - 1][j] > solutions[i][j - 1] {
36-
i = i - 1;
36+
i -= 1;
3737
} else {
38-
j = j - 1;
38+
j -= 1;
3939
}
4040
}
4141

0 commit comments

Comments
 (0)