Skip to content

Commit 96c4b85

Browse files
committed
chore: fix clippy lints and cargo check warnings
Mostly a 'cargo clippy --fix --all-features --all-targets', plus some manual fixes for elided lifetimes.
1 parent 54716a1 commit 96c4b85

File tree

17 files changed

+331
-379
lines changed

17 files changed

+331
-379
lines changed

cap-async-std/src/net/tcp_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl TcpListener {
6767
///
6868
/// This corresponds to [`async_std::net::TcpListener::incoming`].
6969
#[inline]
70-
pub fn incoming(&self) -> Incoming {
70+
pub fn incoming(&self) -> Incoming<'_> {
7171
let incoming = self.std.incoming();
7272
Incoming::from_std(incoming)
7373
}

cap-async-std/src/os/unix/net/unix_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl UnixListener {
6969
///
7070
/// [`async_std::os::unix::net::UnixListener::incoming`]: https://docs.rs/async-std/latest/async_std/os/unix/net/struct.UnixListener.html#method.incoming
7171
#[inline]
72-
pub fn incoming(&self) -> Incoming {
72+
pub fn incoming(&self) -> Incoming<'_> {
7373
let incoming = self.std.incoming();
7474
Incoming::from_std(incoming)
7575
}

cap-primitives/src/fs/via_parent/open_parent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn open_parent<'path, 'borrow>(
3737
/// - Append a `.` to a path with a trailing `..` to avoid requiring our
3838
/// callers to special-case `..`.
3939
/// - Bare absolute paths are ok.
40-
fn split_parent(path: &Path) -> Option<(&Path, Component)> {
40+
fn split_parent(path: &Path) -> Option<(&Path, Component<'_>)> {
4141
if path.as_os_str().is_empty() {
4242
return None;
4343
}

cap-std/src/net/tcp_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl TcpListener {
7272
///
7373
/// This corresponds to [`std::net::TcpListener::incoming`].
7474
#[inline]
75-
pub fn incoming(&self) -> Incoming {
75+
pub fn incoming(&self) -> Incoming<'_> {
7676
let incoming = self.std.incoming();
7777
Incoming::from_std(incoming)
7878
}

cap-std/src/os/unix/net/unix_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl UnixListener {
9090
///
9191
/// [`std::os::unix::net::UnixListener::incoming`]: https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.incoming
9292
#[inline]
93-
pub fn incoming(&self) -> Incoming {
93+
pub fn incoming(&self) -> Incoming<'_> {
9494
let incoming = self.std.incoming();
9595
Incoming::from_std(incoming)
9696
}

examples/async_std_fs_misc.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ async fn main() {
4545
println!("`mkdir a`");
4646

4747
// Create a directory, returns `io::Result<()>`
48-
match cwd.create_dir("a") {
49-
Err(why) => println!("! {:?}", why.kind()),
50-
Ok(_) => {}
51-
}
48+
if let Err(why) = cwd.create_dir("a") { println!("! {:?}", why.kind()) }
5249

5350
println!("`echo hello > a/b.txt`");
5451
// The previous match can be simplified using the `unwrap_or_else` method
55-
echo("hello", &mut cwd, &Path::new("a/b.txt"))
52+
echo("hello", &mut cwd, Path::new("a/b.txt"))
5653
.await
5754
.unwrap_or_else(|why| {
5855
println!("! {:?}", why.kind());
@@ -65,7 +62,7 @@ async fn main() {
6562
});
6663

6764
println!("`touch a/c/e.txt`");
68-
touch(&mut cwd, &Path::new("a/c/e.txt"))
65+
touch(&mut cwd, Path::new("a/c/e.txt"))
6966
.await
7067
.unwrap_or_else(|why| {
7168
println!("! {:?}", why.kind());
@@ -83,7 +80,7 @@ async fn main() {
8380
}
8481

8582
println!("`cat a/c/b.txt`");
86-
match cat(&mut cwd, &Path::new("a/c/b.txt")).await {
83+
match cat(&mut cwd, Path::new("a/c/b.txt")).await {
8784
Err(why) => println!("! {:?}", why.kind()),
8885
Ok(s) => println!("> {}", s),
8986
}

examples/std_fs_misc.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ fn main() {
3939
println!("`mkdir a`");
4040

4141
// Create a directory, returns `io::Result<()>`
42-
match cwd.create_dir("a") {
43-
Err(why) => println!("! {:?}", why.kind()),
44-
Ok(_) => {}
45-
}
42+
if let Err(why) = cwd.create_dir("a") { println!("! {:?}", why.kind()) }
4643

4744
println!("`echo hello > a/b.txt`");
4845
// The previous match can be simplified using the `unwrap_or_else` method
49-
echo("hello", &mut cwd, &Path::new("a/b.txt")).unwrap_or_else(|why| {
46+
echo("hello", &mut cwd, Path::new("a/b.txt")).unwrap_or_else(|why| {
5047
println!("! {:?}", why.kind());
5148
});
5249

@@ -57,7 +54,7 @@ fn main() {
5754
});
5855

5956
println!("`touch a/c/e.txt`");
60-
touch(&mut cwd, &Path::new("a/c/e.txt")).unwrap_or_else(|why| {
57+
touch(&mut cwd, Path::new("a/c/e.txt")).unwrap_or_else(|why| {
6158
println!("! {:?}", why.kind());
6259
});
6360

@@ -71,7 +68,7 @@ fn main() {
7168
}
7269

7370
println!("`cat a/c/b.txt`");
74-
match cat(&mut cwd, &Path::new("a/c/b.txt")) {
71+
match cat(&mut cwd, Path::new("a/c/b.txt")) {
7572
Err(why) => println!("! {:?}", why.kind()),
7673
Ok(s) => println!("> {}", s),
7774
}

tests/cap-net-ext-udp-split.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ fn socket_smoke_test_ip4() {
6262
let client =
6363
UdpSocket::new(AddressFamily::of_socket_addr(client_ip), Blocking::Yes).unwrap();
6464
t!(client_pool
65-
.udp_binder(&client_ip)
65+
.udp_binder(client_ip)
6666
.unwrap()
6767
.bind_existing_udp_socket(&client));
6868
rx1.recv().unwrap();
69-
t!(p.send_to_udp_socket_addr(&client, &[99], &server_ip));
69+
t!(p.send_to_udp_socket_addr(&client, &[99], server_ip));
7070
tx2.send(()).unwrap();
7171
});
7272

7373
let server =
7474
UdpSocket::new(AddressFamily::of_socket_addr(server_ip), Blocking::Yes).unwrap();
7575
t!(server_pool
76-
.udp_binder(&server_ip)
76+
.udp_binder(server_ip)
7777
.unwrap()
7878
.bind_existing_udp_socket(&server));
7979
tx1.send(()).unwrap();
@@ -94,7 +94,7 @@ fn socket_name() {
9494

9595
let server = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
9696
t!(pool
97-
.udp_binder(&addr)
97+
.udp_binder(addr)
9898
.unwrap()
9999
.bind_existing_udp_socket(&server));
100100
assert_eq!(addr, t!(server.local_addr()));
@@ -111,15 +111,15 @@ fn socket_peer() {
111111

112112
let server = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
113113
t!(pool1
114-
.udp_binder(&addr1)
114+
.udp_binder(addr1)
115115
.unwrap()
116116
.bind_existing_udp_socket(&server));
117117
assert_eq!(
118118
server.peer_addr().unwrap_err().kind(),
119119
ErrorKind::NotConnected
120120
);
121121
t!(pool2
122-
.udp_connecter(&addr2)
122+
.udp_connecter(addr2)
123123
.unwrap()
124124
.connect_existing_udp_socket(&server));
125125
assert_eq!(addr2, t!(server.peer_addr()));
@@ -136,20 +136,20 @@ fn udp_clone_smoke() {
136136

137137
let sock1 = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
138138
t!(pool1
139-
.udp_binder(&addr1)
139+
.udp_binder(addr1)
140140
.unwrap()
141141
.bind_existing_udp_socket(&sock1));
142142
let sock2 = UdpSocket::new(AddressFamily::of_socket_addr(addr2), Blocking::Yes).unwrap();
143143
t!(pool2
144-
.udp_binder(&addr2)
144+
.udp_binder(addr2)
145145
.unwrap()
146146
.bind_existing_udp_socket(&sock2));
147147

148148
let _t = thread::spawn(move || {
149149
let mut buf = [0, 0];
150150
assert_eq!(sock2.recv_from(&mut buf).unwrap(), (1, addr1));
151151
assert_eq!(buf[0], 1);
152-
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], &addr1));
152+
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], addr1));
153153
});
154154

155155
let sock3 = t!(sock1.try_clone());
@@ -159,7 +159,7 @@ fn udp_clone_smoke() {
159159
let p = pool2.clone();
160160
let _t = thread::spawn(move || {
161161
rx1.recv().unwrap();
162-
t!(p.send_to_udp_socket_addr(&sock3, &[1], &addr2));
162+
t!(p.send_to_udp_socket_addr(&sock3, &[1], addr2));
163163
tx2.send(()).unwrap();
164164
});
165165
tx1.send(()).unwrap();
@@ -179,21 +179,21 @@ fn udp_clone_two_read() {
179179

180180
let sock1 = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
181181
t!(pool1
182-
.udp_binder(&addr1)
182+
.udp_binder(addr1)
183183
.unwrap()
184184
.bind_existing_udp_socket(&sock1));
185185
let sock2 = UdpSocket::new(AddressFamily::of_socket_addr(addr2), Blocking::Yes).unwrap();
186186
t!(pool2
187-
.udp_binder(&addr2)
187+
.udp_binder(addr2)
188188
.unwrap()
189189
.bind_existing_udp_socket(&sock2));
190190
let (tx1, rx) = channel();
191191
let tx2 = tx1.clone();
192192

193193
let _t = thread::spawn(move || {
194-
t!(pool1.send_to_udp_socket_addr(&sock2, &[1], &addr1));
194+
t!(pool1.send_to_udp_socket_addr(&sock2, &[1], addr1));
195195
rx.recv().unwrap();
196-
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], &addr1));
196+
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], addr1));
197197
rx.recv().unwrap();
198198
});
199199

@@ -224,12 +224,12 @@ fn udp_clone_two_write() {
224224

225225
let sock1 = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
226226
t!(pool1
227-
.udp_binder(&addr1)
227+
.udp_binder(addr1)
228228
.unwrap()
229229
.bind_existing_udp_socket(&sock1));
230230
let sock2 = UdpSocket::new(AddressFamily::of_socket_addr(addr2), Blocking::Yes).unwrap();
231231
t!(pool2
232-
.udp_binder(&addr2)
232+
.udp_binder(addr2)
233233
.unwrap()
234234
.bind_existing_udp_socket(&sock2));
235235

@@ -249,12 +249,12 @@ fn udp_clone_two_write() {
249249
let tx2 = tx.clone();
250250
let p = pool2.clone();
251251
let _t = thread::spawn(move || {
252-
if p.send_to_udp_socket_addr(&sock3, &[1], &addr2).is_ok() {
252+
if p.send_to_udp_socket_addr(&sock3, &[1], addr2).is_ok() {
253253
let _ = tx2.send(());
254254
}
255255
done.send(()).unwrap();
256256
});
257-
if pool2.send_to_udp_socket_addr(&sock1, &[2], &addr2).is_ok() {
257+
if pool2.send_to_udp_socket_addr(&sock1, &[2], addr2).is_ok() {
258258
let _ = tx.send(());
259259
}
260260
drop(tx);
@@ -294,7 +294,7 @@ fn timeouts() {
294294

295295
let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
296296
t!(pool
297-
.udp_binder(&addr)
297+
.udp_binder(addr)
298298
.unwrap()
299299
.bind_existing_udp_socket(&stream));
300300
let dur = Duration::new(15410, 0);
@@ -325,7 +325,7 @@ fn test_read_timeout() {
325325

326326
let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
327327
t!(pool
328-
.udp_binder(&addr)
328+
.udp_binder(addr)
329329
.unwrap()
330330
.bind_existing_udp_socket(&stream));
331331
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));
@@ -336,8 +336,7 @@ fn test_read_timeout() {
336336
loop {
337337
let kind = stream
338338
.recv_from(&mut buf)
339-
.err()
340-
.expect("expected error")
339+
.expect_err("expected error")
341340
.kind();
342341
if kind != ErrorKind::Interrupted {
343342
assert!(
@@ -360,12 +359,12 @@ fn test_read_with_timeout() {
360359

361360
let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
362361
t!(pool
363-
.udp_binder(&addr)
362+
.udp_binder(addr)
364363
.unwrap()
365364
.bind_existing_udp_socket(&stream));
366365
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));
367366

368-
t!(pool.send_to_udp_socket_addr(&stream, b"hello world", &addr));
367+
t!(pool.send_to_udp_socket_addr(&stream, b"hello world", addr));
369368

370369
let mut buf = [0; 11];
371370
t!(stream.recv_from(&mut buf));
@@ -375,8 +374,7 @@ fn test_read_with_timeout() {
375374
loop {
376375
let kind = stream
377376
.recv_from(&mut buf)
378-
.err()
379-
.expect("expected error")
377+
.expect_err("expected error")
380378
.kind();
381379
if kind != ErrorKind::Interrupted {
382380
assert!(
@@ -401,7 +399,7 @@ fn test_timeout_zero_duration() {
401399

402400
let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
403401
t!(pool
404-
.udp_binder(&addr)
402+
.udp_binder(addr)
405403
.unwrap()
406404
.bind_existing_udp_socket(&socket));
407405

@@ -423,7 +421,7 @@ fn connect_send_recv() {
423421

424422
let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
425423
t!(pool
426-
.udp_binder(&addr)
424+
.udp_binder(addr)
427425
.unwrap()
428426
.bind_existing_udp_socket(&socket));
429427
t!(pool
@@ -446,7 +444,7 @@ fn connect_send_peek_recv() {
446444

447445
let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
448446
t!(pool
449-
.udp_binder(&addr)
447+
.udp_binder(addr)
450448
.unwrap()
451449
.bind_existing_udp_socket(&socket));
452450
t!(pool
@@ -478,10 +476,10 @@ fn peek_from() {
478476

479477
let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
480478
t!(pool
481-
.udp_binder(&addr)
479+
.udp_binder(addr)
482480
.unwrap()
483481
.bind_existing_udp_socket(&socket));
484-
t!(pool.send_to_udp_socket_addr(&socket, b"hello world", &addr));
482+
t!(pool.send_to_udp_socket_addr(&socket, b"hello world", addr));
485483

486484
for _ in 1..3 {
487485
let mut buf = [0; 11];
@@ -508,7 +506,7 @@ fn ttl() {
508506

509507
let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
510508
t!(pool
511-
.udp_binder(&addr)
509+
.udp_binder(addr)
512510
.unwrap()
513511
.bind_existing_udp_socket(&stream));
514512

@@ -524,7 +522,7 @@ fn set_nonblocking() {
524522

525523
let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
526524
t!(pool
527-
.udp_binder(&addr)
525+
.udp_binder(addr)
528526
.unwrap()
529527
.bind_existing_udp_socket(&socket));
530528

0 commit comments

Comments
 (0)