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 attribute to len_utf8 and len_utf16. #130819

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

bjoernager
Copy link
Contributor

The len_utf8 and len_utf16 methods in char should have the must_use attribute.

The somewhat similar method <[T]>::len has had this attribute since #95274. Considering that these two methods would most likely be used to test the size of a buffer (before a call to encode_utf8 or encode_utf16), not using their return values could indicate a bug.

According to "When to add #[must_use], this is not considered a breaking change (and could be reverted again at a later time).

@rustbot
Copy link
Collaborator

rustbot commented Sep 25, 2024

r? @Noratrieb

rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 25, 2024
Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for linking the dev guide page so I didn't have to look for it :3. this makes sense

@@ -1738,6 +1740,7 @@ impl EscapeDebugExtArgs {
}

#[inline]
#[must_use]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are private functions, so I don't think it matters much whether they are must_use, it seems very unlikely to cause problems if they aren't

@Noratrieb
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 25, 2024

📌 Commit b466fa6 has been approved by Noratrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 25, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#130735 (Simple validation for unsize coercion in MIR validation)
 - rust-lang#130781 (Fix up setting strip = true in Cargo.toml makes build scripts fail in…)
 - rust-lang#130811 (add link from random() helper fn to extensive DefaultRandomSource docs)
 - rust-lang#130819 (Add `must_use` attribute to `len_utf8` and `len_utf16`.)
 - rust-lang#130832 (fix some cfg logic around optimize_for_size and 16-bit targets)
 - rust-lang#130842 (Add tracking issue for io_error_inprogress)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3b25809 into rust-lang:master Sep 25, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 25, 2024
Rollup merge of rust-lang#130819 - bjoernager:char-must-use-len-utf, r=Noratrieb

Add `must_use` attribute to `len_utf8` and `len_utf16`.

The `len_utf8` and `len_utf16` methods in `char` should have the `must_use` attribute.

The somewhat similar method `<[T]>::len` has had this attribute since rust-lang#95274. Considering that these two methods would most likely be used to test the size of a buffer (before a call to `encode_utf8` or `encode_utf16`), *not* using their return values could indicate a bug.

According to ["When to add `#[must_use]`](https://std-dev-guide.rust-lang.org/policy/must-use.html), this is **not** considered a breaking change (and could be reverted again at a later time).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants