Does the wildcard assignment count as last use?

So, does

_ = c

count as a usage of c? Would the compiler deinit c before this line if there's no access to c afterward?

Without wanting to fall in the XY trap, isn't withExtendedLifetime the "official" way to prevent any unwanted deinitialization?

That would be, and that's also why I'm reluctant to also suggest _ = c when answering this question–Avoid a "variable was written to, but never read" without unnecessary read statements.

This warning is painful indeed. Dummy assignment is also my workaround. But I avoid mixing this with lifetime management.

1 Like

_ = c does not count as a use of the loaded value from c, so if your goal is to delay its potential destruction, you'll still need to use withExtendedLifetime.

4 Likes
Terms of Service

Privacy Policy

Cookie Policy