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

Add must_use function attributes #657

Closed
wants to merge 1 commit into from
Closed

Conversation

cgzones
Copy link

@cgzones cgzones commented Feb 2, 2024

Annotate several public funtions that either don't modify their original value or only compute a value, except for ones returning Result.

Avoid no-op code such as:

let odt = OffsetDateTime::now_utc();
odt.saturating_add(Duration::SECOND);

Annotate several public funtions that either don't modify their original
value or only compute a value, except for ones returning `Result`.

Avoid no-op code such as:

    let odt = OffsetDateTime::now_utc();
    odt.saturating_add(Duration::SECOND);
@jhpratt
Copy link
Member

jhpratt commented Feb 3, 2024

If there is a specific method you think could be reasonably interpreted as mutating the input that does not already have a #[must_use] attribute, please open an issue to discuss it. Adding it to everything is functionally pointless.

@jhpratt jhpratt closed this Feb 3, 2024
@jhpratt jhpratt added the C-invalid Category: no issue exists or the issue cannot be reproduced label Feb 3, 2024
@cgzones
Copy link
Author

cgzones commented Feb 15, 2024

Is it though?
For example std::time::Duration uses the annotation on almost every interface (except for ones returning Result, since Result already comes with an annotation).

@jhpratt
Copy link
Member

jhpratt commented Feb 15, 2024

And I disagree with using it that much. As I said, a method needs to be able to be reasonably interpreted as mutating the input. That is the criteria that I am using. Anything else is a non-starter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-invalid Category: no issue exists or the issue cannot be reproduced
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants