Content-Length: 13066 | pFad | https://doc.rust-lang.org/reference/../std/../std/vec/../sync/../rc/../../error_codes/./E0015.html

E0015 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0015

A non-const function was called in a const context.

Erroneous code example:

#![allow(unused)]
fn main() {
fn create_some() -> Option<u8> {
    Some(1)
}

// error: cannot call non-const function `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:

#![allow(unused)]
fn main() {
// declared as a `const` function:
const fn create_some() -> Option<u8> {
    Some(1)
}

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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/reference/../std/../std/vec/../sync/../rc/../../error_codes/./E0015.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy