-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-control-flowArea: Control flowArea: Control flowA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-control-flowArea: Control flowArea: Control flowA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.