Skip to content

A lint for taking a mutable reference to a constant #829

Closed
@petrochenkov

Description

@petrochenkov

i.e. rust-lang/rfcs#885

This is currently legal and prints 0 1 because a and ARR[0] are actually references to temporaries and not to C and ARR, but this is confusing as hell.

const C: u8 = 0;
const ARR: [u8; 3] = [1, 2, 3];

fn main() {
    let a = &mut C;
    *a = 1;
    ARR[0] = 4;
    println!("{} {}", C, ARR[0]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions