Closed
Description
example by @felix91gr
#![feature(const_generics)]
#![allow(const_err)]
fn foo<const C: u8>() {
if C > 0 {
println!("Foo gives {}", 25 / C);
}
else {
println!("Foo gives 0");
}
}
fn main() {
foo::<0>();
}
Note that this currently requires allow(const_err)
because 25 /C
would panic at runtime.
This is however fine as it isn't reachable because of C > 0
.
We probably should relax this slightly here, not sure what's the best approach though
Other example (by @RalfJung)
const D: u8 = 0; // imagine this is in a different crate
pub fn foo() {
if D > 0 {
let _val = 25/D; // ERROR
} else {
panic!()
}
}