Skip to content

Commit 356d64d

Browse files
authored
make offset must_use
https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset: > At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated.
1 parent d903a9d commit 356d64d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/libcore/intrinsics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ extern "rust-intrinsic" {
13111311
///
13121312
/// The stabilized version of this intrinsic is
13131313
/// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1314+
#[must_use = "returns a new pointer rather than modifying its argument"]
13141315
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
13151316

13161317
/// Calculates the offset from a pointer, potentially wrapping.

0 commit comments

Comments
 (0)