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

Non-capturing closures in statics #44669

Closed
elinorbgr opened this issue Sep 18, 2017 · 2 comments
Closed

Non-capturing closures in statics #44669

elinorbgr opened this issue Sep 18, 2017 · 2 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@elinorbgr
Copy link
Contributor

Now that non-capturing closures can be coerced to function pointers, I really want to do things like this:

struct Foo {
    a: fn(u32) -> u32
}

static FOO: Foo = Foo {
    a: |x| x*2
};

but while it seems to work perfectly, it still returns this warning:

warning: constant evaluation error: unsupported constant expr. This will become a HARD ERROR in the future
 --> src/main.rs:7:19
  |
7 |   static Foo: Foo = Foo {
  |  ___________________^
8 | |     a: |x| x*2
9 | | };
  | |_^
  |
  = note: #[warn(const_err)] on by default

Why would this become an hard error? Is this an error in the lint, or is there a problem in doing this?

@oli-obk
Copy link
Contributor

oli-obk commented Sep 18, 2017

This is just an oversight that happened when closure -> fn ptr coercion was added.

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 18, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Mar 16, 2018

This has been fixed in #46882

@oli-obk oli-obk closed this as completed Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

No branches or pull requests

3 participants