- Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.