Skip to content

Commit f225090

Browse files
authored
Merge pull request #29 from tsemo4917/clippy
fix some clippy warnings, use `PhantomData` for the lifetime marker in Iter and IterMut
2 parents a5136d6 + 7fc1cdf commit f225090

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
115115
}
116116
}
117117

118-
let result = self.free_list[class].iter().next().clone();
118+
let result = self.free_list[class].iter().next();
119119
if let Some(result_ref) = result {
120120
let result = *result_ref;
121121
self.free_list[class].remove(&result);
@@ -155,7 +155,7 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
155155
let mut current_class = class;
156156
while current_class < self.free_list.len() {
157157
let buddy = current_ptr ^ (1 << current_class);
158-
if self.free_list[current_class].remove(&buddy) == true {
158+
if self.free_list[current_class].remove(&buddy) {
159159
// Free buddy found
160160
current_ptr = min(current_ptr, buddy);
161161
current_class += 1;

src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ extern crate spin;
1010

1111
extern crate alloc;
1212

13-
use core::alloc::{GlobalAlloc, Layout};
13+
#[cfg(feature = "use_spin")]
14+
use core::alloc::GlobalAlloc;
15+
use core::alloc::Layout;
1416
use core::cmp::{max, min};
1517
use core::fmt;
1618
use core::mem::size_of;
@@ -76,7 +78,7 @@ impl<const ORDER: usize> Heap<ORDER> {
7678
pub unsafe fn add_to_heap(&mut self, mut start: usize, mut end: usize) {
7779
// avoid unaligned access on some platforms
7880
start = (start + size_of::<usize>() - 1) & (!size_of::<usize>() + 1);
79-
end = end & (!size_of::<usize>() + 1);
81+
end &= !size_of::<usize>() + 1;
8082
assert!(start <= end);
8183

8284
let mut total = 0;
@@ -338,5 +340,5 @@ unsafe impl<const ORDER: usize> GlobalAlloc for LockedHeapWithRescue<ORDER> {
338340
}
339341

340342
pub(crate) fn prev_power_of_two(num: usize) -> usize {
341-
1 << (8 * (size_of::<usize>()) - num.leading_zeros() as usize - 1)
343+
1 << (usize::BITS as usize - num.leading_zeros() as usize - 1)
342344
}

src/linked_list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Provide the intrusive LinkedList
2-
#![allow(dead_code)]
32
3+
use core::marker::PhantomData;
44
use core::{fmt, ptr};
55

66
/// An intrusive linked list
@@ -52,7 +52,7 @@ impl LinkedList {
5252
pub fn iter(&self) -> Iter {
5353
Iter {
5454
curr: self.head,
55-
list: self,
55+
list: PhantomData,
5656
}
5757
}
5858

@@ -61,7 +61,7 @@ impl LinkedList {
6161
IterMut {
6262
prev: &mut self.head as *mut *mut usize as *mut usize,
6363
curr: self.head,
64-
list: self,
64+
list: PhantomData,
6565
}
6666
}
6767
}
@@ -75,7 +75,7 @@ impl fmt::Debug for LinkedList {
7575
/// An iterator over the linked list
7676
pub struct Iter<'a> {
7777
curr: *mut usize,
78-
list: &'a LinkedList,
78+
list: PhantomData<&'a LinkedList>,
7979
}
8080

8181
impl<'a> Iterator for Iter<'a> {
@@ -117,7 +117,7 @@ impl ListNode {
117117

118118
/// A mutable iterator over the linked list
119119
pub struct IterMut<'a> {
120-
list: &'a mut LinkedList,
120+
list: PhantomData<&'a mut LinkedList>,
121121
prev: *mut usize,
122122
curr: *mut usize,
123123
}

0 commit comments

Comments
 (0)