Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post-#112261 pointer += integer diagnostics suggest replacing with unused value #137391

Open
nabijaczleweli opened this issue Feb 21, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-raw-pointers Area: raw pointers, MaybeUninit, NonNull A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nabijaczleweli
Copy link
Contributor

nabijaczleweli commented Feb 21, 2025

Code

fn main() {
	let ga_z = [];
	let mut known_rgbs_groups = 0 as *mut u32;
	known_rgbs_groups += ga_z.len();
}

Current output

stable:

error[E0368]: binary assignment operation `+=` cannot be applied to type `*mut u32`
 --> test.rs:4:2
  |
4 |     known_rgbs_groups += ga_z.len();
  |     -----------------^^^^^^^^^^^^^^
  |     |
  |     cannot use `+=` on type `*mut u32`
  |
help: consider using `wrapping_add` or `add` for pointer + {integer}
  |
4 |     known_rgbs_groups.wrapping_add(ga_z.len());
  |                      ~~~~~~~~~~~~~~          +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0368`.

nightly:

error[E0368]: binary assignment operation `+=` cannot be applied to type `*mut u32`
 --> test.rs:4:2
  |
4 |     known_rgbs_groups += ga_z.len();
  |     -----------------^^^^^^^^^^^^^^
  |     |
  |     cannot use `+=` on type `*mut u32`
  |
help: consider using `wrapping_add` or `add` for pointer + {integer}
  |
4 -     known_rgbs_groups += ga_z.len();
4 +     known_rgbs_groups.wrapping_add(ga_z.len());
  |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0368`.

Desired output

known_rgbs_groups = known_rgbs_groups.add(ga_z.len());

Rationale and extra context

known_rgbs_groups.add(ga_z.len()); doesn't do anything 💀

Rust Version

rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-pc-windows-gnu
release: 1.84.1
LLVM version: 19.1.5
rustc 1.87.0-nightly (827a0d638 2025-02-18)
binary: rustc
commit-hash: 827a0d638dabc9a22c56f9c37a557568f86ac76c
commit-date: 2025-02-18
host: x86_64-pc-windows-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Anything else?

This is #112261, and in 20 comments and 4 review rounds no-one tried += lol

@nabijaczleweli nabijaczleweli added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 21, 2025
@fmease fmease added A-raw-pointers Area: raw pointers, MaybeUninit, NonNull D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-raw-pointers Area: raw pointers, MaybeUninit, NonNull A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants