Skip to content

Commit a575a8b

Browse files
committed
Auto merge of rust-lang#131111 - matthiaskrgr:rollup-n6do187, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#130005 (Replace -Z default-hidden-visibility with -Z default-visibility) - rust-lang#130229 (ptr::add/sub: do not claim equivalence with `offset(c as isize)`) - rust-lang#130773 (Update Unicode escapes in `/library/core/src/char/methods.rs`) - rust-lang#130933 (rustdoc: lists items that contain multiple paragraphs are more clear) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bcfd953 + 82e1372 commit a575a8b

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
lines changed

core/src/char/methods.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl char {
6969
/// assert_eq!(char::from_u32(value_at_max + 1), None);
7070
/// ```
7171
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
72-
pub const MAX: char = '\u{10ffff}';
72+
pub const MAX: char = '\u{10FFFF}';
7373

7474
/// `U+FFFD REPLACEMENT CHARACTER` (�) is used in Unicode to represent a
7575
/// decoding error.
@@ -1841,7 +1841,6 @@ pub const fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] {
18411841
}
18421842
(2, [a, b, ..]) => {
18431843
code -= 0x1_0000;
1844-
18451844
*a = (code >> 10) as u16 | 0xD800;
18461845
*b = (code & 0x3FF) as u16 | 0xDC00;
18471846
}

core/src/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,7 @@ extern "rust-intrinsic" {
14251425
///
14261426
/// If the computed offset is non-zero, then both the starting and resulting pointer must be
14271427
/// either in bounds or at the end of an allocated object. If either pointer is out
1428-
/// of bounds or arithmetic overflow occurs then any further use of the returned value will
1429-
/// result in undefined behavior.
1428+
/// of bounds or arithmetic overflow occurs then this operation is undefined behavior.
14301429
///
14311430
/// The stabilized version of this intrinsic is [`pointer::offset`].
14321431
#[must_use = "returns a new pointer rather than modifying its argument"]

core/src/ptr/const_ptr.rs

+26-21
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<T: ?Sized> *const T {
346346
if self.is_null() { None } else { Some(unsafe { &*(self as *const MaybeUninit<T>) }) }
347347
}
348348

349-
/// Adds an offset to a pointer.
349+
/// Adds a signed offset to a pointer.
350350
///
351351
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
352352
/// offset of `3 * size_of::<T>()` bytes.
@@ -355,7 +355,8 @@ impl<T: ?Sized> *const T {
355355
///
356356
/// If any of the following conditions are violated, the result is Undefined Behavior:
357357
///
358-
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
358+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
359+
/// "wrapping around"), must fit in an `isize`.
359360
///
360361
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
361362
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -398,7 +399,7 @@ impl<T: ?Sized> *const T {
398399
unsafe { intrinsics::offset(self, count) }
399400
}
400401

401-
/// Calculates the offset from a pointer in bytes.
402+
/// Adds a signed offset in bytes to a pointer.
402403
///
403404
/// `count` is in units of **bytes**.
404405
///
@@ -418,7 +419,7 @@ impl<T: ?Sized> *const T {
418419
unsafe { self.cast::<u8>().offset(count).with_metadata_of(self) }
419420
}
420421

421-
/// Calculates the offset from a pointer using wrapping arithmetic.
422+
/// Adds a signed offset to a pointer using wrapping arithmetic.
422423
///
423424
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
424425
/// offset of `3 * size_of::<T>()` bytes.
@@ -480,7 +481,7 @@ impl<T: ?Sized> *const T {
480481
unsafe { intrinsics::arith_offset(self, count) }
481482
}
482483

483-
/// Calculates the offset from a pointer in bytes using wrapping arithmetic.
484+
/// Adds a signed offset in bytes to a pointer using wrapping arithmetic.
484485
///
485486
/// `count` is in units of **bytes**.
486487
///
@@ -804,7 +805,11 @@ impl<T: ?Sized> *const T {
804805
}
805806
}
806807

807-
/// Adds an offset to a pointer (convenience for `.offset(count as isize)`).
808+
/// Adds an unsigned offset to a pointer.
809+
///
810+
/// This can only move the pointer forward (or not move it). If you need to move forward or
811+
/// backward depending on the value, then you might want [`offset`](#method.offset) instead
812+
/// which takes a signed offset.
808813
///
809814
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
810815
/// offset of `3 * size_of::<T>()` bytes.
@@ -813,7 +818,8 @@ impl<T: ?Sized> *const T {
813818
///
814819
/// If any of the following conditions are violated, the result is Undefined Behavior:
815820
///
816-
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
821+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
822+
/// "wrapping around"), must fit in an `isize`.
817823
///
818824
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
819825
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -856,7 +862,7 @@ impl<T: ?Sized> *const T {
856862
unsafe { intrinsics::offset(self, count) }
857863
}
858864

859-
/// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`).
865+
/// Adds an unsigned offset in bytes to a pointer.
860866
///
861867
/// `count` is in units of bytes.
862868
///
@@ -876,8 +882,11 @@ impl<T: ?Sized> *const T {
876882
unsafe { self.cast::<u8>().add(count).with_metadata_of(self) }
877883
}
878884

879-
/// Subtracts an offset from a pointer (convenience for
880-
/// `.offset((count as isize).wrapping_neg())`).
885+
/// Subtracts an unsigned offset from a pointer.
886+
///
887+
/// This can only move the pointer backward (or not move it). If you need to move forward or
888+
/// backward depending on the value, then you might want [`offset`](#method.offset) instead
889+
/// which takes a signed offset.
881890
///
882891
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
883892
/// offset of `3 * size_of::<T>()` bytes.
@@ -886,7 +895,8 @@ impl<T: ?Sized> *const T {
886895
///
887896
/// If any of the following conditions are violated, the result is Undefined Behavior:
888897
///
889-
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
898+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
899+
/// "wrapping around"), must fit in an `isize`.
890900
///
891901
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
892902
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -937,8 +947,7 @@ impl<T: ?Sized> *const T {
937947
}
938948
}
939949

940-
/// Calculates the offset from a pointer in bytes (convenience for
941-
/// `.byte_offset((count as isize).wrapping_neg())`).
950+
/// Subtracts an unsigned offset in bytes from a pointer.
942951
///
943952
/// `count` is in units of bytes.
944953
///
@@ -958,8 +967,7 @@ impl<T: ?Sized> *const T {
958967
unsafe { self.cast::<u8>().sub(count).with_metadata_of(self) }
959968
}
960969

961-
/// Calculates the offset from a pointer using wrapping arithmetic.
962-
/// (convenience for `.wrapping_offset(count as isize)`)
970+
/// Adds an unsigned offset to a pointer using wrapping arithmetic.
963971
///
964972
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
965973
/// offset of `3 * size_of::<T>()` bytes.
@@ -1020,8 +1028,7 @@ impl<T: ?Sized> *const T {
10201028
self.wrapping_offset(count as isize)
10211029
}
10221030

1023-
/// Calculates the offset from a pointer in bytes using wrapping arithmetic.
1024-
/// (convenience for `.wrapping_byte_offset(count as isize)`)
1031+
/// Adds an unsigned offset in bytes to a pointer using wrapping arithmetic.
10251032
///
10261033
/// `count` is in units of bytes.
10271034
///
@@ -1038,8 +1045,7 @@ impl<T: ?Sized> *const T {
10381045
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
10391046
}
10401047

1041-
/// Calculates the offset from a pointer using wrapping arithmetic.
1042-
/// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
1048+
/// Subtracts an unsigned offset from a pointer using wrapping arithmetic.
10431049
///
10441050
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
10451051
/// offset of `3 * size_of::<T>()` bytes.
@@ -1100,8 +1106,7 @@ impl<T: ?Sized> *const T {
11001106
self.wrapping_offset((count as isize).wrapping_neg())
11011107
}
11021108

1103-
/// Calculates the offset from a pointer in bytes using wrapping arithmetic.
1104-
/// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
1109+
/// Subtracts an unsigned offset in bytes from a pointer using wrapping arithmetic.
11051110
///
11061111
/// `count` is in units of bytes.
11071112
///

core/src/ptr/mut_ptr.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<T: ?Sized> *mut T {
344344
if self.is_null() { None } else { Some(unsafe { &*(self as *const MaybeUninit<T>) }) }
345345
}
346346

347-
/// Adds an offset to a pointer.
347+
/// Adds a signed offset to a pointer.
348348
///
349349
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
350350
/// offset of `3 * size_of::<T>()` bytes.
@@ -353,7 +353,8 @@ impl<T: ?Sized> *mut T {
353353
///
354354
/// If any of the following conditions are violated, the result is Undefined Behavior:
355355
///
356-
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
356+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
357+
/// "wrapping around"), must fit in an `isize`.
357358
///
358359
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
359360
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -398,7 +399,7 @@ impl<T: ?Sized> *mut T {
398399
unsafe { intrinsics::offset(self, count) }
399400
}
400401

401-
/// Calculates the offset from a pointer in bytes.
402+
/// Adds a signed offset in bytes to a pointer.
402403
///
403404
/// `count` is in units of **bytes**.
404405
///
@@ -418,7 +419,8 @@ impl<T: ?Sized> *mut T {
418419
unsafe { self.cast::<u8>().offset(count).with_metadata_of(self) }
419420
}
420421

421-
/// Calculates the offset from a pointer using wrapping arithmetic.
422+
/// Adds a signed offset to a pointer using wrapping arithmetic.
423+
///
422424
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
423425
/// offset of `3 * size_of::<T>()` bytes.
424426
///
@@ -477,7 +479,7 @@ impl<T: ?Sized> *mut T {
477479
unsafe { intrinsics::arith_offset(self, count) as *mut T }
478480
}
479481

480-
/// Calculates the offset from a pointer in bytes using wrapping arithmetic.
482+
/// Adds a signed offset in bytes to a pointer using wrapping arithmetic.
481483
///
482484
/// `count` is in units of **bytes**.
483485
///
@@ -885,7 +887,11 @@ impl<T: ?Sized> *mut T {
885887
unsafe { (self as *const T).sub_ptr(origin) }
886888
}
887889

888-
/// Adds an offset to a pointer (convenience for `.offset(count as isize)`).
890+
/// Adds an unsigned offset to a pointer.
891+
///
892+
/// This can only move the pointer forward (or not move it). If you need to move forward or
893+
/// backward depending on the value, then you might want [`offset`](#method.offset) instead
894+
/// which takes a signed offset.
889895
///
890896
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
891897
/// offset of `3 * size_of::<T>()` bytes.
@@ -894,7 +900,8 @@ impl<T: ?Sized> *mut T {
894900
///
895901
/// If any of the following conditions are violated, the result is Undefined Behavior:
896902
///
897-
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
903+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
904+
/// "wrapping around"), must fit in an `isize`.
898905
///
899906
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
900907
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -937,7 +944,7 @@ impl<T: ?Sized> *mut T {
937944
unsafe { intrinsics::offset(self, count) }
938945
}
939946

940-
/// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`).
947+
/// Adds an unsigned offset in bytes to a pointer.
941948
///
942949
/// `count` is in units of bytes.
943950
///
@@ -957,8 +964,11 @@ impl<T: ?Sized> *mut T {
957964
unsafe { self.cast::<u8>().add(count).with_metadata_of(self) }
958965
}
959966

960-
/// Subtracts an offset from a pointer (convenience for
961-
/// `.offset((count as isize).wrapping_neg())`).
967+
/// Subtracts an unsigned offset from a pointer.
968+
///
969+
/// This can only move the pointer backward (or not move it). If you need to move forward or
970+
/// backward depending on the value, then you might want [`offset`](#method.offset) instead
971+
/// which takes a signed offset.
962972
///
963973
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
964974
/// offset of `3 * size_of::<T>()` bytes.
@@ -967,7 +977,8 @@ impl<T: ?Sized> *mut T {
967977
///
968978
/// If any of the following conditions are violated, the result is Undefined Behavior:
969979
///
970-
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
980+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
981+
/// "wrapping around"), must fit in an `isize`.
971982
///
972983
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
973984
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -1018,8 +1029,7 @@ impl<T: ?Sized> *mut T {
10181029
}
10191030
}
10201031

1021-
/// Calculates the offset from a pointer in bytes (convenience for
1022-
/// `.byte_offset((count as isize).wrapping_neg())`).
1032+
/// Subtracts an unsigned offset in bytes from a pointer.
10231033
///
10241034
/// `count` is in units of bytes.
10251035
///
@@ -1039,8 +1049,7 @@ impl<T: ?Sized> *mut T {
10391049
unsafe { self.cast::<u8>().sub(count).with_metadata_of(self) }
10401050
}
10411051

1042-
/// Calculates the offset from a pointer using wrapping arithmetic.
1043-
/// (convenience for `.wrapping_offset(count as isize)`)
1052+
/// Adds an unsigned offset to a pointer using wrapping arithmetic.
10441053
///
10451054
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
10461055
/// offset of `3 * size_of::<T>()` bytes.
@@ -1099,8 +1108,7 @@ impl<T: ?Sized> *mut T {
10991108
self.wrapping_offset(count as isize)
11001109
}
11011110

1102-
/// Calculates the offset from a pointer in bytes using wrapping arithmetic.
1103-
/// (convenience for `.wrapping_byte_offset(count as isize)`)
1111+
/// Adds an unsigned offset in bytes to a pointer using wrapping arithmetic.
11041112
///
11051113
/// `count` is in units of bytes.
11061114
///
@@ -1117,8 +1125,7 @@ impl<T: ?Sized> *mut T {
11171125
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
11181126
}
11191127

1120-
/// Calculates the offset from a pointer using wrapping arithmetic.
1121-
/// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
1128+
/// Subtracts an unsigned offset from a pointer using wrapping arithmetic.
11221129
///
11231130
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
11241131
/// offset of `3 * size_of::<T>()` bytes.
@@ -1177,8 +1184,7 @@ impl<T: ?Sized> *mut T {
11771184
self.wrapping_offset((count as isize).wrapping_neg())
11781185
}
11791186

1180-
/// Calculates the offset from a pointer in bytes using wrapping arithmetic.
1181-
/// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
1187+
/// Subtracts an unsigned offset in bytes from a pointer using wrapping arithmetic.
11821188
///
11831189
/// `count` is in units of bytes.
11841190
///

0 commit comments

Comments
 (0)