Can't implement a const Option::unwrap
because of "destructors cannot be evaluated at compile-time" error. #66753
Closed
Description
opened on Nov 25, 2019
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
Activity