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

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

Closed
qwerty19106 opened this issue Sep 10, 2018 · 2 comments · Fixed by #56070
Closed

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

qwerty19106 opened this issue Sep 10, 2018 · 2 comments · Fixed by #56070
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@qwerty19106
Copy link

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)
@memoryruins
Copy link
Contributor

cc #52613 #51251

@memoryruins memoryruins added A-diagnostics Area: Messages for errors, warnings, and lints A-const-eval Area: Constant evaluation (MIR interpretation) labels Sep 15, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Nov 19, 2018

Note that

        const res: AA = AA { data: [0; 10] };
        res.data[0] = 5;
        res

does not modify res. It creates a new temporary copy of res and modifies that. The resulting res does not contain a 5

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 (MIR interpretation) A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants