summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0015.md
blob: ac78f66adada052ae5b3487fa532bb4b8f65874a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
A non-`const` function was called in a `const` context.

Erroneous code example:

```compile_fail,E0015
fn create_some() -> Option<u8> {
    Some(1)
}

// error: cannot call non-const fn `create_some` in constants
const FOO: Option<u8> = create_some();
```

All functions used in a `const` context (constant or static expression) must
be marked `const`.

To fix this error, you can declare `create_some` as a constant function:

```
// declared as a `const` function:
const fn create_some() -> Option<u8> {
    Some(1)
}

const FOO: Option<u8> = create_some(); // no error!
```