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

const_item_mutation warning is triggered when modifying an array by pointer #79971

Closed
MSxDOS opened this issue Dec 12, 2020 · 0 comments · Fixed by #80133
Closed

const_item_mutation warning is triggered when modifying an array by pointer #79971

MSxDOS opened this issue Dec 12, 2020 · 0 comments · Fixed by #80133
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MSxDOS
Copy link

MSxDOS commented Dec 12, 2020

const ARRAY: *mut [u32; 4] = 0x12345678 as _;

pub unsafe fn test(val: u32) {
    (*ARRAY)[0] = val;
}
Warning: attempting to modify a `const` item
 --> <source>:4:5
  |
4 |     (*ARRAY)[0] = val;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(const_item_mutation)]` on by default
  = note: each usage of a `const` item creates a new temporary; the original `const` item will not be modified
note: `const` item defined here
 --> <source>:1:1
  |
1 | const ARRAY: *mut [u32; 4] = 0x12345678 as _;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#77324 missed that case.

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 12, 2020
@Aaron1011 Aaron1011 self-assigned this Dec 14, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Dec 19, 2020
…tebank

Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere

Fixes rust-lang#79971
JohnTitor added a commit to JohnTitor/rust that referenced this issue Dec 19, 2020
…tebank

Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere

Fixes rust-lang#79971
@bors bors closed this as completed in dea1363 Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants