Skip to content

Commit b74c1e7

Browse files
committed
Auto merge of #148120 - Zalathar:rollup-xzrn9a0, r=Zalathar
Rollup of 3 pull requests Successful merges: - #144090 (Make `IoSlice` and `IoSliceMut` methods unstably const) - #145665 (Don't require `T: RefUnwindSafe` for `vec::IntoIter<T>: UnwindSafe`) - #147818 (Unify and deduplicate max recip float tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cc63a0a + 420214a commit b74c1e7

File tree

9 files changed

+47
-47
lines changed

9 files changed

+47
-47
lines changed

library/alloc/src/vec/into_iter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use core::mem::{ManuallyDrop, MaybeUninit, SizedTypeProperties};
77
use core::num::NonZero;
88
#[cfg(not(no_global_oom_handling))]
99
use core::ops::Deref;
10+
use core::panic::UnwindSafe;
1011
use core::ptr::{self, NonNull};
1112
use core::slice::{self};
1213
use core::{array, fmt};
@@ -60,6 +61,11 @@ pub struct IntoIter<
6061
pub(super) end: *const T,
6162
}
6263

64+
// Manually mirroring what `Vec` has,
65+
// because otherwise we get `T: RefUnwindSafe` from `NonNull`.
66+
#[stable(feature = "catch_unwind", since = "1.9.0")]
67+
impl<T: UnwindSafe, A: Allocator + UnwindSafe> UnwindSafe for IntoIter<T, A> {}
68+
6369
#[stable(feature = "vec_intoiter_debug", since = "1.13.0")]
6470
impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A> {
6571
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f128)]
33

4-
#[cfg(any(miri, target_has_reliable_f128_math))]
5-
use super::assert_approx_eq;
64
use super::assert_biteq;
75

86
// Note these tolerances make sense around zero, but not for more extreme exponents.
@@ -20,16 +18,6 @@ const TOL_PRECISE: f128 = 1e-28;
2018
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
2119
// the intrinsics.
2220

23-
#[test]
24-
#[cfg(any(miri, target_has_reliable_f128_math))]
25-
fn test_max_recip() {
26-
assert_approx_eq!(
27-
f128::MAX.recip(),
28-
8.40525785778023376565669454330438228902076605e-4933,
29-
1e-4900
30-
);
31-
}
32-
3321
#[test]
3422
fn test_from() {
3523
assert_biteq!(f128::from(false), 0.0);

library/coretests/tests/floats/f16.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f16)]
33

4-
use super::{assert_approx_eq, assert_biteq};
4+
use super::assert_biteq;
55

66
/// Tolerance for results on the order of 10.0e-2
77
#[allow(unused)]
@@ -22,12 +22,6 @@ const TOL_P4: f16 = 10.0;
2222
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
2323
// the intrinsics.
2424

25-
#[test]
26-
#[cfg(any(miri, target_has_reliable_f16_math))]
27-
fn test_max_recip() {
28-
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
29-
}
30-
3125
#[test]
3226
fn test_from() {
3327
assert_biteq!(f16::from(false), 0.0);

library/coretests/tests/floats/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ trait TestableFloat: Sized {
3838
const MUL_ADD_RESULT: Self;
3939
/// The result of (-12.3).mul_add(-4.5, -6.7)
4040
const NEG_MUL_ADD_RESULT: Self;
41+
/// Reciprocal of the maximum val
42+
const MAX_RECIP: Self;
4143
}
4244

4345
impl TestableFloat for f16 {
@@ -64,6 +66,7 @@ impl TestableFloat for f16 {
6466
const RAW_MINUS_14_DOT_25: Self = Self::from_bits(0xcb20);
6567
const MUL_ADD_RESULT: Self = 62.031;
6668
const NEG_MUL_ADD_RESULT: Self = 48.625;
69+
const MAX_RECIP: Self = 1.526624e-5;
6770
}
6871

6972
impl TestableFloat for f32 {
@@ -92,6 +95,7 @@ impl TestableFloat for f32 {
9295
const RAW_MINUS_14_DOT_25: Self = Self::from_bits(0xc1640000);
9396
const MUL_ADD_RESULT: Self = 62.05;
9497
const NEG_MUL_ADD_RESULT: Self = 48.65;
98+
const MAX_RECIP: Self = 2.938736e-39;
9599
}
96100

97101
impl TestableFloat for f64 {
@@ -116,6 +120,7 @@ impl TestableFloat for f64 {
116120
const RAW_MINUS_14_DOT_25: Self = Self::from_bits(0xc02c800000000000);
117121
const MUL_ADD_RESULT: Self = 62.050000000000004;
118122
const NEG_MUL_ADD_RESULT: Self = 48.650000000000006;
123+
const MAX_RECIP: Self = 5.562684646268003e-309;
119124
}
120125

121126
impl TestableFloat for f128 {
@@ -140,6 +145,7 @@ impl TestableFloat for f128 {
140145
const RAW_MINUS_14_DOT_25: Self = Self::from_bits(0xc002c800000000000000000000000000);
141146
const MUL_ADD_RESULT: Self = 62.0500000000000000000000000000000037;
142147
const NEG_MUL_ADD_RESULT: Self = 48.6500000000000000000000000000000049;
148+
const MAX_RECIP: Self = 8.40525785778023376565669454330438228902076605e-4933;
143149
}
144150

145151
/// Determine the tolerance for values of the argument type.
@@ -1425,13 +1431,15 @@ float_test! {
14251431
let nan: Float = Float::NAN;
14261432
let inf: Float = Float::INFINITY;
14271433
let neg_inf: Float = Float::NEG_INFINITY;
1434+
let max: Float = Float::MAX;
14281435
assert_biteq!((1.0 as Float).recip(), 1.0);
14291436
assert_biteq!((2.0 as Float).recip(), 0.5);
14301437
assert_biteq!((-0.4 as Float).recip(), -2.5);
14311438
assert_biteq!((0.0 as Float).recip(), inf);
14321439
assert!(nan.recip().is_nan());
14331440
assert_biteq!(inf.recip(), 0.0);
14341441
assert_biteq!(neg_inf.recip(), -0.0);
1442+
assert_biteq!(max.recip(), Float::MAX_RECIP);
14351443
}
14361444
}
14371445

library/std/src/io/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,9 @@ impl<'a> IoSliceMut<'a> {
13381338
///
13391339
/// Panics on Windows if the slice is larger than 4GB.
13401340
#[stable(feature = "iovec", since = "1.36.0")]
1341+
#[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
13411342
#[inline]
1342-
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
1343+
pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
13431344
IoSliceMut(sys::io::IoSliceMut::new(buf))
13441345
}
13451346

@@ -1366,8 +1367,9 @@ impl<'a> IoSliceMut<'a> {
13661367
/// assert_eq!(buf.deref(), [1; 5].as_ref());
13671368
/// ```
13681369
#[stable(feature = "io_slice_advance", since = "1.81.0")]
1370+
#[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
13691371
#[inline]
1370-
pub fn advance(&mut self, n: usize) {
1372+
pub const fn advance(&mut self, n: usize) {
13711373
self.0.advance(n)
13721374
}
13731375

@@ -1496,9 +1498,10 @@ impl<'a> IoSlice<'a> {
14961498
///
14971499
/// Panics on Windows if the slice is larger than 4GB.
14981500
#[stable(feature = "iovec", since = "1.36.0")]
1501+
#[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
14991502
#[must_use]
15001503
#[inline]
1501-
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
1504+
pub const fn new(buf: &'a [u8]) -> IoSlice<'a> {
15021505
IoSlice(sys::io::IoSlice::new(buf))
15031506
}
15041507

@@ -1525,8 +1528,9 @@ impl<'a> IoSlice<'a> {
15251528
/// assert_eq!(buf.deref(), [1; 5].as_ref());
15261529
/// ```
15271530
#[stable(feature = "io_slice_advance", since = "1.81.0")]
1531+
#[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
15281532
#[inline]
1529-
pub fn advance(&mut self, n: usize) {
1533+
pub const fn advance(&mut self, n: usize) {
15301534
self.0.advance(n)
15311535
}
15321536

library/std/src/sys/io/io_slice/iovec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ pub struct IoSlice<'a> {
1818

1919
impl<'a> IoSlice<'a> {
2020
#[inline]
21-
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
21+
pub const fn new(buf: &'a [u8]) -> IoSlice<'a> {
2222
IoSlice {
2323
vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() },
2424
_p: PhantomData,
2525
}
2626
}
2727

2828
#[inline]
29-
pub fn advance(&mut self, n: usize) {
29+
pub const fn advance(&mut self, n: usize) {
3030
if self.vec.iov_len < n {
3131
panic!("advancing IoSlice beyond its length");
3232
}
@@ -51,15 +51,15 @@ pub struct IoSliceMut<'a> {
5151

5252
impl<'a> IoSliceMut<'a> {
5353
#[inline]
54-
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
54+
pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
5555
IoSliceMut {
5656
vec: iovec { iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() },
5757
_p: PhantomData,
5858
}
5959
}
6060

6161
#[inline]
62-
pub fn advance(&mut self, n: usize) {
62+
pub const fn advance(&mut self, n: usize) {
6363
if self.vec.iov_len < n {
6464
panic!("advancing IoSliceMut beyond its length");
6565
}
@@ -71,7 +71,7 @@ impl<'a> IoSliceMut<'a> {
7171
}
7272

7373
#[inline]
74-
pub fn as_slice(&self) -> &[u8] {
74+
pub const fn as_slice(&self) -> &[u8] {
7575
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
7676
}
7777

@@ -81,7 +81,7 @@ impl<'a> IoSliceMut<'a> {
8181
}
8282

8383
#[inline]
84-
pub fn as_mut_slice(&mut self) -> &mut [u8] {
84+
pub const fn as_mut_slice(&mut self) -> &mut [u8] {
8585
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
8686
}
8787
}

library/std/src/sys/io/io_slice/unsupported.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ pub struct IoSlice<'a>(&'a [u8]);
55

66
impl<'a> IoSlice<'a> {
77
#[inline]
8-
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
8+
pub const fn new(buf: &'a [u8]) -> IoSlice<'a> {
99
IoSlice(buf)
1010
}
1111

1212
#[inline]
13-
pub fn advance(&mut self, n: usize) {
13+
pub const fn advance(&mut self, n: usize) {
1414
self.0 = &self.0[n..]
1515
}
1616

@@ -24,19 +24,19 @@ pub struct IoSliceMut<'a>(&'a mut [u8]);
2424

2525
impl<'a> IoSliceMut<'a> {
2626
#[inline]
27-
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
27+
pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
2828
IoSliceMut(buf)
2929
}
3030

3131
#[inline]
32-
pub fn advance(&mut self, n: usize) {
32+
pub const fn advance(&mut self, n: usize) {
3333
let slice = mem::take(&mut self.0);
3434
let (_, remaining) = slice.split_at_mut(n);
3535
self.0 = remaining;
3636
}
3737

3838
#[inline]
39-
pub fn as_slice(&self) -> &[u8] {
39+
pub const fn as_slice(&self) -> &[u8] {
4040
self.0
4141
}
4242

@@ -46,7 +46,7 @@ impl<'a> IoSliceMut<'a> {
4646
}
4747

4848
#[inline]
49-
pub fn as_mut_slice(&mut self) -> &mut [u8] {
49+
pub const fn as_mut_slice(&mut self) -> &mut [u8] {
5050
self.0
5151
}
5252
}

library/std/src/sys/io/io_slice/wasi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pub struct IoSlice<'a> {
1010

1111
impl<'a> IoSlice<'a> {
1212
#[inline]
13-
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
13+
pub const fn new(buf: &'a [u8]) -> IoSlice<'a> {
1414
IoSlice { vec: wasi::Ciovec { buf: buf.as_ptr(), buf_len: buf.len() }, _p: PhantomData }
1515
}
1616

1717
#[inline]
18-
pub fn advance(&mut self, n: usize) {
18+
pub const fn advance(&mut self, n: usize) {
1919
if self.vec.buf_len < n {
2020
panic!("advancing IoSlice beyond its length");
2121
}
@@ -40,15 +40,15 @@ pub struct IoSliceMut<'a> {
4040

4141
impl<'a> IoSliceMut<'a> {
4242
#[inline]
43-
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
43+
pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
4444
IoSliceMut {
4545
vec: wasi::Iovec { buf: buf.as_mut_ptr(), buf_len: buf.len() },
4646
_p: PhantomData,
4747
}
4848
}
4949

5050
#[inline]
51-
pub fn advance(&mut self, n: usize) {
51+
pub const fn advance(&mut self, n: usize) {
5252
if self.vec.buf_len < n {
5353
panic!("advancing IoSlice beyond its length");
5454
}
@@ -60,7 +60,7 @@ impl<'a> IoSliceMut<'a> {
6060
}
6161

6262
#[inline]
63-
pub fn as_slice(&self) -> &[u8] {
63+
pub const fn as_slice(&self) -> &[u8] {
6464
unsafe { slice::from_raw_parts(self.vec.buf as *const u8, self.vec.buf_len) }
6565
}
6666

@@ -70,7 +70,7 @@ impl<'a> IoSliceMut<'a> {
7070
}
7171

7272
#[inline]
73-
pub fn as_mut_slice(&mut self) -> &mut [u8] {
73+
pub const fn as_mut_slice(&mut self) -> &mut [u8] {
7474
unsafe { slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.buf_len) }
7575
}
7676
}

library/std/src/sys/io/io_slice/windows.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct IoSlice<'a> {
1111

1212
impl<'a> IoSlice<'a> {
1313
#[inline]
14-
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
14+
pub const fn new(buf: &'a [u8]) -> IoSlice<'a> {
1515
assert!(buf.len() <= u32::MAX as usize);
1616
IoSlice {
1717
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_ptr() as *mut u8 },
@@ -20,7 +20,7 @@ impl<'a> IoSlice<'a> {
2020
}
2121

2222
#[inline]
23-
pub fn advance(&mut self, n: usize) {
23+
pub const fn advance(&mut self, n: usize) {
2424
if (self.vec.len as usize) < n {
2525
panic!("advancing IoSlice beyond its length");
2626
}
@@ -45,7 +45,7 @@ pub struct IoSliceMut<'a> {
4545

4646
impl<'a> IoSliceMut<'a> {
4747
#[inline]
48-
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
48+
pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
4949
assert!(buf.len() <= u32::MAX as usize);
5050
IoSliceMut {
5151
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_mut_ptr() },
@@ -54,7 +54,7 @@ impl<'a> IoSliceMut<'a> {
5454
}
5555

5656
#[inline]
57-
pub fn advance(&mut self, n: usize) {
57+
pub const fn advance(&mut self, n: usize) {
5858
if (self.vec.len as usize) < n {
5959
panic!("advancing IoSliceMut beyond its length");
6060
}
@@ -66,7 +66,7 @@ impl<'a> IoSliceMut<'a> {
6666
}
6767

6868
#[inline]
69-
pub fn as_slice(&self) -> &[u8] {
69+
pub const fn as_slice(&self) -> &[u8] {
7070
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) }
7171
}
7272

@@ -76,7 +76,7 @@ impl<'a> IoSliceMut<'a> {
7676
}
7777

7878
#[inline]
79-
pub fn as_mut_slice(&mut self) -> &mut [u8] {
79+
pub const fn as_mut_slice(&mut self) -> &mut [u8] {
8080
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) }
8181
}
8282
}

0 commit comments

Comments
 (0)