Skip to content

Wrong error with const let #52613

Closed
@rizakrko

Description

@rizakrko

I tried this code:

#![feature(const_fn)]
#![feature(const_let)]
struct S {
    state: u32,
}

impl S {
    const fn foo(&mut self, x: u32) {
        self.state = x;
    }
}

fn main() {}

And got

error[E0658]: statements in constant functions are unstable (see issue #48821)
 --> src/main.rs:9:9
  |
9 |         self.state = x;
  |         ^^^^^^^^^^^^^^
  |
  = help: add #![feature(const_let)] to the crate attributes to enable

Similar to #51251

Meta

rustc --version --verbose:

rustc 1.29.0-nightly (874dec25e 2018-07-21)
binary: rustc
commit-hash: 874dec25ed4c08d36f17d396b6872ca50313fc8e
commit-date: 2018-07-21
host: x86_64-unknown-linux-gnu
release: 1.29.0-nightly
LLVM version: 7.0

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 lintsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions