Skip to content

Instantly share code, notes, and snippets.

@oyvindln oyvindln/const.rs
Created Aug 17, 2017

Embed
What would you like to do?
const
#![crate_type = "lib"]
#![feature(const_fn)]
const fn foo() -> usize {
10
}
// Ends up as simply return 25 in the mir output.
pub fn test1<T>() -> usize {
if true {
25
} else {
99
}
}
// This does not.
pub fn test2<T>() -> usize {
if foo() < 32 {
25
} else {
99
}
}
// Neither does this.
pub fn test3<T>() -> usize {
if 10 < 32 {
25
} else {
99
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.