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 MAX_LEN_UTF8 and MAX_LEN_UTF16 Constants #120580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HTGAzureX1212
Copy link
Contributor

This pull request adds the MAX_LEN_UTF8 and MAX_LEN_UTF16 constants as per #45795, gated behind the char_max_len feature.

The constants are currently applied in the alloc, core and std libraries.

@HTGAzureX1212 HTGAzureX1212 changed the title Add MAX_LEN_UTF8 and MAX_LEN_UTF16 constants Add MAX_LEN_UTF8 and MAX_LEN_UTF16 Constants Feb 2, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2024

r? @m-ou-se

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added O-windows Operating system: Windows 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 Feb 2, 2024
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-libs-api-nominated Nominated for discussion during a libs-api team meeting. and removed O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 8, 2024
@bors
Copy link
Contributor

bors commented Feb 19, 2024

☔ The latest upstream changes (presumably #121295) made this pull request unmergeable. Please resolve the merge conflicts.

@joshtriplett
Copy link
Member

In the tracking issue, please include a mention that when stabilizing this we should adjust the documentation of https://doc.rust-lang.org/std/primitive.char.html#method.encode_utf8 to use it.

@m-ou-se
Copy link
Member

m-ou-se commented Feb 27, 2024

We briefly discussed this in the libs-api meeting and are happy to add these as unstable.
Please open a tracking issue and use that in the #[unstable] attributes. Thanks!

@m-ou-se m-ou-se added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Feb 27, 2024
@HTGAzureX1212
Copy link
Contributor Author

Tracking issue created. Will finish the remaining things later today.

@rustbot rustbot added the O-windows Operating system: Windows label Feb 28, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@HTGAzureX1212
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 6, 2024
@bors
Copy link
Contributor

bors commented Jun 22, 2024

☔ The latest upstream changes (presumably #116113) made this pull request unmergeable. Please resolve the merge conflicts.

@clarfonthey
Copy link
Contributor

clarfonthey commented Jun 22, 2024

Small question: why are these constants in the char module instead of being associated constants on the char type? The initial proposal is from 2017 when presumably this wasn't possible, but now that it is, we should probably make them associated constants instead to avoid having to duplicate across multiple modules.

@GrigorenkoPV
Copy link
Contributor

Small question: why are these constants in the char module instead of being associated constants on the char type? The initial proposal is from 2017 when presumably this wasn't possible, but now that it is, we should probably make them associated constants instead to avoid having to duplicate across multiple modules.

From what I can tell, in this PR they are added as associated constants on char-the-type and then also reexported in char-the-module.

@clarfonthey
Copy link
Contributor

clarfonthey commented Jun 24, 2024

Oh, I completely missed that point. I personally wouldn't add module exports since that way there's just one way to access them.

We've also been deprecating the module equivalents of associated consts in a bunch of places, and so adding a new one doesn't make much sense.

@bors
Copy link
Contributor

bors commented Sep 9, 2024

☔ The latest upstream changes (presumably #130165) made this pull request unmergeable. Please resolve the merge conflicts.

@Amanieu Amanieu added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 20, 2024
@joshtriplett
Copy link
Member

Observation: we still don't support importing associated constants in order to use them unqualified, and these seem like the kinds of things people might want to import and use unqualified.

Until we support importing associated constants, I think we should add these as both. We can always deprecate the module constants in the future when we do add that support.

Copy link
Member

@m-ou-se m-ou-se left a comment

Choose a reason for hiding this comment

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

We briefly discussed this in the libs-api meeting. This can be merged after rebasing.

@joshtriplett
Copy link
Member

Recording an observation from a discussion in a meeting: I found MAX_LEN_UTF16 misleading, as I would have expected "number of bytes" rather than "number of 16-bit words".

This isn't a blocking objection, on the basis that anytime I'm using UTF-16 I'm already having a bad time, so this doesn't make it that much worse. I just hope that nobody ever uses this to size e.g. a buffer for a read call and ends up with the wrong buffer length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-libs-api-nominated Nominated for discussion during a libs-api team meeting. O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants