Must_use lint for functions returning Result?

Hi. I just ran into a bug where I did not use the boolish value from a function that returned Result<bool>.

I quick-checked with the playground whether a must_use would've saved me, and turns out: it would not have.

Is there a way to make the compiler emit a warning if the Result<_> part of the return value is used, but the bool part is not?


Edit: Related PR to the crate which I mis-used: https://github.com/mitsuhiko/dialoguer/pull/117

1 Like

One way to achieve something like this is by not using a bool at all. If the bool returned by a function is important then either that function could be named appropriately such that it is clear that a bool is returned, or you can use a different enum and mark that one must_use (example in playground).

3 Likes

That is not a solution for a bug in the compiler. There are many situations where people want to return Result<bool, _> and also want to use must_user

I wouldn’t call it a bug. If anything, it’s a missing feature. It’s also kind-of unclear how exactly such a feature is supposed to work. What counts as a “use” of the wrapped value?

2 Likes

Yeah, my bad. I misunderstood the situation a little bit.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.