Skip to content

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

Description

@MSxDOS
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.

Activity

  1. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Dec 12, 2020
  2. self-assigned this
    on Dec 14, 2020
  3. added a commit that references this issue on Dec 17, 2020
    dea1363
  4. added a commit that references this issue on Dec 19, 2020
    66042fc
  5. added a commit that references this issue on Dec 19, 2020
    6b52475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions