|
|
Subscribe / Log in / New account

Discarding return value, and ignoring return type

Discarding return value, and ignoring return type

Posted Sep 25, 2025 8:11 UTC (Thu) by proski (subscriber, #104)
In reply to: Discarding return value, and ignoring return type by epa
Parent article: Canceling asynchronous Rust

There are three levels of badness here, not two. Discarding a return value in general should be OK, it could be informational (e.g. number of bytes copied). Ignoring Result is worse, it means that the caller doesn't care if the call was successful. I wouldn't do it in serious code, I would at least try to log the error. Ignoring Future is even worse. I cannot imagine why anyone would do, unless it's a test for the compiler, and nobody cares about the runtime behavior.


to post comments

Discarding return value, and ignoring return type

Posted Sep 25, 2025 8:57 UTC (Thu) by taladar (subscriber, #68407) [Link] (1 responses)

Ignoring futures could be useful in unit tests where you only want to test the function creating the future in one test and the future itself in the next one.

Discarding return value, and ignoring return type

Posted Sep 25, 2025 21:26 UTC (Thu) by intgr (subscriber, #39733) [Link]

I think in that case writing `drop(create_future())` would make the intention clearer than assigning to _


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds