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

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

Closed
toku-sa-n opened this issue Sep 24, 2020 · 1 comment · Fixed by #77136
Closed

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

toku-sa-n opened this issue Sep 24, 2020 · 1 comment · Fixed by #77136
Assignees
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@toku-sa-n
Copy link

toku-sa-n commented Sep 24, 2020

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

@toku-sa-n toku-sa-n added the C-bug Category: This is a bug. label Sep 24, 2020
@ecstatic-morse ecstatic-morse self-assigned this Sep 24, 2020
@ecstatic-morse ecstatic-morse added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 24, 2020
@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Sep 24, 2020

After #76850, #![feature(const_mut_refs)] is required instead of #![feature(const_fn)]. #77136 will emit the correct suggestion.

@ecstatic-morse ecstatic-morse added the B-unstable Blocker: Implemented in the nightly compiler and unstable. label Sep 24, 2020
toku-sa-n added a commit to toku-sa-n/linked-list-allocator that referenced this issue Sep 24, 2020
toku-sa-n added a commit to toku-sa-n/x86_64 that referenced this issue Sep 24, 2020
phil-opp pushed a commit to rust-osdev/x86_64 that referenced this issue Sep 24, 2020
phil-opp pushed a commit to rust-osdev/linked-list-allocator that referenced this issue Sep 24, 2020
@bors bors closed this as completed in 473ae22 Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants