Skip to content

Commit 1bc6ae8

Browse files
Apply various Clippy recommendations (#603)
1 parent 0062c29 commit 1bc6ae8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+124
-140
lines changed

bytes/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub mod arc {
9696
sequestered: self.sequestered.clone(),
9797
};
9898

99-
unsafe { self.ptr = self.ptr.offset(index as isize); }
99+
unsafe { self.ptr = self.ptr.add(index); }
100100
self.len -= index;
101101

102102
result
@@ -161,7 +161,7 @@ pub mod arc {
161161
/// shared4.try_merge(shared2).ok().expect("Failed to merge 4 and 231");
162162
/// ```
163163
pub fn try_merge(&mut self, other: Bytes) -> Result<(), Bytes> {
164-
if Arc::ptr_eq(&self.sequestered, &other.sequestered) && ::std::ptr::eq(unsafe { self.ptr.offset(self.len as isize) }, other.ptr) {
164+
if Arc::ptr_eq(&self.sequestered, &other.sequestered) && ::std::ptr::eq(unsafe { self.ptr.add(self.len) }, other.ptr) {
165165
self.len += other.len;
166166
Ok(())
167167
}

communication/src/allocator/process.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl AllocateBuilder for ProcessBuilder {
3535

3636
// Initialize buzzers; send first, then recv.
3737
for worker in self.buzzers_send.iter() {
38-
let buzzer = Buzzer::new();
38+
let buzzer = Buzzer::default();
3939
worker.send(buzzer).expect("Failed to send buzzer");
4040
}
4141
let mut buzzers = Vec::with_capacity(self.buzzers_recv.len());
@@ -88,8 +88,8 @@ impl Process {
8888

8989
counters_recv
9090
.into_iter()
91-
.zip(buzzers_send.into_iter())
92-
.zip(buzzers_recv.into_iter())
91+
.zip(buzzers_send)
92+
.zip(buzzers_recv)
9393
.enumerate()
9494
.map(|(index, ((recv, bsend), brecv))| {
9595
ProcessBuilder {

communication/src/allocator/thread.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ pub struct ThreadBuilder;
1515

1616
impl AllocateBuilder for ThreadBuilder {
1717
type Allocator = Thread;
18-
fn build(self) -> Self::Allocator { Thread::new() }
18+
fn build(self) -> Self::Allocator { Thread::default() }
1919
}
2020

2121

2222
/// An allocator for intra-thread communication.
23+
#[derive(Default)]
2324
pub struct Thread {
2425
/// Shared counts of messages in channels.
2526
events: Rc<RefCell<Vec<usize>>>,
@@ -53,13 +54,6 @@ pub type ThreadPusher<T> = CountPusher<T, Pusher<T>>;
5354
pub type ThreadPuller<T> = CountPuller<T, Puller<T>>;
5455

5556
impl Thread {
56-
/// Allocates a new thread-local channel allocator.
57-
pub fn new() -> Self {
58-
Thread {
59-
events: Rc::new(RefCell::new(Default::default())),
60-
}
61-
}
62-
6357
/// Creates a new thread-local channel from an identifier and shared counts.
6458
pub fn new_from<T: 'static>(identifier: usize, events: Rc<RefCell<Vec<usize>>>)
6559
-> (ThreadPusher<T>, ThreadPuller<T>)

communication/src/allocator/zero_copy/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<A: AllocateBuilder> TcpBuilder<A> {
8282
// Fulfill puller obligations.
8383
let mut recvs = Vec::with_capacity(self.peers);
8484
for promise in self.promises.into_iter() {
85-
let buzzer = crate::buzzer::Buzzer::new();
85+
let buzzer = crate::buzzer::Buzzer::default();
8686
let queue = MergeQueue::new(buzzer);
8787
promise.send(queue.clone()).expect("Failed to send MergeQueue");
8888
recvs.push(queue.clone());

communication/src/allocator/zero_copy/allocator_process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl ProcessBuilder {
6060
// Fulfill puller obligations.
6161
let mut recvs = Vec::with_capacity(self.peers);
6262
for puller in self.pullers.into_iter() {
63-
let buzzer = crate::buzzer::Buzzer::new();
63+
let buzzer = crate::buzzer::Buzzer::default();
6464
let queue = MergeQueue::new(buzzer);
6565
puller.send(queue.clone()).expect("Failed to send MergeQueue");
6666
recvs.push(queue.clone());

communication/src/allocator/zero_copy/initialize.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ pub fn initialize_networking_from_sockets<S: Stream + 'static>(
6363
-> ::std::io::Result<(Vec<TcpBuilder<ProcessBuilder>>, CommsGuard)>
6464
{
6565
// Sockets are expected to be blocking,
66-
for socket in sockets.iter_mut() {
67-
if let Some(socket) = socket {
68-
socket.set_nonblocking(false).expect("failed to set socket to blocking");
69-
}
66+
for socket in sockets.iter_mut().flatten() {
67+
socket.set_nonblocking(false).expect("failed to set socket to blocking");
7068
}
7169

7270
let processes = sockets.len();

communication/src/allocator/zero_copy/tcp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//!
1+
//! Methods related to reading from and writing to TCP connections
22
33
use std::io::{self, Write};
44
use crossbeam_channel::{Sender, Receiver};
@@ -67,9 +67,9 @@ where
6767
assert!(!buffer.empty().is_empty());
6868

6969
// Attempt to read some more bytes into self.buffer.
70-
let read = match reader.read(&mut buffer.empty()) {
70+
let read = match reader.read(buffer.empty()) {
7171
Err(x) => tcp_panic("reading data", x),
72-
Ok(n) if n == 0 => {
72+
Ok(0) => {
7373
tcp_panic(
7474
"reading data",
7575
std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "socket closed"),
@@ -102,7 +102,7 @@ where
102102
panic!("Clean shutdown followed by data.");
103103
}
104104
buffer.ensure_capacity(1);
105-
if reader.read(&mut buffer.empty()).unwrap_or_else(|e| tcp_panic("reading EOF", e)) > 0 {
105+
if reader.read(buffer.empty()).unwrap_or_else(|e| tcp_panic("reading EOF", e)) > 0 {
106106
panic!("Clean shutdown followed by data.");
107107
}
108108
}
@@ -141,7 +141,7 @@ pub fn send_loop<S: Stream>(
141141
logger.as_mut().map(|l| l.log(StateEvent { send: true, process, remote, start: true, }));
142142

143143
let mut sources: Vec<MergeQueue> = sources.into_iter().map(|x| {
144-
let buzzer = crate::buzzer::Buzzer::new();
144+
let buzzer = crate::buzzer::Buzzer::default();
145145
let queue = MergeQueue::new(buzzer);
146146
x.send(queue.clone()).expect("failed to send MergeQueue");
147147
queue

communication/src/buzzer.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ pub struct Buzzer {
88
thread: Thread,
99
}
1010

11+
impl Default for Buzzer {
12+
fn default() -> Self { Self { thread: std::thread::current() } }
13+
}
14+
1115
impl Buzzer {
12-
/// Creates a new buzzer for the current thread.
13-
pub fn new() -> Self {
14-
Self {
15-
thread: std::thread::current()
16-
}
17-
}
1816
/// Unparks the target thread.
1917
pub fn buzz(&self) {
2018
self.thread.unpark()

communication/src/initialize.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ impl Config {
155155
Ok((vec![GenericBuilder::Thread(ThreadBuilder)], Box::new(())))
156156
},
157157
Config::Process(threads) => {
158-
Ok((Process::new_vector(threads).into_iter().map(|x| GenericBuilder::Process(x)).collect(), Box::new(())))
158+
Ok((Process::new_vector(threads).into_iter().map(GenericBuilder::Process).collect(), Box::new(())))
159159
},
160160
Config::ProcessBinary(threads) => {
161-
Ok((ProcessBuilder::new_vector(threads).into_iter().map(|x| GenericBuilder::ProcessBinary(x)).collect(), Box::new(())))
161+
Ok((ProcessBuilder::new_vector(threads).into_iter().map(GenericBuilder::ProcessBinary).collect(), Box::new(())))
162162
},
163163
Config::Cluster { threads, process, addresses, report, log_fn } => {
164164
match initialize_networking(addresses, process, threads, report, log_fn) {
165165
Ok((stuff, guard)) => {
166-
Ok((stuff.into_iter().map(|x| GenericBuilder::ZeroCopy(x)).collect(), Box::new(guard)))
166+
Ok((stuff.into_iter().map(GenericBuilder::ZeroCopy).collect(), Box::new(guard)))
167167
},
168168
Err(err) => Err(format!("failed to initialize networking: {}", err))
169169
}

communication/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ fn promise_futures<T>(sends: usize, recvs: usize) -> (Vec<Vec<Sender<T>>>, Vec<V
181181
let mut senders: Vec<_> = (0 .. sends).map(|_| Vec::with_capacity(recvs)).collect();
182182
let mut recvers: Vec<_> = (0 .. recvs).map(|_| Vec::with_capacity(sends)).collect();
183183

184-
for sender in 0 .. sends {
185-
for recver in 0 .. recvs {
184+
for sender in senders.iter_mut() {
185+
for recver in recvers.iter_mut() {
186186
let (send, recv) = crossbeam_channel::unbounded();
187-
senders[sender].push(send);
188-
recvers[recver].push(recv);
187+
sender.push(send);
188+
recver.push(recv);
189189
}
190190
}
191191

0 commit comments

Comments
 (0)