Skip to content

#![feature(const_fn)] doesn't work #77134

Closed
@toku-sa-n

Description

@toku-sa-n

I tried this code:

#![feature(const_fn)]
struct Foo(Option<&'static mut i32>);
impl Foo {
    const fn new() -> Self {
        Self(None)
    }
}

fn main() {}

I expected to see this happen: Compilable

Instead, this happened:

   Compiling foo v0.1.0 (/home/hiroki/foo)
error[E0723]: mutable references in const fn are unstable
 --> src/main.rs:5:14
  |
5 |         Self(None)
  |              ^^^^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0723`.
error: could not compile `foo`

To learn more, run the command again with --verbose.

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (8b4085359 2020-09-23)
binary: rustc
commit-hash: 8b4085359ae798dedb05c95ad42520557bd25320
commit-date: 2020-09-23
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

I found this bug when I was trying to build linked-list-allocator crate.

cargo-bisect-rustc : https://gist.github.com/toku-sa-n/0b8e18d78c625ee1dd6b9fe630bed7ce

Metadata

Metadata

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.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