Skip to content

Commit 16ea589

Browse files
committed
Auto merge of rust-lang#137065 - jhpratt:rollup-ree9mej, r=jhpratt
Rollup of 9 pull requests Successful merges: - rust-lang#135687 (re-export `FromCoroutine` from `core::iter`) - rust-lang#135813 (CI: split i686-mingw job to three free runners) - rust-lang#136749 (Implement Extend<AsciiChar> for String) - rust-lang#136879 (Add safe new() to NotAllOnes) - rust-lang#136978 (Windows: Update generated bindings) - rust-lang#137028 (mir_build: Clarify some code for lowering `hir::PatExpr` to THIR) - rust-lang#137029 (Remove unnecessary check code in unused_delims) - rust-lang#137056 (made check_argument_compat public for use in miri) - rust-lang#137062 (Forward all default methods for I/O impls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9691b85 + c2b1e08 commit 16ea589

File tree

14 files changed

+2899
-2767
lines changed

14 files changed

+2899
-2767
lines changed

Diff for: alloc/src/string.rs

+26
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,32 @@ impl<'a> Extend<Cow<'a, str>> for String {
24422442
}
24432443
}
24442444

2445+
#[cfg(not(no_global_oom_handling))]
2446+
#[unstable(feature = "ascii_char", issue = "110998")]
2447+
impl Extend<core::ascii::Char> for String {
2448+
fn extend<I: IntoIterator<Item = core::ascii::Char>>(&mut self, iter: I) {
2449+
self.vec.extend(iter.into_iter().map(|c| c.to_u8()));
2450+
}
2451+
2452+
#[inline]
2453+
fn extend_one(&mut self, c: core::ascii::Char) {
2454+
self.vec.push(c.to_u8());
2455+
}
2456+
}
2457+
2458+
#[cfg(not(no_global_oom_handling))]
2459+
#[unstable(feature = "ascii_char", issue = "110998")]
2460+
impl<'a> Extend<&'a core::ascii::Char> for String {
2461+
fn extend<I: IntoIterator<Item = &'a core::ascii::Char>>(&mut self, iter: I) {
2462+
self.extend(iter.into_iter().cloned());
2463+
}
2464+
2465+
#[inline]
2466+
fn extend_one(&mut self, c: &'a core::ascii::Char) {
2467+
self.vec.push(c.to_u8());
2468+
}
2469+
}
2470+
24452471
/// A convenience impl that delegates to the impl for `&str`.
24462472
///
24472473
/// # Examples

Diff for: core/src/iter/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,14 @@ pub use self::adapters::{Intersperse, IntersperseWith};
420420
issue = "42168"
421421
)]
422422
pub use self::range::Step;
423+
#[stable(feature = "iter_empty", since = "1.2.0")]
424+
pub use self::sources::{Empty, empty};
423425
#[unstable(
424426
feature = "iter_from_coroutine",
425427
issue = "43122",
426428
reason = "coroutines are unstable"
427429
)]
428-
pub use self::sources::from_coroutine;
429-
#[stable(feature = "iter_empty", since = "1.2.0")]
430-
pub use self::sources::{Empty, empty};
430+
pub use self::sources::{FromCoroutine, from_coroutine};
431431
#[stable(feature = "iter_from_fn", since = "1.34.0")]
432432
pub use self::sources::{FromFn, from_fn};
433433
#[stable(feature = "iter_once", since = "1.2.0")]

Diff for: core/src/iter/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::empty::{Empty, empty};
1515
issue = "43122",
1616
reason = "coroutines are unstable"
1717
)]
18-
pub use self::from_coroutine::from_coroutine;
18+
pub use self::from_coroutine::{FromCoroutine, from_coroutine};
1919
#[stable(feature = "iter_from_fn", since = "1.34.0")]
2020
pub use self::from_fn::{FromFn, from_fn};
2121
#[stable(feature = "iter_once", since = "1.2.0")]

Diff for: core/src/num/niche_types.rs

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ macro_rules! define_valid_range_type {
3232
};
3333

3434
impl $name {
35+
#[inline]
36+
pub const fn new(val: $int) -> Option<Self> {
37+
if (val as $uint) >= ($low as $uint) && (val as $uint) <= ($high as $uint) {
38+
// SAFETY: just checked the inclusive range
39+
Some(unsafe { $name(val) })
40+
} else {
41+
None
42+
}
43+
}
44+
3545
/// Constructs an instance of this type from the underlying integer
3646
/// primitive without checking whether its zero.
3747
///

Diff for: coretests/tests/ascii_char.rs

+12
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ fn test_debug_control() {
2626
assert_eq!(want, format!("{chr:?}"), "byte: {byte}");
2727
}
2828
}
29+
30+
/// Tests Extend implementation for ascii::Char.
31+
#[test]
32+
fn test_extend() {
33+
let mut s = String::from("abc");
34+
s.extend_one(Char::SmallD);
35+
assert_eq!(s, String::from("abcd"));
36+
37+
let mut s = String::from("abc");
38+
s.extend(Char::CapitalA..=Char::CapitalC);
39+
assert_eq!(s, String::from("abcABC"));
40+
}

Diff for: coretests/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![feature(duration_constructors)]
2828
#![feature(error_generic_member_access)]
2929
#![feature(exact_size_is_empty)]
30+
#![feature(extend_one)]
3031
#![feature(extern_types)]
3132
#![feature(float_minimum_maximum)]
3233
#![feature(flt2dec)]

Diff for: std/src/io/impls.rs

+62
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl<R: Read + ?Sized> Read for &mut R {
4545
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
4646
(**self).read_exact(buf)
4747
}
48+
4849
#[inline]
4950
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
5051
(**self).read_buf_exact(cursor)
@@ -77,6 +78,11 @@ impl<W: Write + ?Sized> Write for &mut W {
7778
(**self).write_all(buf)
7879
}
7980

81+
#[inline]
82+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
83+
(**self).write_all_vectored(bufs)
84+
}
85+
8086
#[inline]
8187
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
8288
(**self).write_fmt(fmt)
@@ -89,10 +95,25 @@ impl<S: Seek + ?Sized> Seek for &mut S {
8995
(**self).seek(pos)
9096
}
9197

98+
#[inline]
99+
fn rewind(&mut self) -> io::Result<()> {
100+
(**self).rewind()
101+
}
102+
103+
#[inline]
104+
fn stream_len(&mut self) -> io::Result<u64> {
105+
(**self).stream_len()
106+
}
107+
92108
#[inline]
93109
fn stream_position(&mut self) -> io::Result<u64> {
94110
(**self).stream_position()
95111
}
112+
113+
#[inline]
114+
fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
115+
(**self).seek_relative(offset)
116+
}
96117
}
97118
#[stable(feature = "rust1", since = "1.0.0")]
98119
impl<B: BufRead + ?Sized> BufRead for &mut B {
@@ -106,11 +127,21 @@ impl<B: BufRead + ?Sized> BufRead for &mut B {
106127
(**self).consume(amt)
107128
}
108129

130+
#[inline]
131+
fn has_data_left(&mut self) -> io::Result<bool> {
132+
(**self).has_data_left()
133+
}
134+
109135
#[inline]
110136
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
111137
(**self).read_until(byte, buf)
112138
}
113139

140+
#[inline]
141+
fn skip_until(&mut self, byte: u8) -> io::Result<usize> {
142+
(**self).skip_until(byte)
143+
}
144+
114145
#[inline]
115146
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
116147
(**self).read_line(buf)
@@ -153,6 +184,7 @@ impl<R: Read + ?Sized> Read for Box<R> {
153184
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
154185
(**self).read_exact(buf)
155186
}
187+
156188
#[inline]
157189
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
158190
(**self).read_buf_exact(cursor)
@@ -185,6 +217,11 @@ impl<W: Write + ?Sized> Write for Box<W> {
185217
(**self).write_all(buf)
186218
}
187219

220+
#[inline]
221+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
222+
(**self).write_all_vectored(bufs)
223+
}
224+
188225
#[inline]
189226
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
190227
(**self).write_fmt(fmt)
@@ -197,10 +234,25 @@ impl<S: Seek + ?Sized> Seek for Box<S> {
197234
(**self).seek(pos)
198235
}
199236

237+
#[inline]
238+
fn rewind(&mut self) -> io::Result<()> {
239+
(**self).rewind()
240+
}
241+
242+
#[inline]
243+
fn stream_len(&mut self) -> io::Result<u64> {
244+
(**self).stream_len()
245+
}
246+
200247
#[inline]
201248
fn stream_position(&mut self) -> io::Result<u64> {
202249
(**self).stream_position()
203250
}
251+
252+
#[inline]
253+
fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
254+
(**self).seek_relative(offset)
255+
}
204256
}
205257
#[stable(feature = "rust1", since = "1.0.0")]
206258
impl<B: BufRead + ?Sized> BufRead for Box<B> {
@@ -214,11 +266,21 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
214266
(**self).consume(amt)
215267
}
216268

269+
#[inline]
270+
fn has_data_left(&mut self) -> io::Result<bool> {
271+
(**self).has_data_left()
272+
}
273+
217274
#[inline]
218275
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
219276
(**self).read_until(byte, buf)
220277
}
221278

279+
#[inline]
280+
fn skip_until(&mut self, byte: u8) -> io::Result<usize> {
281+
(**self).skip_until(byte)
282+
}
283+
222284
#[inline]
223285
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
224286
(**self).read_line(buf)

Diff for: std/src/os/fd/owned.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ impl BorrowedFd<'_> {
6767
/// The resource pointed to by `fd` must remain open for the duration of
6868
/// the returned `BorrowedFd`, and it must not have the value `-1`.
6969
#[inline]
70+
#[track_caller]
7071
#[rustc_const_stable(feature = "io_safety", since = "1.63.0")]
7172
#[stable(feature = "io_safety", since = "1.63.0")]
7273
pub const unsafe fn borrow_raw(fd: RawFd) -> Self {
73-
assert!(fd != u32::MAX as RawFd);
74-
// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
75-
let fd = unsafe { ValidRawFd::new_unchecked(fd) };
76-
Self { fd, _phantom: PhantomData }
74+
Self { fd: ValidRawFd::new(fd).expect("fd != -1"), _phantom: PhantomData }
7775
}
7876
}
7977

@@ -154,11 +152,9 @@ impl FromRawFd for OwnedFd {
154152
///
155153
/// [io-safety]: io#io-safety
156154
#[inline]
155+
#[track_caller]
157156
unsafe fn from_raw_fd(fd: RawFd) -> Self {
158-
assert_ne!(fd, u32::MAX as RawFd);
159-
// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
160-
let fd = unsafe { ValidRawFd::new_unchecked(fd) };
161-
Self { fd }
157+
Self { fd: ValidRawFd::new(fd).expect("fd != -1") }
162158
}
163159
}
164160

Diff for: std/src/os/solid/io.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,9 @@ impl BorrowedFd<'_> {
101101
/// the returned `BorrowedFd`, and it must not have the value
102102
/// `SOLID_NET_INVALID_FD`.
103103
#[inline]
104+
#[track_caller]
104105
pub const unsafe fn borrow_raw(fd: RawFd) -> Self {
105-
assert!(fd != -1 as RawFd);
106-
// SAFETY: we just asserted that the value is in the valid range and
107-
// isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
108-
let fd = unsafe { ValidRawFd::new_unchecked(fd) };
109-
Self { fd, _phantom: PhantomData }
106+
Self { fd: ValidRawFd::new(fd).expect("fd != -1"), _phantom: PhantomData }
110107
}
111108
}
112109

@@ -156,12 +153,9 @@ impl FromRawFd for OwnedFd {
156153
/// The resource pointed to by `fd` must be open and suitable for assuming
157154
/// ownership. The resource must not require any cleanup other than `close`.
158155
#[inline]
156+
#[track_caller]
159157
unsafe fn from_raw_fd(fd: RawFd) -> Self {
160-
assert_ne!(fd, -1 as RawFd);
161-
// SAFETY: we just asserted that the value is in the valid range and
162-
// isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
163-
let fd = unsafe { ValidRawFd::new_unchecked(fd) };
164-
Self { fd }
158+
Self { fd: ValidRawFd::new(fd).expect("fd != -1") }
165159
}
166160
}
167161

Diff for: std/src/os/windows/io/socket.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ impl BorrowedSocket<'_> {
5858
/// the returned `BorrowedSocket`, and it must not have the value
5959
/// `INVALID_SOCKET`.
6060
#[inline]
61+
#[track_caller]
6162
#[rustc_const_stable(feature = "io_safety", since = "1.63.0")]
6263
#[stable(feature = "io_safety", since = "1.63.0")]
6364
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
64-
assert!(socket != sys::c::INVALID_SOCKET as RawSocket);
65-
let socket = unsafe { ValidRawSocket::new_unchecked(socket) };
66-
Self { socket, _phantom: PhantomData }
65+
Self { socket: ValidRawSocket::new(socket).expect("socket != -1"), _phantom: PhantomData }
6766
}
6867
}
6968

@@ -185,10 +184,9 @@ impl IntoRawSocket for OwnedSocket {
185184
#[stable(feature = "io_safety", since = "1.63.0")]
186185
impl FromRawSocket for OwnedSocket {
187186
#[inline]
187+
#[track_caller]
188188
unsafe fn from_raw_socket(socket: RawSocket) -> Self {
189-
debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
190-
let socket = unsafe { ValidRawSocket::new_unchecked(socket) };
191-
Self { socket }
189+
Self { socket: ValidRawSocket::new(socket).expect("socket != -1") }
192190
}
193191
}
194192

Diff for: std/src/sys/pal/solid/fs.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ struct FileDesc {
2222

2323
impl FileDesc {
2424
#[inline]
25+
#[track_caller]
2526
fn new(fd: c_int) -> FileDesc {
26-
assert_ne!(fd, -1i32);
27-
// Safety: we just asserted that the value is in the valid range and
28-
// isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
29-
let fd = unsafe { CIntNotMinusOne::new_unchecked(fd) };
30-
FileDesc { fd }
27+
FileDesc { fd: CIntNotMinusOne::new(fd).expect("fd != -1") }
3128
}
3229

3330
#[inline]

0 commit comments

Comments
 (0)