Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add a @mustuse function attribute #83

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

CompeyDev
Copy link

@CompeyDev CompeyDev commented Nov 29, 2024

This RFC proposes a @mustuse attribute, which may be applied to a function, enforcing the usage of a function's return value.

Rendered.

This RFC proposes a `@mustuse` attribute, which may be applied
to a function, enforcing the usage of a function's return
value.
@dv-extrarius
Copy link

I know it's used in several languages, but to me "mustuse" is sort of confusing - it sounds like you have to use the function. In C++ there is the gcc attribute warn_unused_result and the standard nodiscard (don't discard the return value or you get a warning), both of which seem better to me

@CompeyDev
Copy link
Author

I know it's used in several languages, but to me "mustuse" is sort of confusing - it sounds like you have to use the function. In C++ there is the gcc attribute warn_unused_result and the standard nodiscard (don't discard the return value or you get a warning), both of which seem better to me

I would also prefer @nodiscard on second thought, since @mustuse does initially feel like a dead code lint of sorts.

@Dekkonot
Copy link
Contributor

Dekkonot commented Jan 2, 2025

I'd like it if there was a 'reason' argument supported for this attribute, as it may not be obvious at a glance why a value must be used.

Also, this seems like it'd need a presence in the type system. That's not currently implemented, so this RFC is somewhat hiding a much more complicated proposal behind it. I suggest you (or someone else) write an RFC for attributes to exist in the type system.

@CompeyDev
Copy link
Author

I suggest you (or someone else) write an RFC for attributes to exist in the type system.

I was looking to do that as an extension to this RFC once it is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants