rust/tests
Chris Denton 8f42ac0043
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)
2025-04-22 01:22:13 +00:00
..
assembly stabilize naked_functions 2025-04-20 11:18:38 +02:00
auxiliary stabilize naked_functions 2025-04-20 11:18:38 +02:00
codegen Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgross35,Amanieu,traviscross 2025-04-21 18:53:15 +00:00
codegen-units
coverage
coverage-run-rustdoc
crashes Rollup merge of #140021 - compiler-errors:no-deep-norm-ice, r=lcnr 2025-04-21 15:55:58 +00:00
debuginfo Rollup merge of #138599 - adwinwhite:recursive-overflow, r=wesleywiser 2025-04-18 05:17:53 +02:00
incremental UI tests: migrate remaining compile time error-patterns to line annotations 2025-04-13 21:48:53 +03:00
mir-opt Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlin 2025-04-19 19:30:46 +00:00
pretty Auto merge of #139114 - m-ou-se:super-let-pin, r=davidtwco 2025-04-19 08:01:53 +00:00
run-make Rollup merge of #140077 - xizheyin:issue-139805, r=jieyouxu 2025-04-22 01:22:12 +00:00
rustdoc Rollup merge of #139913 - fmease:rustdoc-fix-fn-param-handling, r=GuillaumeGomez 2025-04-18 05:16:31 +02:00
rustdoc-gui Add regression test for #139282 2025-04-07 17:28:46 +02:00
rustdoc-js rustdoc-search: add unbox flag to Result aliases 2025-04-11 11:36:40 -07:00
rustdoc-js-std rustdoc-search: add unbox flag to Result aliases 2025-04-11 11:36:40 -07:00
rustdoc-json Rollup merge of #140076 - aDotInTheVoid:jsondocline, r=GuillaumeGomez 2025-04-21 18:53:19 +00:00
rustdoc-ui Add regression test for #140026 2025-04-19 21:10:40 +02:00
ui Rollup merge of #140094 - Kivooeo:raw-pointer-assignment-suggestion, r=compiler-errors 2025-04-22 01:22:13 +00:00
ui-fulldeps Move eager translation to a method on Diag 2025-04-16 21:38:59 -04:00
COMPILER_TESTS.md