about summary refs log tree commit diff
path: root/tests/rustdoc-js-std/parser-paths.js
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-04-22 01:22:13 +0000
committerGitHub <noreply@github.com>2025-04-22 01:22:13 +0000
commit8f42ac0043dde085d1b392a3d687fdf8bd68a611 (patch)
tree7b92ac152a64803bdfd2248b90d4d9772991136c /tests/rustdoc-js-std/parser-paths.js
parent07a28ec2fb99d8b408c02e19558aca19b2358685 (diff)
parent834e476a0c3d275d267d10425aa3a22666e9376e (diff)
downloadrust-8f42ac0043dde085d1b392a3d687fdf8bd68a611.tar.gz
rust-8f42ac0043dde085d1b392a3d687fdf8bd68a611.zip
Rollup merge of #140094 - Kivooeo:raw-pointer-assignment-suggestion, r=compiler-errors
Improve diagnostics for pointer arithmetic += and -= (fixes #137391)

**Description**:

This PR improves the diagnostic message for cases where a binary assignment operation like `ptr += offset` or `ptr -= offset` is attempted on `*mut T`. These operations are not allowed, and the compiler previously suggested calling `.add()` or `.wrapping_add()`, which is misleading if not assigned.

This PR updates the diagnostics to suggest assigning the result of `.wrapping_add()` or `.wrapping_sub()` back to the pointer, e.g.:

**Examples**

For this code
```rust
let mut arr = [0u8; 10];
let mut ptr = arr.as_mut_ptr();

ptr += 2;
```
it will say:
```rust
10 |     ptr += 2;
   |     ---^^^^^
   |     |
   |     cannot use `+=` on type `*mut u8`
   |
help: consider replacing `ptr += offset` with `ptr = ptr.wrapping_add(offset)` or `ptr.add(offset)`
   |
10 -     ptr += 2;
10 +     ptr = ptr.wrapping_add(2);
```

**Related issue**: #137391
cc `@nabijaczleweli` for context (issue author)
Diffstat (limited to 'tests/rustdoc-js-std/parser-paths.js')
0 files changed, 0 insertions, 0 deletions