Assume that the condition is always true.
This may enable additional optimizations when you know better than the compiler.
If the condition is false, this is equivalent to assert in debug mode. In release mode, it will cause undefined behavior.
Examples
use std::assume;
use std::collections::Vector;
fn get_unchecked<T>(vec: &Vector<T>, index: usize) -> T {
assume!(index < vec.len());
vec.get(index).unwrap()
}
let vec = Vector::from_slice(&[0, 1, 2, 3, 4]);
// The bounds check in Vector::get *may* be optimized out:
println!("{}", vec.get_unchecked(3));
// In release mode, this will likely segfault, but can also make demons
// fly out of your nose:
// println!("{}", vec.get_unchecked(10));
Run this example
use std::assume;
assume!(1 > 2); // Ò̴̡̤̗̬̳̱͉̳͓̝̥̞͗́̿͑̂̓̀͋̈́͐̏͝H̷̳̺̝̗̖̖̫͆̀́̚͝ ̷͚̜̟̘̦̺̼̣̘̓N̸̜̞̬̞͓̮̘̣͍͕͍̱̮̍͛̇̋̅̏͒̕͠Ỏ̴̭̯͘̚̕
Run this example