Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita778c83

Browse files
committed
Auto merge ofrust-lang#127777 - matthiaskrgr:rollup-qp2vkan, r=matthiaskrgr
Rollup of 6 pull requestsSuccessful merges: -rust-lang#124921 (offset_from: always allow pointers to point to the same address) -rust-lang#127407 (Make parse error suggestions verbose and fix spans) -rust-lang#127684 (consolidate miri-unleashed tests for mutable refs into one file) -rust-lang#127729 (Stop using the `gen` identifier in the compiler) -rust-lang#127736 (Add myself to the review rotation) -rust-lang#127758 (coverage: Restrict `ExpressionUsed` simplification to `Code` mappings)r? `@ghost``@rustbot` modify labels: rollup
2 parentsac443f2 +6535591 commita778c83

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

‎core/src/ptr/const_ptr.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,9 @@ impl<T: ?Sized> *const T {
604604
///
605605
/// * `self` and `origin` must either
606606
///
607+
/// * point to the same address, or
607608
/// * both be *derived from* a pointer to the same [allocated object], and the memory range between
608-
/// the two pointers must be either empty or in bounds of that object. (See below for an example.)
609-
/// * or both be derived from an integer literal/constant, and point to the same address.
609+
/// the two pointers must be in bounds of that object. (See below for an example.)
610610
///
611611
/// * The distance between the pointers, in bytes, must be an exact multiple
612612
/// of the size of `T`.
@@ -653,14 +653,14 @@ impl<T: ?Sized> *const T {
653653
/// let ptr1 = Box::into_raw(Box::new(0u8)) as *const u8;
654654
/// let ptr2 = Box::into_raw(Box::new(1u8)) as *const u8;
655655
/// let diff = (ptr2 as isize).wrapping_sub(ptr1 as isize);
656-
/// // Make ptr2_other an "alias" of ptr2, but derived from ptr1.
657-
/// let ptr2_other = (ptr1 as *const u8).wrapping_offset(diff);
656+
/// // Make ptr2_other an "alias" of ptr2.add(1), but derived from ptr1.
657+
/// let ptr2_other = (ptr1 as *const u8).wrapping_offset(diff).wrapping_offset(1);
658658
/// assert_eq!(ptr2 as usize, ptr2_other as usize);
659659
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
660660
/// // computing their offset is undefined behavior, even though
661-
/// // they point to the sameaddress!
661+
/// // they point toaddresses that are in-bounds ofthe sameobject!
662662
/// unsafe {
663-
/// letzero = ptr2_other.offset_from(ptr2); // Undefined Behavior
663+
/// letone = ptr2_other.offset_from(ptr2); // Undefined Behavior! ⚠️
664664
/// }
665665
/// ```
666666
#[stable(feature ="ptr_offset_from", since ="1.47.0")]

‎core/src/ptr/mut_ptr.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,9 @@ impl<T: ?Sized> *mut T {
829829
///
830830
/// * `self` and `origin` must either
831831
///
832+
/// * point to the same address, or
832833
/// * both be *derived from* a pointer to the same [allocated object], and the memory range between
833-
/// the two pointers must be either empty or in bounds of that object. (See below for an example.)
834-
/// * or both be derived from an integer literal/constant, and point to the same address.
834+
/// the two pointers must be in bounds of that object. (See below for an example.)
835835
///
836836
/// * The distance between the pointers, in bytes, must be an exact multiple
837837
/// of the size of `T`.
@@ -878,14 +878,14 @@ impl<T: ?Sized> *mut T {
878878
/// let ptr1 = Box::into_raw(Box::new(0u8));
879879
/// let ptr2 = Box::into_raw(Box::new(1u8));
880880
/// let diff = (ptr2 as isize).wrapping_sub(ptr1 as isize);
881-
/// // Make ptr2_other an "alias" of ptr2, but derived from ptr1.
882-
/// let ptr2_other = (ptr1 as *mut u8).wrapping_offset(diff);
881+
/// // Make ptr2_other an "alias" of ptr2.add(1), but derived from ptr1.
882+
/// let ptr2_other = (ptr1 as *mut u8).wrapping_offset(diff).wrapping_offset(1);
883883
/// assert_eq!(ptr2 as usize, ptr2_other as usize);
884884
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
885885
/// // computing their offset is undefined behavior, even though
886-
/// // they point to the sameaddress!
886+
/// // they point toaddresses that are in-bounds ofthe sameobject!
887887
/// unsafe {
888-
/// letzero = ptr2_other.offset_from(ptr2); // Undefined Behavior
888+
/// letone = ptr2_other.offset_from(ptr2); // Undefined Behavior! ⚠️
889889
/// }
890890
/// ```
891891
#[stable(feature ="ptr_offset_from", since ="1.47.0")]

‎core/src/ptr/non_null.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,9 @@ impl<T: ?Sized> NonNull<T> {
735735
///
736736
/// * `self` and `origin` must either
737737
///
738+
/// * point to the same address, or
738739
/// * both be *derived from* a pointer to the same [allocated object], and the memory range between
739-
/// the two pointers must be either empty or in bounds of that object. (See below for an example.)
740-
/// * or both be derived from an integer literal/constant, and point to the same address.
740+
/// the two pointers must be in bounds of that object. (See below for an example.)
741741
///
742742
/// * The distance between the pointers, in bytes, must be an exact multiple
743743
/// of the size of `T`.
@@ -789,14 +789,15 @@ impl<T: ?Sized> NonNull<T> {
789789
/// let ptr1 = NonNull::new(Box::into_raw(Box::new(0u8))).unwrap();
790790
/// let ptr2 = NonNull::new(Box::into_raw(Box::new(1u8))).unwrap();
791791
/// let diff = (ptr2.addr().get() as isize).wrapping_sub(ptr1.addr().get() as isize);
792-
/// // Make ptr2_other an "alias" of ptr2, but derived from ptr1.
793-
/// let ptr2_other = NonNull::new(ptr1.as_ptr().wrapping_byte_offset(diff)).unwrap();
792+
/// // Make ptr2_other an "alias" of ptr2.add(1), but derived from ptr1.
793+
/// let diff_plus_1 = diff.wrapping_add(1);
794+
/// let ptr2_other = NonNull::new(ptr1.as_ptr().wrapping_byte_offset(diff_plus_1)).unwrap();
794795
/// assert_eq!(ptr2.addr(), ptr2_other.addr());
795796
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
796797
/// // computing their offset is undefined behavior, even though
797-
/// // they point to the sameaddress!
798+
/// // they point toaddresses that are in-bounds ofthe sameobject!
798799
///
799-
/// letzero = unsafe { ptr2_other.offset_from(ptr2) }; // Undefined Behavior
800+
/// letone = unsafe { ptr2_other.offset_from(ptr2) }; // Undefined Behavior! ⚠️
800801
/// ```
801802
#[inline]
802803
#[cfg_attr(miri, track_caller)]// even without panics, this helps for Miri backtraces

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp