Skip to content

Instantly share code, notes, and snippets.

@oyvindln
Created August 17, 2017 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oyvindln/d9f876c43f284cb387a8d4ff112ce7ff to your computer and use it in GitHub Desktop.
Save oyvindln/d9f876c43f284cb387a8d4ff112ce7ff to your computer and use it in GitHub Desktop.
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