Rollup merge of #130229 - RalfJung:ptr-offset-unsigned, r=scottmcm · qinheping/verify-rust-std@b33d815 (original) (raw)

`@@ -344,7 +344,7 @@ impl<T: ?Sized> *mut T {

`

344

344

`if self.is_null() { None } else { Some(unsafe { &*(self as *const MaybeUninit) }) }

`

345

345

`}

`

346

346

``

347

``

`-

/// Adds an offset to a pointer.

`

``

347

`+

/// Adds a signed offset to a pointer.

`

348

348

`///

`

349

349

`` /// count is in units of T; e.g., a count of 3 represents a pointer

``

350

350

`` /// offset of 3 * size_of::<T>() bytes.

``

`@@ -353,7 +353,8 @@ impl<T: ?Sized> *mut T {

`

353

353

`///

`

354

354

`/// If any of the following conditions are violated, the result is Undefined Behavior:

`

355

355

`///

`

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.

``

357

358

`///

`

358

359

`` /// * If the computed offset is non-zero, then self must be derived from a pointer to some

``

359

360

`` /// [allocated object], and the entire memory range between self and the result must be in

``

`@@ -398,7 +399,7 @@ impl<T: ?Sized> *mut T {

`

398

399

`unsafe { intrinsics::offset(self, count) }

`

399

400

`}

`

400

401

``

401

``

`-

/// Calculates the offset from a pointer in bytes.

`

``

402

`+

/// Adds a signed offset in bytes to a pointer.

`

402

403

`///

`

403

404

`` /// count is in units of bytes.

``

404

405

`///

`

`@@ -418,7 +419,8 @@ impl<T: ?Sized> *mut T {

`

418

419

`unsafe { self.cast::().offset(count).with_metadata_of(self) }

`

419

420

`}

`

420

421

``

421

``

`-

/// Calculates the offset from a pointer using wrapping arithmetic.

`

``

422

`+

/// Adds a signed offset to a pointer using wrapping arithmetic.

`

``

423

`+

///

`

422

424

`` /// count is in units of T; e.g., a count of 3 represents a pointer

``

423

425

`` /// offset of 3 * size_of::<T>() bytes.

``

424

426

`///

`

`@@ -477,7 +479,7 @@ impl<T: ?Sized> *mut T {

`

477

479

`unsafe { intrinsics::arith_offset(self, count) as *mut T }

`

478

480

`}

`

479

481

``

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.

`

481

483

`///

`

482

484

`` /// count is in units of bytes.

``

483

485

`///

`

`@@ -885,7 +887,11 @@ impl<T: ?Sized> *mut T {

`

885

887

`unsafe { (self as *const T).sub_ptr(origin) }

`

886

888

`}

`

887

889

``

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 instead

``

``

894

`+

/// which takes a signed offset.

`

889

895

`///

`

890

896

`` /// count is in units of T; e.g., a count of 3 represents a pointer

``

891

897

`` /// offset of 3 * size_of::<T>() bytes.

``

`@@ -894,7 +900,8 @@ impl<T: ?Sized> *mut T {

`

894

900

`///

`

895

901

`/// If any of the following conditions are violated, the result is Undefined Behavior:

`

896

902

`///

`

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.

``

898

905

`///

`

899

906

`` /// * If the computed offset is non-zero, then self must be derived from a pointer to some

``

900

907

`` /// [allocated object], and the entire memory range between self and the result must be in

``

`@@ -937,7 +944,7 @@ impl<T: ?Sized> *mut T {

`

937

944

`unsafe { intrinsics::offset(self, count) }

`

938

945

`}

`

939

946

``

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.

`

941

948

`///

`

942

949

`` /// count is in units of bytes.

``

943

950

`///

`

`@@ -957,8 +964,11 @@ impl<T: ?Sized> *mut T {

`

957

964

`unsafe { self.cast::().add(count).with_metadata_of(self) }

`

958

965

`}

`

959

966

``

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 instead

``

``

971

`+

/// which takes a signed offset.

`

962

972

`///

`

963

973

`` /// count is in units of T; e.g., a count of 3 represents a pointer

``

964

974

`` /// offset of 3 * size_of::<T>() bytes.

``

`@@ -967,7 +977,8 @@ impl<T: ?Sized> *mut T {

`

967

977

`///

`

968

978

`/// If any of the following conditions are violated, the result is Undefined Behavior:

`

969

979

`///

`

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.

``

971

982

`///

`

972

983

`` /// * If the computed offset is non-zero, then self must be derived from a pointer to some

``

973

984

`` /// [allocated object], and the entire memory range between self and the result must be in

``

`@@ -1018,8 +1029,7 @@ impl<T: ?Sized> *mut T {

`

1018

1029

`}

`

1019

1030

`}

`

1020

1031

``

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.

`

1023

1033

`///

`

1024

1034

`` /// count is in units of bytes.

``

1025

1035

`///

`

`@@ -1039,8 +1049,7 @@ impl<T: ?Sized> *mut T {

`

1039

1049

`unsafe { self.cast::().sub(count).with_metadata_of(self) }

`

1040

1050

`}

`

1041

1051

``

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.

`

1044

1053

`///

`

1045

1054

`` /// count is in units of T; e.g., a count of 3 represents a pointer

``

1046

1055

`` /// offset of 3 * size_of::<T>() bytes.

``

`@@ -1099,8 +1108,7 @@ impl<T: ?Sized> *mut T {

`

1099

1108

`self.wrapping_offset(count as isize)

`

1100

1109

`}

`

1101

1110

``

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.

`

1104

1112

`///

`

1105

1113

`` /// count is in units of bytes.

``

1106

1114

`///

`

`@@ -1117,8 +1125,7 @@ impl<T: ?Sized> *mut T {

`

1117

1125

`self.cast::().wrapping_add(count).with_metadata_of(self)

`

1118

1126

`}

`

1119

1127

``

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.

`

1122

1129

`///

`

1123

1130

`` /// count is in units of T; e.g., a count of 3 represents a pointer

``

1124

1131

`` /// offset of 3 * size_of::<T>() bytes.

``

`@@ -1177,8 +1184,7 @@ impl<T: ?Sized> *mut T {

`

1177

1184

`self.wrapping_offset((count as isize).wrapping_neg())

`

1178

1185

`}

`

1179

1186

``

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.

`

1182

1188

`///

`

1183

1189

`` /// count is in units of bytes.

``

1184

1190

`///

`