compiler/rustc_error_codes/src/error_codes/E0015.md MARKDOWN 27 lines View on github.com → Search inside
1A non-`const` function was called in a `const` context.23Erroneous code example:45```compile_fail,E00156fn create_some() -> Option<u8> {7    Some(1)8}910// error: cannot call non-const function `create_some` in constants11const FOO: Option<u8> = create_some();12```1314All functions used in a `const` context (constant or static expression) must15be marked `const`.1617To fix this error, you can declare `create_some` as a constant function:1819```20// declared as a `const` function:21const fn create_some() -> Option<u8> {22    Some(1)23}2425const FOO: Option<u8> = create_some(); // no error!26```

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.