Skip to content

Commit c9e4bb2

Browse files
committed
Auto merge of rust-lang#83674 - Dylan-DPC:rollup-bcuc1hl, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#83568 (update comment at MaybeUninit::uninit_array) - rust-lang#83571 (Constantify some slice methods) - rust-lang#83579 (Improve pointer arithmetic docs) - rust-lang#83645 (Wrap non-pre code blocks) - rust-lang#83656 (Add a regression test for issue-82865) - rust-lang#83662 (Update books) - rust-lang#83667 (Suggest box/pin/arc ing receiver on method calls) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f704e79 + 8f2b9b1 commit c9e4bb2

File tree

5 files changed

+66
-66
lines changed

5 files changed

+66
-66
lines changed

core/src/mem/maybe_uninit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ impl<T> MaybeUninit<T> {
319319
/// Create a new array of `MaybeUninit<T>` items, in an uninitialized state.
320320
///
321321
/// Note: in a future Rust version this method may become unnecessary
322-
/// when array literal syntax allows
323-
/// [repeating const expressions](https://github.com/rust-lang/rust/issues/49147).
324-
/// The example below could then use `let mut buf = [MaybeUninit::<u8>::uninit(); 32];`.
322+
/// when Rust allows
323+
/// [inline const expressions](https://github.com/rust-lang/rust/issues/76001).
324+
/// The example below could then use `let mut buf = [const { MaybeUninit::<u8>::uninit() }; 32];`.
325325
///
326326
/// # Examples
327327
///

core/src/ptr/const_ptr.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ impl<T: ?Sized> *const T {
184184
/// Behavior:
185185
///
186186
/// * Both the starting and resulting pointer must be either in bounds or one
187-
/// byte past the end of the same allocated object. Note that in Rust,
188-
/// every (stack-allocated) variable is considered a separate allocated object.
187+
/// byte past the end of the same [allocated object].
189188
///
190189
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
191190
///
@@ -210,6 +209,7 @@ impl<T: ?Sized> *const T {
210209
/// enables more aggressive compiler optimizations.
211210
///
212211
/// [`wrapping_offset`]: #method.wrapping_offset
212+
/// [allocated object]: crate::ptr#allocated-object
213213
///
214214
/// # Examples
215215
///
@@ -245,9 +245,8 @@ impl<T: ?Sized> *const T {
245245
///
246246
/// This operation itself is always safe, but using the resulting pointer is not.
247247
///
248-
/// The resulting pointer remains attached to the same allocated object that `self` points to.
249-
/// It may *not* be used to access a different allocated object. Note that in Rust, every
250-
/// (stack-allocated) variable is considered a separate allocated object.
248+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
249+
/// be used to read or write other allocated objects.
251250
///
252251
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
253252
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -265,10 +264,8 @@ impl<T: ?Sized> *const T {
265264
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
266265
/// words, leaving the allocated object and then re-entering it later is permitted.
267266
///
268-
/// If you need to cross object boundaries, cast the pointer to an integer and
269-
/// do the arithmetic there.
270-
///
271267
/// [`offset`]: #method.offset
268+
/// [allocated object]: crate::ptr#allocated-object
272269
///
273270
/// # Examples
274271
///
@@ -314,8 +311,7 @@ impl<T: ?Sized> *const T {
314311
/// Behavior:
315312
///
316313
/// * Both the starting and other pointer must be either in bounds or one
317-
/// byte past the end of the same allocated object. Note that in Rust,
318-
/// every (stack-allocated) variable is considered a separate allocated object.
314+
/// byte past the end of the same [allocated object].
319315
///
320316
/// * Both pointers must be *derived from* a pointer to the same object.
321317
/// (See below for an example.)
@@ -345,6 +341,7 @@ impl<T: ?Sized> *const T {
345341
/// such large allocations either.)
346342
///
347343
/// [`add`]: #method.add
344+
/// [allocated object]: crate::ptr#allocated-object
348345
///
349346
/// # Panics
350347
///
@@ -468,8 +465,7 @@ impl<T: ?Sized> *const T {
468465
/// Behavior:
469466
///
470467
/// * Both the starting and resulting pointer must be either in bounds or one
471-
/// byte past the end of the same allocated object. Note that in Rust,
472-
/// every (stack-allocated) variable is considered a separate allocated object.
468+
/// byte past the end of the same [allocated object].
473469
///
474470
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
475471
///
@@ -494,6 +490,7 @@ impl<T: ?Sized> *const T {
494490
/// enables more aggressive compiler optimizations.
495491
///
496492
/// [`wrapping_add`]: #method.wrapping_add
493+
/// [allocated object]: crate::ptr#allocated-object
497494
///
498495
/// # Examples
499496
///
@@ -532,8 +529,7 @@ impl<T: ?Sized> *const T {
532529
/// Behavior:
533530
///
534531
/// * Both the starting and resulting pointer must be either in bounds or one
535-
/// byte past the end of the same allocated object. Note that in Rust,
536-
/// every (stack-allocated) variable is considered a separate allocated object.
532+
/// byte past the end of the same [allocated object].
537533
///
538534
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
539535
///
@@ -558,6 +554,7 @@ impl<T: ?Sized> *const T {
558554
/// enables more aggressive compiler optimizations.
559555
///
560556
/// [`wrapping_sub`]: #method.wrapping_sub
557+
/// [allocated object]: crate::ptr#allocated-object
561558
///
562559
/// # Examples
563560
///
@@ -594,9 +591,8 @@ impl<T: ?Sized> *const T {
594591
///
595592
/// This operation itself is always safe, but using the resulting pointer is not.
596593
///
597-
/// The resulting pointer remains attached to the same allocated object that `self` points to.
598-
/// It may *not* be used to access a different allocated object. Note that in Rust, every
599-
/// (stack-allocated) variable is considered a separate allocated object.
594+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
595+
/// be used to read or write other allocated objects.
600596
///
601597
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
602598
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -614,10 +610,8 @@ impl<T: ?Sized> *const T {
614610
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
615611
/// allocated object and then re-entering it later is permitted.
616612
///
617-
/// If you need to cross object boundaries, cast the pointer to an integer and
618-
/// do the arithmetic there.
619-
///
620613
/// [`add`]: #method.add
614+
/// [allocated object]: crate::ptr#allocated-object
621615
///
622616
/// # Examples
623617
///
@@ -659,9 +653,8 @@ impl<T: ?Sized> *const T {
659653
///
660654
/// This operation itself is always safe, but using the resulting pointer is not.
661655
///
662-
/// The resulting pointer remains attached to the same allocated object that `self` points to.
663-
/// It may *not* be used to access a different allocated object. Note that in Rust, every
664-
/// (stack-allocated) variable is considered a separate allocated object.
656+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
657+
/// be used to read or write other allocated objects.
665658
///
666659
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
667660
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -679,10 +672,8 @@ impl<T: ?Sized> *const T {
679672
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
680673
/// allocated object and then re-entering it later is permitted.
681674
///
682-
/// If you need to cross object boundaries, cast the pointer to an integer and
683-
/// do the arithmetic there.
684-
///
685675
/// [`sub`]: #method.sub
676+
/// [allocated object]: crate::ptr#allocated-object
686677
///
687678
/// # Examples
688679
///
@@ -997,7 +988,7 @@ impl<T> *const [T] {
997988
/// * The pointer must be [valid] for reads for `ptr.len() * mem::size_of::<T>()` many bytes,
998989
/// and it must be properly aligned. This means in particular:
999990
///
1000-
/// * The entire memory range of this slice must be contained within a single allocated object!
991+
/// * The entire memory range of this slice must be contained within a single [allocated object]!
1001992
/// Slices can never span across multiple allocated objects.
1002993
///
1003994
/// * The pointer must be aligned even for zero-length slices. One
@@ -1019,6 +1010,7 @@ impl<T> *const [T] {
10191010
/// See also [`slice::from_raw_parts`][].
10201011
///
10211012
/// [valid]: crate::ptr#safety
1013+
/// [allocated object]: crate::ptr#allocated-object
10221014
#[inline]
10231015
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
10241016
pub unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]> {

core/src/ptr/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
//! has size 0, i.e., even if memory is not actually touched. Consider using
5656
//! [`NonNull::dangling`] in such cases.
5757
//!
58+
//! ## Allocated object
59+
//!
60+
//! For several operations, such as [`offset`] or field projections (`expr.field`), the notion of an
61+
//! "allocated object" becomes relevant. An allocated object is a contiguous region of memory.
62+
//! Common examples of allocated objects include stack-allocated variables (each variable is a
63+
//! separate allocated object), heap allocations (each allocation created by the global allocator is
64+
//! a separate allocated object), and `static` variables.
65+
//!
5866
//! [aliasing]: ../../nomicon/aliasing.html
5967
//! [book]: ../../book/ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer
6068
//! [ub]: ../../reference/behavior-considered-undefined.html

core/src/ptr/mut_ptr.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ impl<T: ?Sized> *mut T {
189189
/// Behavior:
190190
///
191191
/// * Both the starting and resulting pointer must be either in bounds or one
192-
/// byte past the end of the same allocated object. Note that in Rust,
193-
/// every (stack-allocated) variable is considered a separate allocated object.
192+
/// byte past the end of the same [allocated object].
194193
///
195194
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
196195
///
@@ -215,6 +214,7 @@ impl<T: ?Sized> *mut T {
215214
/// enables more aggressive compiler optimizations.
216215
///
217216
/// [`wrapping_offset`]: #method.wrapping_offset
217+
/// [allocated object]: crate::ptr#allocated-object
218218
///
219219
/// # Examples
220220
///
@@ -251,9 +251,8 @@ impl<T: ?Sized> *mut T {
251251
///
252252
/// This operation itself is always safe, but using the resulting pointer is not.
253253
///
254-
/// The resulting pointer remains attached to the same allocated object that `self` points to.
255-
/// It may *not* be used to access a different allocated object. Note that in Rust, every
256-
/// (stack-allocated) variable is considered a separate allocated object.
254+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
255+
/// be used to read or write other allocated objects.
257256
///
258257
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
259258
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -271,10 +270,8 @@ impl<T: ?Sized> *mut T {
271270
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
272271
/// words, leaving the allocated object and then re-entering it later is permitted.
273272
///
274-
/// If you need to cross object boundaries, cast the pointer to an integer and
275-
/// do the arithmetic there.
276-
///
277273
/// [`offset`]: #method.offset
274+
/// [allocated object]: crate::ptr#allocated-object
278275
///
279276
/// # Examples
280277
///
@@ -485,8 +482,7 @@ impl<T: ?Sized> *mut T {
485482
/// Behavior:
486483
///
487484
/// * Both the starting and other pointer must be either in bounds or one
488-
/// byte past the end of the same allocated object. Note that in Rust,
489-
/// every (stack-allocated) variable is considered a separate allocated object.
485+
/// byte past the end of the same [allocated object].
490486
///
491487
/// * Both pointers must be *derived from* a pointer to the same object.
492488
/// (See below for an example.)
@@ -516,6 +512,7 @@ impl<T: ?Sized> *mut T {
516512
/// such large allocations either.)
517513
///
518514
/// [`add`]: #method.add
515+
/// [allocated object]: crate::ptr#allocated-object
519516
///
520517
/// # Panics
521518
///
@@ -575,8 +572,7 @@ impl<T: ?Sized> *mut T {
575572
/// Behavior:
576573
///
577574
/// * Both the starting and resulting pointer must be either in bounds or one
578-
/// byte past the end of the same allocated object. Note that in Rust,
579-
/// every (stack-allocated) variable is considered a separate allocated object.
575+
/// byte past the end of the same [allocated object].
580576
///
581577
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
582578
///
@@ -639,8 +635,7 @@ impl<T: ?Sized> *mut T {
639635
/// Behavior:
640636
///
641637
/// * Both the starting and resulting pointer must be either in bounds or one
642-
/// byte past the end of the same allocated object. Note that in Rust,
643-
/// every (stack-allocated) variable is considered a separate allocated object.
638+
/// byte past the end of the same [allocated object].
644639
///
645640
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
646641
///
@@ -665,6 +660,7 @@ impl<T: ?Sized> *mut T {
665660
/// enables more aggressive compiler optimizations.
666661
///
667662
/// [`wrapping_sub`]: #method.wrapping_sub
663+
/// [allocated object]: crate::ptr#allocated-object
668664
///
669665
/// # Examples
670666
///
@@ -701,9 +697,8 @@ impl<T: ?Sized> *mut T {
701697
///
702698
/// This operation itself is always safe, but using the resulting pointer is not.
703699
///
704-
/// The resulting pointer remains attached to the same allocated object that `self` points to.
705-
/// It may *not* be used to access a different allocated object. Note that in Rust, every
706-
/// (stack-allocated) variable is considered a separate allocated object.
700+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
701+
/// be used to read or write other allocated objects.
707702
///
708703
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
709704
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -721,10 +716,8 @@ impl<T: ?Sized> *mut T {
721716
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
722717
/// allocated object and then re-entering it later is permitted.
723718
///
724-
/// If you need to cross object boundaries, cast the pointer to an integer and
725-
/// do the arithmetic there.
726-
///
727719
/// [`add`]: #method.add
720+
/// [allocated object]: crate::ptr#allocated-object
728721
///
729722
/// # Examples
730723
///
@@ -766,9 +759,8 @@ impl<T: ?Sized> *mut T {
766759
///
767760
/// This operation itself is always safe, but using the resulting pointer is not.
768761
///
769-
/// The resulting pointer remains attached to the same allocated object that `self` points to.
770-
/// It may *not* be used to access a different allocated object. Note that in Rust, every
771-
/// (stack-allocated) variable is considered a separate allocated object.
762+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
763+
/// be used to read or write other allocated objects.
772764
///
773765
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
774766
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -786,10 +778,8 @@ impl<T: ?Sized> *mut T {
786778
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
787779
/// allocated object and then re-entering it later is permitted.
788780
///
789-
/// If you need to cross object boundaries, cast the pointer to an integer and
790-
/// do the arithmetic there.
791-
///
792781
/// [`sub`]: #method.sub
782+
/// [allocated object]: crate::ptr#allocated-object
793783
///
794784
/// # Examples
795785
///
@@ -1261,7 +1251,7 @@ impl<T> *mut [T] {
12611251
/// * The pointer must be [valid] for reads for `ptr.len() * mem::size_of::<T>()` many bytes,
12621252
/// and it must be properly aligned. This means in particular:
12631253
///
1264-
/// * The entire memory range of this slice must be contained within a single allocated object!
1254+
/// * The entire memory range of this slice must be contained within a single [allocated object]!
12651255
/// Slices can never span across multiple allocated objects.
12661256
///
12671257
/// * The pointer must be aligned even for zero-length slices. One
@@ -1283,6 +1273,7 @@ impl<T> *mut [T] {
12831273
/// See also [`slice::from_raw_parts`][].
12841274
///
12851275
/// [valid]: crate::ptr#safety
1276+
/// [allocated object]: crate::ptr#allocated-object
12861277
#[inline]
12871278
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
12881279
pub unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]> {
@@ -1311,7 +1302,7 @@ impl<T> *mut [T] {
13111302
/// * The pointer must be [valid] for reads and writes for `ptr.len() * mem::size_of::<T>()`
13121303
/// many bytes, and it must be properly aligned. This means in particular:
13131304
///
1314-
/// * The entire memory range of this slice must be contained within a single allocated object!
1305+
/// * The entire memory range of this slice must be contained within a single [allocated object]!
13151306
/// Slices can never span across multiple allocated objects.
13161307
///
13171308
/// * The pointer must be aligned even for zero-length slices. One
@@ -1333,6 +1324,7 @@ impl<T> *mut [T] {
13331324
/// See also [`slice::from_raw_parts_mut`][].
13341325
///
13351326
/// [valid]: crate::ptr#safety
1327+
/// [allocated object]: crate::ptr#allocated-object
13361328
#[inline]
13371329
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
13381330
pub unsafe fn as_uninit_slice_mut<'a>(self) -> Option<&'a mut [MaybeUninit<T>]> {

0 commit comments

Comments
 (0)