Match does not understand lifetimes of enum variants #88423
Labels
A-borrow-checker
Area: The borrow checker
A-patterns
Relating to patterns and pattern matching
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
I tried this code:
I expected the match arm
a @ Example::TotallyOwned { .. } => a
to work, as this variant is completely owned.Instead, I needed to completely destruct the enum variant, and create a new one, to "make Rust understand" I was creating a fully owned enum instance.
I can understand why this error exists: namely if I am returning a rebound instance of the original enum, it still is bound to the
'a
lifetime, however in the case of theTotallyOwned
variant, this lifetime is "meaningless", which (someday?) rustc may be able to see.Since this is more of an "improvement request" kind of issue, let me know if there is a better place to open this, or if this is the sort of thing that would require an RFC.
Meta
This presents in the current stable (1.54.0), as well as the current nightly (2021-08-27), though is likely true for all versions
Backtrace
The text was updated successfully, but these errors were encountered: