Skip to content

Commit dda84cb

Browse files
committed
📝 fix cargo clippy warnings
1 parent e8389c0 commit dda84cb

File tree

10 files changed

+23
-22
lines changed

10 files changed

+23
-22
lines changed

examples/echo_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn main() {
7777

7878
let msg = vec![0; test_msg_len];
7979

80-
let err = io::Error::new(io::ErrorKind::Other, "can't resolve socket addresses");
80+
let err = io::Error::other("can't resolve socket addresses");
8181
let addr = t!(target_addr.to_socket_addrs())
8282
.fold(Err(err), |prev, addr| prev.or(Ok(addr)))
8383
.unwrap();

examples/echo_udp_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
let test_conn_num = args.flag_c;
7171
let test_seconds = args.flag_d;
7272

73-
let err = io::Error::new(io::ErrorKind::Other, "can't resolve socket addresses");
73+
let err = io::Error::other("can't resolve socket addresses");
7474
let addr = t!(target_addr.to_socket_addrs())
7575
.fold(Err(err), |prev, addr| prev.or(Ok(addr)))
7676
.unwrap();

examples/echo_udp_client1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
let test_conn_num = args.flag_c;
7171
let test_seconds = args.flag_d;
7272

73-
let err = io::Error::new(io::ErrorKind::Other, "can't resolve socket addresses");
73+
let err = io::Error::other("can't resolve socket addresses");
7474
let addr = t!(target_addr.to_socket_addrs())
7575
.fold(Err(err), |prev, addr| prev.or(Ok(addr)))
7676
.unwrap();

may_queue/src/mpsc_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<T> Queue<T> {
5353
pub fn is_empty(&self) -> bool {
5454
let tail = unsafe { *self.tail.get() };
5555
// the list is empty
56-
self.head.load(Ordering::Acquire) == tail
56+
std::ptr::eq(self.head.load(Ordering::Acquire), tail)
5757
}
5858

5959
/// Pops some data from this queue.
@@ -62,7 +62,7 @@ impl<T> Queue<T> {
6262
let tail = *self.tail.get();
6363

6464
// the list is empty
65-
if self.head.load(Ordering::Acquire) == tail {
65+
if std::ptr::eq(self.head.load(Ordering::Acquire), tail) {
6666
return None;
6767
}
6868

may_queue/src/mpsc_list_v1.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<T> Queue<T> {
172172
(*node).prev = prev;
173173
(*prev).next.store(node, Ordering::Release);
174174
let tail = *self.tail.get();
175-
let is_head = tail == prev;
175+
let is_head = std::ptr::eq(tail, prev);
176176
(Entry(ptr::NonNull::new_unchecked(node)), is_head)
177177
}
178178
}
@@ -182,7 +182,7 @@ impl<T> Queue<T> {
182182
pub fn is_empty(&self) -> bool {
183183
let tail = unsafe { *self.tail.get() };
184184
// the list is empty
185-
self.head.load(Ordering::Acquire) == tail
185+
std::ptr::eq(self.head.load(Ordering::Acquire), tail)
186186
}
187187

188188
/// get the head ref
@@ -192,7 +192,7 @@ impl<T> Queue<T> {
192192
pub unsafe fn peek(&self) -> Option<&T> {
193193
let tail = *self.tail.get();
194194
// the list is empty
195-
if self.head.load(Ordering::Acquire) == tail {
195+
if std::ptr::eq(self.head.load(Ordering::Acquire), tail) {
196196
return None;
197197
}
198198
// spin until tail next become non-null
@@ -219,7 +219,7 @@ impl<T> Queue<T> {
219219
unsafe {
220220
let tail = *self.tail.get();
221221
// the list is empty
222-
if self.head.load(Ordering::Acquire) == tail {
222+
if std::ptr::eq(self.head.load(Ordering::Acquire), tail) {
223223
return None;
224224
}
225225

@@ -270,7 +270,7 @@ impl<T> Queue<T> {
270270
let tail = *self.tail.get();
271271

272272
// the list is empty
273-
if self.head.load(Ordering::Acquire) == tail {
273+
if std::ptr::eq(self.head.load(Ordering::Acquire), tail) {
274274
return None;
275275
}
276276

may_queue/src/spmc.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<T> Queue<T> {
195195
loop {
196196
head = (head as usize & !(1 << 63)) as *mut BlockNode<T>;
197197
let (block, id) = BlockPtr::unpack(head);
198-
if block == tail_block && id >= (push_index & BLOCK_MASK) {
198+
if std::ptr::eq(block, tail_block) && id >= (push_index & BLOCK_MASK) {
199199
return None;
200200
}
201201

@@ -265,7 +265,7 @@ impl<T> Queue<T> {
265265
loop {
266266
head = (head as usize & !(1 << 63)) as *mut BlockNode<T>;
267267
let (block, id) = BlockPtr::unpack(head);
268-
if block == tail_block && id >= (push_index & BLOCK_MASK) {
268+
if std::ptr::eq(block, tail_block) && id >= (push_index & BLOCK_MASK) {
269269
return None;
270270
}
271271

@@ -336,11 +336,15 @@ impl<T> Queue<T> {
336336
let (block, id) = BlockPtr::unpack(head);
337337
let push_id = push_index & BLOCK_MASK;
338338
// at least leave one element to the owner
339-
if block == tail_block && id >= push_id {
339+
if std::ptr::eq(block, tail_block) && id >= push_id {
340340
return SmallVec::new();
341341
}
342342

343-
let new_id = if block != tail_block { 0 } else { push_id };
343+
let new_id = if !std::ptr::eq(block, tail_block) {
344+
0
345+
} else {
346+
push_id
347+
};
344348

345349
let new_head = if new_id == 0 {
346350
(head as usize | (1 << 63)) as *mut BlockNode<T>
@@ -435,7 +439,7 @@ impl<T> Queue<T> {
435439
let push_index = self.tail.index.load(Ordering::Acquire);
436440
let tail_block = self.tail.block.load(Ordering::Acquire);
437441

438-
block == tail_block && id == (push_index & BLOCK_MASK)
442+
std::ptr::eq(block, tail_block) && id == (push_index & BLOCK_MASK)
439443
}
440444
}
441445

may_queue/src/spsc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<T> Drop for Queue<T> {
310310
#[cfg(feature = "inner_cache")]
311311
let mut first = self.first.load(Ordering::Relaxed);
312312
#[cfg(feature = "inner_cache")]
313-
while first != tail {
313+
while !std::ptr::eq(first, tail) {
314314
let next = unsafe { &*first }.next.load(Ordering::Relaxed);
315315
let _ = unsafe { Box::from_raw(first) };
316316
first = next;

src/cancel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<T: CancelIo> CancelImpl<T> {
134134
if let Some(mut co) = co.take() {
135135
// this is not safe, the kernel may still need to use the overlapped
136136
// set the cancel result for the coroutine
137-
set_co_para(&mut co, io::Error::new(io::ErrorKind::Other, "Canceled"));
137+
set_co_para(&mut co, io::Error::other("Canceled"));
138138
get_scheduler().schedule(co);
139139
}
140140
}

src/io/sys/unix/net/tcp_stream_connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl TcpStreamConnect {
3333
// let err = io::Error::new(io::ErrorKind::Other, "no socket addresses resolved");
3434
addr.to_socket_addrs()?
3535
.next()
36-
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "no socket addresses resolved"))
36+
.ok_or_else(|| io::Error::other("no socket addresses resolved"))
3737
.and_then(|addr| {
3838
let stream = match addr {
3939
SocketAddr::V4(..) => Socket::new(Domain::IPV4, Type::STREAM, None)?,

src/yield_now.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ pub fn yield_with<T: EventSource>(resource: &T) {
2323
// if cancel detected in user space
2424
// no need to get into kernel any more
2525
if unlikely(cancel.is_canceled()) {
26-
co_set_para(::std::io::Error::new(
27-
::std::io::ErrorKind::Other,
28-
"Canceled",
29-
));
26+
co_set_para(std::io::Error::other("Canceled"));
3027
return resource.yield_back(cancel);
3128
}
3229

0 commit comments

Comments
 (0)