Trying to understand a lifetime error (E0597)

Thanks @vitalyd for noting that an improvement is coming! Your answer also helped me improve my searching, which got me to the right place in the language reference, which states (emphasis mine):

... the lifetime of temporary values is typically the innermost enclosing statement; the tail expression of a block is considered part of the statement that encloses the block ...

along with with this reddit thread which discusses the issue in much more detail. That thread in particular discusses some cases in which this rule is necessary, but also notes that this is an issue that multiple users been bitten by unexpectedly.

3 Likes