Closed
Description
To try and workaround the lack of const
Result::unwrap
on 1.47 I implemented a basic variant of it manually, but this fails to compile without suppressing the unconditional_panic
warning:
#[derive(Copy, Clone)]
pub struct Foo;
impl Foo {
pub const fn new_unwrap(success: bool) -> Self {
let result = if success { Ok(Foo) } else { Err(()) };
[][match result {
Ok(foo) => return foo,
Err(_) => 0,
}]
}
}
fn main() {}
error: this operation will panic at runtime
--> uwu.rs:7:9
|
7 | / [][match result {
8 | | Ok(foo) => return foo,
9 | | Err(_) => 0,
10 | | }]
| |__________^ index out of bounds: the length is 0 but the index is 0
|
= note: `#[deny(unconditional_panic)]` on by default
error: aborting due to previous error
This code panicking is conditional on the input success
value.
@rustbot modify labels: +A-const-fn, +A-lint