Skip to content

Commit 33e2e71

Browse files
authored
Rollup merge of #115489 - saethlin:is-interrupted, r=thomcc
Use std::io::Error::is_interrupted everywhere In #115228 I introduced this helper and started using it, this PR uses it to replace all applicable uses of `std::io::Error::kind`. The justification is the same; for whatever reason LLVM totally flops optimizing `Error::kind` so it's nice to use it less. FYI ``@mkroening`` I swear the hermit changes look good, but I was so sure about the previous PR.
2 parents d22043c + 642251b commit 33e2e71

File tree

11 files changed

+18
-17
lines changed

11 files changed

+18
-17
lines changed

library/std/src/io/buffered/bufwriter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<W: ?Sized + Write> BufWriter<W> {
237237
));
238238
}
239239
Ok(n) => guard.consume(n),
240-
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
240+
Err(ref e) if e.is_interrupted() => {}
241241
Err(e) => return Err(e),
242242
}
243243
}

library/std/src/io/copy.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{BorrowedBuf, BufReader, BufWriter, ErrorKind, Read, Result, Write, DEFAULT_BUF_SIZE};
1+
use super::{BorrowedBuf, BufReader, BufWriter, Read, Result, Write, DEFAULT_BUF_SIZE};
22
use crate::alloc::Allocator;
33
use crate::cmp;
44
use crate::collections::VecDeque;
@@ -30,6 +30,7 @@ mod tests;
3030
///
3131
/// [`read`]: Read::read
3232
/// [`write`]: Write::write
33+
/// [`ErrorKind::Interrupted`]: crate::io::ErrorKind::Interrupted
3334
///
3435
/// # Examples
3536
///
@@ -163,7 +164,7 @@ where
163164
// from adding I: Read
164165
match self.read(&mut []) {
165166
Ok(_) => {}
166-
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
167+
Err(e) if e.is_interrupted() => continue,
167168
Err(e) => return Err(e),
168169
}
169170
let buf = self.buffer();
@@ -243,7 +244,7 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
243244
// Read again if the buffer still has enough capacity, as BufWriter itself would do
244245
// This will occur if the reader returns short reads
245246
}
246-
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
247+
Err(ref e) if e.is_interrupted() => {}
247248
Err(e) => return Err(e),
248249
}
249250
} else {
@@ -275,7 +276,7 @@ impl<A: Allocator> BufferedWriterSpec for Vec<u8, A> {
275276
let mut buf: BorrowedBuf<'_> = self.spare_capacity_mut().into();
276277
match reader.read_buf(buf.unfilled()) {
277278
Ok(()) => {}
278-
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
279+
Err(e) if e.is_interrupted() => continue,
279280
Err(e) => return Err(e),
280281
};
281282

@@ -307,7 +308,7 @@ fn stack_buffer_copy<R: Read + ?Sized, W: Write + ?Sized>(
307308
loop {
308309
match reader.read_buf(buf.unfilled()) {
309310
Ok(()) => {}
310-
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
311+
Err(e) if e.is_interrupted() => continue,
311312
Err(e) => return Err(e),
312313
};
313314

library/std/src/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ pub trait Write {
16471647
));
16481648
}
16491649
Ok(n) => IoSlice::advance_slices(&mut bufs, n),
1650-
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
1650+
Err(ref e) if e.is_interrupted() => {}
16511651
Err(e) => return Err(e),
16521652
}
16531653
}

library/std/src/os/unix/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait FileExt {
123123
buf = &mut tmp[n..];
124124
offset += n as u64;
125125
}
126-
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
126+
Err(ref e) if e.is_interrupted() => {}
127127
Err(e) => return Err(e),
128128
}
129129
}
@@ -258,7 +258,7 @@ pub trait FileExt {
258258
buf = &buf[n..];
259259
offset += n as u64
260260
}
261-
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
261+
Err(ref e) if e.is_interrupted() => {}
262262
Err(e) => return Err(e),
263263
}
264264
}

library/std/src/os/wasi/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub trait FileExt {
8282
buf = &mut tmp[n..];
8383
offset += n as u64;
8484
}
85-
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
85+
Err(ref e) if e.is_interrupted() => {}
8686
Err(e) => return Err(e),
8787
}
8888
}
@@ -162,7 +162,7 @@ pub trait FileExt {
162162
buf = &buf[n..];
163163
offset += n as u64
164164
}
165-
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
165+
Err(ref e) if e.is_interrupted() => {}
166166
Err(e) => return Err(e),
167167
}
168168
}

library/std/src/sys/hermit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ where
200200
{
201201
loop {
202202
match cvt(f()) {
203-
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
203+
Err(ref e) if e.is_interrupted() => {}
204204
other => return other,
205205
}
206206
}

library/std/src/sys/hermit/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Socket {
102102
match unsafe { netc::poll(&mut pollfd, 1, timeout) } {
103103
-1 => {
104104
let err = io::Error::last_os_error();
105-
if err.kind() != io::ErrorKind::Interrupted {
105+
if !err.is_interrupted() {
106106
return Err(err);
107107
}
108108
}

library/std/src/sys/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ impl Drop for Dir {
792792
fn drop(&mut self) {
793793
let r = unsafe { libc::closedir(self.0) };
794794
assert!(
795-
r == 0 || crate::io::Error::last_os_error().kind() == crate::io::ErrorKind::Interrupted,
795+
r == 0 || crate::io::Error::last_os_error().is_interrupted(),
796796
"unexpected error during closedir: {:?}",
797797
crate::io::Error::last_os_error()
798798
);

library/std/src/sys/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ where
320320
{
321321
loop {
322322
match cvt(f()) {
323-
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
323+
Err(ref e) if e.is_interrupted() => {}
324324
other => return other,
325325
}
326326
}

library/std/src/sys/unix/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Socket {
184184
match unsafe { libc::poll(&mut pollfd, 1, timeout) } {
185185
-1 => {
186186
let err = io::Error::last_os_error();
187-
if err.kind() != io::ErrorKind::Interrupted {
187+
if !err.is_interrupted() {
188188
return Err(err);
189189
}
190190
}

library/std/src/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Command {
165165
assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
166166
return Err(Error::from_raw_os_error(errno));
167167
}
168-
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
168+
Err(ref e) if e.is_interrupted() => {}
169169
Err(e) => {
170170
assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
171171
panic!("the CLOEXEC pipe failed: {e:?}")

0 commit comments

Comments
 (0)