Open
Description
struct Test<T>(T);
impl<T> Test<T> {
const fn unpack(self) -> T {
self.0
}
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0493]: destructors cannot be evaluated at compile-time
--> src/lib.rs:4:21
|
4 | const fn unpack(self) -> T {
| ^^^^ constant functions cannot evaluate destructors
5 | self.0
6 | }
| - value is dropped here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0493`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
However, no destructors are actually ran, as can be seen in the MIR output:
fn <impl at src/lib.rs:3:1: 7:2>::unpack(_1: Test<T>) -> T {
debug self => _1; // in scope 0 at src/lib.rs:4:15: 4:19
let mut _0: T; // return place in scope 0 at src/lib.rs:4:24: 4:25
bb0: {
_0 = move (_1.0: T); // scope 0 at src/lib.rs:5:9: 5:15
return; // scope 0 at src/lib.rs:6:6: 6:6
}
}
The same effect can be observed if the field access is replaced by pattern matching, either in let
or match
.