-
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-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.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
It's not possible to implement Option::unwrap
as a const fn like:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=8ad0c1cdd371ca0488fab9d872bd6ffe
#![feature(const_fn)]
#![feature(const_if_match)]
#![feature(const_panic)]
const fn unwrap<T>(opt:Option<T>)->T{
match opt {
Some(x)=>x,
None=>panic!("Trying to unwrap a None"),
}
}
Because the function triggers this error:
error[E0493]: destructors cannot be evaluated at compile-time
--> src/lib.rs:5:20
|
5 | const fn unwrap<T>(opt:Option<T>)->T{
| ^^^ constant functions cannot evaluate destructors
error: aborting due to previous error
schneiderfelipeschneiderfelipeecstatic-morse, mpfaff and schneiderfelipeschneiderfelipeschneiderfelipe, qRoC and orzogc
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-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.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.