Skip to content

Commit 251dc8a

Browse files
committed
Auto merge of #133059 - workingjubilee:rollup-rc5kvr1, r=workingjubilee
Rollup of 8 pull requests Successful merges: - #132790 (Add as_slice/into_slice for IoSlice/IoSliceMut.) - #132905 ([AIX] Add crate "unwind" to link with libunwind) - #132977 (Fix compilation error on Solaris due to flock usage) - #132984 ([illumos] use pipe2 to create anonymous pipes) - #133019 (docs: Fix missing period and colon in methods for primitive types) - #133048 (use `&raw` in `{read, write}_unaligned` documentation) - #133050 (Always inline functions signatures containing `f16` or `f128`) - #133053 (tests: Fix the SIMD FFI tests with certain x86 configuration) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3bc6916 + efe2c44 commit 251dc8a

File tree

21 files changed

+279
-52
lines changed

21 files changed

+279
-52
lines changed

compiler/rustc_mir_transform/src/cross_crate_inline.rs

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
5050
_ => {}
5151
}
5252

53+
let sig = tcx.fn_sig(def_id).instantiate_identity();
54+
for ty in sig.inputs().skip_binder().iter().chain(std::iter::once(&sig.output().skip_binder()))
55+
{
56+
// FIXME(f16_f128): in order to avoid crashes building `core`, always inline to skip
57+
// codegen if the function is not used.
58+
if ty == &tcx.types.f16 || ty == &tcx.types.f128 {
59+
return true;
60+
}
61+
}
62+
5363
// Don't do any inference when incremental compilation is enabled; the additional inlining that
5464
// inference permits also creates more work for small edits.
5565
if tcx.sess.opts.incremental.is_some() {

library/core/src/num/f128.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,8 @@ impl f128 {
12581258
min <= max,
12591259
"min > max, or either was NaN",
12601260
"min > max, or either was NaN. min = {min:?}, max = {max:?}",
1261-
// FIXME(f16_f128): Passed by-ref to avoid codegen crashes
1262-
min: &f128 = &min,
1263-
max: &f128 = &max,
1261+
min: f128,
1262+
max: f128,
12641263
);
12651264

12661265
if self < min {

library/core/src/num/f16.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,8 @@ impl f16 {
12351235
min <= max,
12361236
"min > max, or either was NaN",
12371237
"min > max, or either was NaN. min = {min:?}, max = {max:?}",
1238-
// FIXME(f16_f128): Passed by-ref to avoid codegen crashes
1239-
min: &f16 = &min,
1240-
max: &f16 = &max,
1238+
min: f16,
1239+
max: f16,
12411240
);
12421241

12431242
if self < min {

library/core/src/num/int_macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ macro_rules! int_impl {
13001300
}
13011301
}
13021302

1303-
/// Unbounded shift left. Computes `self << rhs`, without bounding the value of `rhs`
1303+
/// Unbounded shift left. Computes `self << rhs`, without bounding the value of `rhs`.
13041304
///
13051305
/// If `rhs` is larger or equal to the number of bits in `self`,
13061306
/// the entire value is shifted out, and `0` is returned.
@@ -1423,7 +1423,7 @@ macro_rules! int_impl {
14231423
}
14241424
}
14251425

1426-
/// Unbounded shift right. Computes `self >> rhs`, without bounding the value of `rhs`
1426+
/// Unbounded shift right. Computes `self >> rhs`, without bounding the value of `rhs`.
14271427
///
14281428
/// If `rhs` is larger or equal to the number of bits in `self`,
14291429
/// the entire value is shifted out, which yields `0` for a positive number,
@@ -2389,7 +2389,7 @@ macro_rules! int_impl {
23892389
(res, overflowed ^ (rhs < 0))
23902390
}
23912391

2392-
/// Calculates `self` - `rhs`
2392+
/// Calculates `self` - `rhs`.
23932393
///
23942394
/// Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow
23952395
/// would occur. If an overflow would have occurred then the wrapped value is returned.
@@ -2470,7 +2470,7 @@ macro_rules! int_impl {
24702470
(c, b != d)
24712471
}
24722472

2473-
/// Calculates `self` - `rhs` with an unsigned `rhs`
2473+
/// Calculates `self` - `rhs` with an unsigned `rhs`.
24742474
///
24752475
/// Returns a tuple of the subtraction along with a boolean indicating
24762476
/// whether an arithmetic overflow would occur. If an overflow would

library/core/src/num/uint_macros.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ macro_rules! uint_impl {
15171517
}
15181518
}
15191519

1520-
/// Unbounded shift left. Computes `self << rhs`, without bounding the value of `rhs`
1520+
/// Unbounded shift left. Computes `self << rhs`, without bounding the value of `rhs`.
15211521
///
15221522
/// If `rhs` is larger or equal to the number of bits in `self`,
15231523
/// the entire value is shifted out, and `0` is returned.
@@ -1640,7 +1640,7 @@ macro_rules! uint_impl {
16401640
}
16411641
}
16421642

1643-
/// Unbounded shift right. Computes `self >> rhs`, without bounding the value of `rhs`
1643+
/// Unbounded shift right. Computes `self >> rhs`, without bounding the value of `rhs`.
16441644
///
16451645
/// If `rhs` is larger or equal to the number of bits in `self`,
16461646
/// the entire value is shifted out, and `0` is returned.
@@ -2299,7 +2299,7 @@ macro_rules! uint_impl {
22992299
///
23002300
/// # Examples
23012301
///
2302-
/// Basic usage
2302+
/// Basic usage:
23032303
///
23042304
/// ```
23052305
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));")]
@@ -2389,15 +2389,15 @@ macro_rules! uint_impl {
23892389
(res, overflowed ^ (rhs < 0))
23902390
}
23912391

2392-
/// Calculates `self` - `rhs`
2392+
/// Calculates `self` - `rhs`.
23932393
///
23942394
/// Returns a tuple of the subtraction along with a boolean indicating
23952395
/// whether an arithmetic overflow would occur. If an overflow would
23962396
/// have occurred then the wrapped value is returned.
23972397
///
23982398
/// # Examples
23992399
///
2400-
/// Basic usage
2400+
/// Basic usage:
24012401
///
24022402
/// ```
24032403
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false));")]
@@ -2550,7 +2550,7 @@ macro_rules! uint_impl {
25502550
///
25512551
/// # Examples
25522552
///
2553-
/// Basic usage
2553+
/// Basic usage:
25542554
///
25552555
/// ```
25562556
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div(2), (2, false));")]
@@ -2581,7 +2581,7 @@ macro_rules! uint_impl {
25812581
///
25822582
/// # Examples
25832583
///
2584-
/// Basic usage
2584+
/// Basic usage:
25852585
///
25862586
/// ```
25872587
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));")]
@@ -2609,7 +2609,7 @@ macro_rules! uint_impl {
26092609
///
26102610
/// # Examples
26112611
///
2612-
/// Basic usage
2612+
/// Basic usage:
26132613
///
26142614
/// ```
26152615
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem(2), (1, false));")]
@@ -2640,7 +2640,7 @@ macro_rules! uint_impl {
26402640
///
26412641
/// # Examples
26422642
///
2643-
/// Basic usage
2643+
/// Basic usage:
26442644
///
26452645
/// ```
26462646
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));")]
@@ -2664,7 +2664,7 @@ macro_rules! uint_impl {
26642664
///
26652665
/// # Examples
26662666
///
2667-
/// Basic usage
2667+
/// Basic usage:
26682668
///
26692669
/// ```
26702670
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".overflowing_neg(), (0, false));")]
@@ -2689,7 +2689,7 @@ macro_rules! uint_impl {
26892689
///
26902690
/// # Examples
26912691
///
2692-
/// Basic usage
2692+
/// Basic usage:
26932693
///
26942694
/// ```
26952695
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(4), (0x10, false));")]
@@ -2715,7 +2715,7 @@ macro_rules! uint_impl {
27152715
///
27162716
/// # Examples
27172717
///
2718-
/// Basic usage
2718+
/// Basic usage:
27192719
///
27202720
/// ```
27212721
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(4), (0x1, false));")]

library/core/src/ptr/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,8 @@ pub const unsafe fn read<T>(src: *const T) -> T {
14071407
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
14081408
/// *undefined behavior* in your program.
14091409
///
1410-
/// Instead you must use the [`ptr::addr_of!`](addr_of) macro to
1411-
/// create the pointer. You may use that returned pointer together with this
1412-
/// function.
1410+
/// Instead you must use the `&raw const` syntax to create the pointer.
1411+
/// You may use that constructed pointer together with this function.
14131412
///
14141413
/// An example of what not to do and how this relates to `read_unaligned` is:
14151414
///
@@ -1427,7 +1426,7 @@ pub const unsafe fn read<T>(src: *const T) -> T {
14271426
///
14281427
/// // Take the address of a 32-bit integer which is not aligned.
14291428
/// // In contrast to `&packed.unaligned as *const _`, this has no undefined behavior.
1430-
/// let unaligned = std::ptr::addr_of!(packed.unaligned);
1429+
/// let unaligned = &raw const packed.unaligned;
14311430
///
14321431
/// let v = unsafe { std::ptr::read_unaligned(unaligned) };
14331432
/// assert_eq!(v, 0x01020304);
@@ -1615,9 +1614,8 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
16151614
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
16161615
/// *undefined behavior* in your program.
16171616
///
1618-
/// Instead, you must use the [`ptr::addr_of_mut!`](addr_of_mut)
1619-
/// macro to create the pointer. You may use that returned pointer together with
1620-
/// this function.
1617+
/// Instead, you must use the `&raw mut` syntax to create the pointer.
1618+
/// You may use that constructed pointer together with this function.
16211619
///
16221620
/// An example of how to do it and how this relates to `write_unaligned` is:
16231621
///
@@ -1632,7 +1630,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
16321630
///
16331631
/// // Take the address of a 32-bit integer which is not aligned.
16341632
/// // In contrast to `&packed.unaligned as *mut _`, this has no undefined behavior.
1635-
/// let unaligned = std::ptr::addr_of_mut!(packed.unaligned);
1633+
/// let unaligned = &raw mut packed.unaligned;
16361634
///
16371635
/// unsafe { std::ptr::write_unaligned(unaligned, 42) };
16381636
///

library/core/src/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ impl str {
24002400
///
24012401
/// # Examples
24022402
///
2403-
/// Basic usage
2403+
/// Basic usage:
24042404
///
24052405
/// ```
24062406
/// let four: u32 = "4".parse().unwrap();

library/std/src/fs/tests.rs

+28
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ fn file_test_io_seek_and_write() {
204204
}
205205

206206
#[test]
207+
#[cfg(any(
208+
windows,
209+
target_os = "freebsd",
210+
target_os = "linux",
211+
target_os = "netbsd",
212+
target_vendor = "apple",
213+
))]
207214
fn file_lock_multiple_shared() {
208215
let tmpdir = tmpdir();
209216
let filename = &tmpdir.join("file_lock_multiple_shared_test.txt");
@@ -220,6 +227,13 @@ fn file_lock_multiple_shared() {
220227
}
221228

222229
#[test]
230+
#[cfg(any(
231+
windows,
232+
target_os = "freebsd",
233+
target_os = "linux",
234+
target_os = "netbsd",
235+
target_vendor = "apple",
236+
))]
223237
fn file_lock_blocking() {
224238
let tmpdir = tmpdir();
225239
let filename = &tmpdir.join("file_lock_blocking_test.txt");
@@ -237,6 +251,13 @@ fn file_lock_blocking() {
237251
}
238252

239253
#[test]
254+
#[cfg(any(
255+
windows,
256+
target_os = "freebsd",
257+
target_os = "linux",
258+
target_os = "netbsd",
259+
target_vendor = "apple",
260+
))]
240261
fn file_lock_drop() {
241262
let tmpdir = tmpdir();
242263
let filename = &tmpdir.join("file_lock_dup_test.txt");
@@ -251,6 +272,13 @@ fn file_lock_drop() {
251272
}
252273

253274
#[test]
275+
#[cfg(any(
276+
windows,
277+
target_os = "freebsd",
278+
target_os = "linux",
279+
target_os = "netbsd",
280+
target_vendor = "apple",
281+
))]
254282
fn file_lock_dup() {
255283
let tmpdir = tmpdir();
256284
let filename = &tmpdir.join("file_lock_dup_test.txt");

library/std/src/io/mod.rs

+45
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,25 @@ impl<'a> IoSliceMut<'a> {
13401340
bufs[0].advance(left);
13411341
}
13421342
}
1343+
1344+
/// Get the underlying bytes as a mutable slice with the original lifetime.
1345+
///
1346+
/// # Examples
1347+
///
1348+
/// ```
1349+
/// #![feature(io_slice_as_bytes)]
1350+
/// use std::io::IoSliceMut;
1351+
///
1352+
/// let mut data = *b"abcdef";
1353+
/// let io_slice = IoSliceMut::new(&mut data);
1354+
/// io_slice.into_slice()[0] = b'A';
1355+
///
1356+
/// assert_eq!(&data, b"Abcdef");
1357+
/// ```
1358+
#[unstable(feature = "io_slice_as_bytes", issue = "132818")]
1359+
pub const fn into_slice(self) -> &'a mut [u8] {
1360+
self.0.into_slice()
1361+
}
13431362
}
13441363

13451364
#[stable(feature = "iovec", since = "1.36.0")]
@@ -1482,6 +1501,32 @@ impl<'a> IoSlice<'a> {
14821501
bufs[0].advance(left);
14831502
}
14841503
}
1504+
1505+
/// Get the underlying bytes as a slice with the original lifetime.
1506+
///
1507+
/// This doesn't borrow from `self`, so is less restrictive than calling
1508+
/// `.deref()`, which does.
1509+
///
1510+
/// # Examples
1511+
///
1512+
/// ```
1513+
/// #![feature(io_slice_as_bytes)]
1514+
/// use std::io::IoSlice;
1515+
///
1516+
/// let data = b"abcdef";
1517+
///
1518+
/// let mut io_slice = IoSlice::new(data);
1519+
/// let tail = &io_slice.as_slice()[3..];
1520+
///
1521+
/// // This works because `tail` doesn't borrow `io_slice`
1522+
/// io_slice = IoSlice::new(tail);
1523+
///
1524+
/// assert_eq!(io_slice.as_slice(), b"def");
1525+
/// ```
1526+
#[unstable(feature = "io_slice_as_bytes", issue = "132818")]
1527+
pub const fn as_slice(self) -> &'a [u8] {
1528+
self.0.as_slice()
1529+
}
14851530
}
14861531

14871532
#[stable(feature = "iovec", since = "1.36.0")]

library/std/src/io/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,20 @@ fn io_slice_advance_slices_beyond_total_length() {
531531
assert!(bufs.is_empty());
532532
}
533533

534+
#[test]
535+
fn io_slice_as_slice() {
536+
let buf = [1; 8];
537+
let slice = IoSlice::new(&buf).as_slice();
538+
assert_eq!(slice, buf);
539+
}
540+
541+
#[test]
542+
fn io_slice_into_slice() {
543+
let mut buf = [1; 8];
544+
let slice = IoSliceMut::new(&mut buf).into_slice();
545+
assert_eq!(slice, [1; 8]);
546+
}
547+
534548
/// Creates a new writer that reads from at most `n_bufs` and reads
535549
/// `per_call` bytes (in total) per call to write.
536550
fn test_writer(n_bufs: usize, per_call: usize) -> TestWriter {

library/std/src/sys/pal/hermit/io.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'a> IoSlice<'a> {
3333
}
3434

3535
#[inline]
36-
pub fn as_slice(&self) -> &[u8] {
36+
pub const fn as_slice(&self) -> &'a [u8] {
3737
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
3838
}
3939
}
@@ -70,6 +70,11 @@ impl<'a> IoSliceMut<'a> {
7070
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
7171
}
7272

73+
#[inline]
74+
pub const fn into_slice(self) -> &'a mut [u8] {
75+
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
76+
}
77+
7378
#[inline]
7479
pub fn as_mut_slice(&mut self) -> &mut [u8] {
7580
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }

0 commit comments

Comments
 (0)