Skip to content

Commit 808ed55

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '2a9bacf61876' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 2a9bacf Filtered ref: d7fc6d06166167894862d54c9618a3cd7599fa9c Upstream diff: rust-lang/rust@f4665ab...2a9bacf This merge was created using https://github.com/rust-lang/josh-sync.
2 parents a5da025 + b97dbbc commit 808ed55

File tree

48 files changed

+1156
-1345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1156
-1345
lines changed

core/src/ptr/const_ptr.rs

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,7 @@ impl<T: PointeeSized> *const T {
146146
self as _
147147
}
148148

149-
/// Gets the "address" portion of the pointer.
150-
///
151-
/// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
152-
/// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
153-
/// casting the returned address back to a pointer yields a [pointer without
154-
/// provenance][without_provenance], which is undefined behavior to dereference. To properly
155-
/// restore the lost information and obtain a dereferenceable pointer, use
156-
/// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
157-
///
158-
/// If using those APIs is not possible because there is no way to preserve a pointer with the
159-
/// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
160-
/// or [`expose_provenance`][pointer::expose_provenance] and [`with_exposed_provenance`][with_exposed_provenance]
161-
/// instead. However, note that this makes your code less portable and less amenable to tools
162-
/// that check for compliance with the Rust memory model.
163-
///
164-
/// On most platforms this will produce a value with the same bytes as the original
165-
/// pointer, because all the bytes are dedicated to describing the address.
166-
/// Platforms which need to store additional information in the pointer may
167-
/// perform a change of representation to produce a value containing only the address
168-
/// portion of the pointer. What that means is up to the platform to define.
169-
///
170-
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
149+
#[doc = include_str!("./docs/addr.md")]
171150
#[must_use]
172151
#[inline(always)]
173152
#[stable(feature = "strict_provenance", since = "1.84.0")]
@@ -254,23 +233,16 @@ impl<T: PointeeSized> *const T {
254233
(self.cast(), metadata(self))
255234
}
256235

257-
/// Returns `None` if the pointer is null, or else returns a shared reference to
258-
/// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
259-
/// must be used instead.
260-
///
261-
/// [`as_uninit_ref`]: #method.as_uninit_ref
262-
///
263-
/// # Safety
264-
///
265-
/// When calling this method, you have to ensure that *either* the pointer is null *or*
266-
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
236+
#[doc = include_str!("./docs/as_ref.md")]
267237
///
268-
/// # Panics during const evaluation
269-
///
270-
/// This method will panic during const evaluation if the pointer cannot be
271-
/// determined to be null or not. See [`is_null`] for more information.
238+
/// ```
239+
/// let ptr: *const u8 = &10u8 as *const u8;
272240
///
273-
/// [`is_null`]: #method.is_null
241+
/// unsafe {
242+
/// let val_back = &*ptr;
243+
/// assert_eq!(val_back, &10);
244+
/// }
245+
/// ```
274246
///
275247
/// # Examples
276248
///
@@ -284,20 +256,9 @@ impl<T: PointeeSized> *const T {
284256
/// }
285257
/// ```
286258
///
287-
/// # Null-unchecked version
288259
///
289-
/// If you are sure the pointer can never be null and are looking for some kind of
290-
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>`, know that you can
291-
/// dereference the pointer directly.
292-
///
293-
/// ```
294-
/// let ptr: *const u8 = &10u8 as *const u8;
295-
///
296-
/// unsafe {
297-
/// let val_back = &*ptr;
298-
/// assert_eq!(val_back, &10);
299-
/// }
300-
/// ```
260+
/// [`is_null`]: #method.is_null
261+
/// [`as_uninit_ref`]: #method.as_uninit_ref
301262
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
302263
#[rustc_const_stable(feature = "const_ptr_is_null", since = "1.84.0")]
303264
#[inline]
@@ -338,23 +299,10 @@ impl<T: PointeeSized> *const T {
338299
unsafe { &*self }
339300
}
340301

341-
/// Returns `None` if the pointer is null, or else returns a shared reference to
342-
/// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
343-
/// that the value has to be initialized.
344-
///
345-
/// [`as_ref`]: #method.as_ref
346-
///
347-
/// # Safety
348-
///
349-
/// When calling this method, you have to ensure that *either* the pointer is null *or*
350-
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
351-
///
352-
/// # Panics during const evaluation
353-
///
354-
/// This method will panic during const evaluation if the pointer cannot be
355-
/// determined to be null or not. See [`is_null`] for more information.
302+
#[doc = include_str!("./docs/as_uninit_ref.md")]
356303
///
357304
/// [`is_null`]: #method.is_null
305+
/// [`as_ref`]: #method.as_ref
358306
///
359307
/// # Examples
360308
///

core/src/ptr/docs/INFO.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This directory holds method documentation that otherwise
2+
would be duplicated across mutable and immutable pointers.
3+
4+
Note that most of the docs here are not the complete docs
5+
for their corresponding method. This is for a few reasons:
6+
7+
1. Examples need to be different for mutable/immutable
8+
pointers, in order to actually call the correct method.
9+
2. Link reference definitions are frequently different
10+
between mutable/immutable pointers, in order to link to
11+
the correct method.
12+
For example, `<*const T>::as_ref` links to
13+
`<*const T>::is_null`, while `<*mut T>::as_ref` links to
14+
`<*mut T>::is_null`.
15+
3. Many methods on mutable pointers link to an alternate
16+
version that returns a mutable reference instead of
17+
a shared reference.
18+
19+
Always review the rendered docs manually when making
20+
changes to these files to make sure you're not accidentally
21+
splitting up a section.

core/src/ptr/docs/addr.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Gets the "address" portion of the pointer.
2+
3+
This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
4+
the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
5+
casting the returned address back to a pointer yields a [pointer without
6+
provenance][without_provenance], which is undefined behavior to dereference. To properly
7+
restore the lost information and obtain a dereferenceable pointer, use
8+
[`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
9+
10+
If using those APIs is not possible because there is no way to preserve a pointer with the
11+
required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
12+
or [`expose_provenance`][pointer::expose_provenance] and [`with_exposed_provenance`][with_exposed_provenance]
13+
instead. However, note that this makes your code less portable and less amenable to tools
14+
that check for compliance with the Rust memory model.
15+
16+
On most platforms this will produce a value with the same bytes as the original
17+
pointer, because all the bytes are dedicated to describing the address.
18+
Platforms which need to store additional information in the pointer may
19+
perform a change of representation to produce a value containing only the address
20+
portion of the pointer. What that means is up to the platform to define.
21+
22+
This is a [Strict Provenance][crate::ptr#strict-provenance] API.

core/src/ptr/docs/as_ref.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Returns `None` if the pointer is null, or else returns a shared reference to
2+
the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
3+
must be used instead.
4+
5+
# Safety
6+
7+
When calling this method, you have to ensure that *either* the pointer is null *or*
8+
the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
9+
10+
# Panics during const evaluation
11+
12+
This method will panic during const evaluation if the pointer cannot be
13+
determined to be null or not. See [`is_null`] for more information.
14+
15+
# Null-unchecked version
16+
17+
If you are sure the pointer can never be null and are looking for some kind of
18+
`as_ref_unchecked` that returns the `&T` instead of `Option<&T>`, know that you can
19+
dereference the pointer directly.

core/src/ptr/docs/as_uninit_ref.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Returns `None` if the pointer is null, or else returns a shared reference to
2+
the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
3+
that the value has to be initialized.
4+
5+
# Safety
6+
7+
When calling this method, you have to ensure that *either* the pointer is null *or*
8+
the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
9+
Note that because the created reference is to `MaybeUninit<T>`, the
10+
source pointer can point to uninitialized memory.
11+
12+
# Panics during const evaluation
13+
14+
This method will panic during const evaluation if the pointer cannot be
15+
determined to be null or not. See [`is_null`] for more information.

core/src/ptr/mut_ptr.rs

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,9 @@ impl<T: PointeeSized> *mut T {
135135
self as _
136136
}
137137

138-
/// Gets the "address" portion of the pointer.
139-
///
140-
/// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
141-
/// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
142-
/// casting the returned address back to a pointer yields a [pointer without
143-
/// provenance][without_provenance_mut], which is undefined behavior to dereference. To properly
144-
/// restore the lost information and obtain a dereferenceable pointer, use
145-
/// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
146-
///
147-
/// If using those APIs is not possible because there is no way to preserve a pointer with the
148-
/// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
149-
/// or [`expose_provenance`][pointer::expose_provenance] and [`with_exposed_provenance`][with_exposed_provenance]
150-
/// instead. However, note that this makes your code less portable and less amenable to tools
151-
/// that check for compliance with the Rust memory model.
152-
///
153-
/// On most platforms this will produce a value with the same bytes as the original
154-
/// pointer, because all the bytes are dedicated to describing the address.
155-
/// Platforms which need to store additional information in the pointer may
156-
/// perform a change of representation to produce a value containing only the address
157-
/// portion of the pointer. What that means is up to the platform to define.
138+
#[doc = include_str!("./docs/addr.md")]
158139
///
159-
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
140+
/// [without_provenance]: without_provenance_mut
160141
#[must_use]
161142
#[inline(always)]
162143
#[stable(feature = "strict_provenance", since = "1.84.0")]
@@ -243,26 +224,16 @@ impl<T: PointeeSized> *mut T {
243224
(self.cast(), super::metadata(self))
244225
}
245226

246-
/// Returns `None` if the pointer is null, or else returns a shared reference to
247-
/// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
248-
/// must be used instead.
249-
///
250-
/// For the mutable counterpart see [`as_mut`].
227+
#[doc = include_str!("./docs/as_ref.md")]
251228
///
252-
/// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
253-
/// [`as_mut`]: #method.as_mut
254-
///
255-
/// # Safety
256-
///
257-
/// When calling this method, you have to ensure that *either* the pointer is null *or*
258-
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
259-
///
260-
/// # Panics during const evaluation
261-
///
262-
/// This method will panic during const evaluation if the pointer cannot be
263-
/// determined to be null or not. See [`is_null`] for more information.
229+
/// ```
230+
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
264231
///
265-
/// [`is_null`]: #method.is_null-1
232+
/// unsafe {
233+
/// let val_back = &*ptr;
234+
/// println!("We got back the value: {val_back}!");
235+
/// }
236+
/// ```
266237
///
267238
/// # Examples
268239
///
@@ -276,20 +247,14 @@ impl<T: PointeeSized> *mut T {
276247
/// }
277248
/// ```
278249
///
279-
/// # Null-unchecked version
280-
///
281-
/// If you are sure the pointer can never be null and are looking for some kind of
282-
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>`, know that you can
283-
/// dereference the pointer directly.
250+
/// # See Also
284251
///
285-
/// ```
286-
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
252+
/// For the mutable counterpart see [`as_mut`].
287253
///
288-
/// unsafe {
289-
/// let val_back = &*ptr;
290-
/// println!("We got back the value: {val_back}!");
291-
/// }
292-
/// ```
254+
/// [`is_null`]: #method.is_null-1
255+
/// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
256+
/// [`as_mut`]: #method.as_mut
257+
293258
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
294259
#[rustc_const_stable(feature = "const_ptr_is_null", since = "1.84.0")]
295260
#[inline]
@@ -332,28 +297,15 @@ impl<T: PointeeSized> *mut T {
332297
unsafe { &*self }
333298
}
334299

335-
/// Returns `None` if the pointer is null, or else returns a shared reference to
336-
/// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
337-
/// that the value has to be initialized.
338-
///
339-
/// For the mutable counterpart see [`as_uninit_mut`].
300+
#[doc = include_str!("./docs/as_uninit_ref.md")]
340301
///
302+
/// [`is_null`]: #method.is_null-1
341303
/// [`as_ref`]: pointer#method.as_ref-1
342-
/// [`as_uninit_mut`]: #method.as_uninit_mut
343-
///
344-
/// # Safety
345-
///
346-
/// When calling this method, you have to ensure that *either* the pointer is null *or*
347-
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
348-
/// Note that because the created reference is to `MaybeUninit<T>`, the
349-
/// source pointer can point to uninitialized memory.
350-
///
351-
/// # Panics during const evaluation
352304
///
353-
/// This method will panic during const evaluation if the pointer cannot be
354-
/// determined to be null or not. See [`is_null`] for more information.
305+
/// # See Also
306+
/// For the mutable counterpart see [`as_uninit_mut`].
355307
///
356-
/// [`is_null`]: #method.is_null-1
308+
/// [`as_uninit_mut`]: #method.as_uninit_mut
357309
///
358310
/// # Examples
359311
///

coretests/tests/array.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,10 @@ fn array_map_drops_unmapped_elements_on_panic() {
717717
assert_eq!(counter.load(Ordering::SeqCst), MAX);
718718
}
719719
}
720+
721+
// This covers the `PartialEq::<[T]>::eq` impl for `[T; N]` when it returns false.
722+
#[test]
723+
fn array_eq() {
724+
let not_true = [0u8] == [].as_slice();
725+
assert!(!not_true);
726+
}

coretests/tests/floats/f128.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ const TOL: f128 = 1e-12;
1717
#[allow(unused)]
1818
const TOL_PRECISE: f128 = 1e-28;
1919

20-
/// First pattern over the mantissa
21-
const NAN_MASK1: u128 = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
22-
23-
/// Second pattern over the mantissa
24-
const NAN_MASK2: u128 = 0x00005555555555555555555555555555;
25-
2620
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
2721
// the intrinsics.
2822

@@ -54,28 +48,6 @@ fn test_max_recip() {
5448
);
5549
}
5650

57-
#[test]
58-
fn test_float_bits_conv() {
59-
assert_eq!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
60-
assert_eq!((12.5f128).to_bits(), 0x40029000000000000000000000000000);
61-
assert_eq!((1337f128).to_bits(), 0x40094e40000000000000000000000000);
62-
assert_eq!((-14.25f128).to_bits(), 0xc002c800000000000000000000000000);
63-
assert_biteq!(f128::from_bits(0x3fff0000000000000000000000000000), 1.0);
64-
assert_biteq!(f128::from_bits(0x40029000000000000000000000000000), 12.5);
65-
assert_biteq!(f128::from_bits(0x40094e40000000000000000000000000), 1337.0);
66-
assert_biteq!(f128::from_bits(0xc002c800000000000000000000000000), -14.25);
67-
68-
// Check that NaNs roundtrip their bits regardless of signaling-ness
69-
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
70-
let masked_nan1 = f128::NAN.to_bits() ^ NAN_MASK1;
71-
let masked_nan2 = f128::NAN.to_bits() ^ NAN_MASK2;
72-
assert!(f128::from_bits(masked_nan1).is_nan());
73-
assert!(f128::from_bits(masked_nan2).is_nan());
74-
75-
assert_eq!(f128::from_bits(masked_nan1).to_bits(), masked_nan1);
76-
assert_eq!(f128::from_bits(masked_nan2).to_bits(), masked_nan2);
77-
}
78-
7951
#[test]
8052
fn test_from() {
8153
assert_biteq!(f128::from(false), 0.0);

0 commit comments

Comments
 (0)