Skip to content

Regression in #![feature(const_let)] #54098

Closed
@qwerty19106

Description

@qwerty19106

The proof source main.rs:

#![feature(min_const_fn)]
#![feature(const_let)]

pub struct AA {
    pub data: [u8; 10],
}

impl AA {
    pub const fn new() -> Self {
        const res: AA = AA { data: [0; 10] };
        res.data[0] = 5;
        res
    }
}

static mut aa: AA = AA::new();

fn main() {
    let ptr = unsafe { &mut aa };
    for a in ptr.data.iter() {
        println!("{}", a);
    }
}

I compiled it and got this error:

pc@home267:~$ rustc main.rs 
error[E0658]: statements in constant functions are unstable (see issue #48821)
  --> src/test.rs:11:9
   |
11 |         res.data[0] = 5;
   |         ^^^^^^^^^^^^^^^
   |
   = help: add #![feature(const_let)] to the crate attributes to enable

error: aborting due to previous error

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

IMPORTANT! The above code contains #![feature(const_let)] already.

pc@home267:~$ rustc --version
rustc 1.30.0-nightly (2d4e34ca8 2018-09-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions