A keyword was used to move control flow out of a const
or static initializer.
This can occur in the following scenario.
A ? was used to return from inside a const initializer:
const fn foo() -> Result<(), ()> { Ok(()) }
fn main() -> Result<(), ()> {
// error: the `?` operator cannot be used to return from inside a `const` initializer
const A: () = foo()?;
Ok(A)
}
To fix this error, either use the keyword or operator outside
the const or static initializer:
const fn foo() -> Result<(), ()> { Ok(()) }
fn main() -> Result<(), ()> {
// store the `Result` in the const and apply `?` later
const A: Result<(), ()> = foo();
Ok(A?)
}
or use let instead of const:
const fn foo() -> Result<(), ()> { Ok(()) }
fn main() -> Result<(), ()> {
let a = foo()?;
Ok(a)
}