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_UTF{8, 16}_LEN constants #98198

Closed
wants to merge 7 commits into from

Conversation

Dylan-DPC
Copy link
Member

Closes #45795

Adds two constants for better readability.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 17, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2022
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@yvt yvt left a comment

Choose a reason for hiding this comment

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

Changes the wording (somewhat based on that of char::len_{utf8,utf16}), adds intra-doc links to char::encode_{utf8,utf16}, and adds the "Use char::* instead" sentences from #95566.

library/core/src/char/methods.rs Outdated Show resolved Hide resolved
library/core/src/char/methods.rs Outdated Show resolved Hide resolved
library/core/src/char/mod.rs Outdated Show resolved Hide resolved
library/core/src/char/mod.rs Outdated Show resolved Hide resolved
Dylan-DPC and others added 4 commits June 18, 2022 16:46
Co-authored-by: yvt <i@yvt.jp>
Co-authored-by: yvt <i@yvt.jp>
Co-authored-by: yvt <i@yvt.jp>
Co-authored-by: yvt <i@yvt.jp>
@@ -45,6 +45,16 @@ impl char {
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
pub const UNICODE_VERSION: (u8, u8, u8) = crate::unicode::UNICODE_VERSION;

/// The maximum number of bytes required to [encode](char::encode_utf8) a
/// `char` in UTF-8.
#[stable(feature = "max_len", since = "1.63.0")]
Copy link
Member

Choose a reason for hiding this comment

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

I think these should go in unstable with a tracking issue, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could but i thought since these were constants that replaced literal values we could directly stabilise them. I'm fine with adding unstable feature if that's the way to go

Copy link
Member

Choose a reason for hiding this comment

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

There's basically three possible ways forward:

  1. This is an internal code readability change, so the consts are pub(crate) and it goes in with a T-libs review.
  2. This is a new API going in unstable, so it can go in with just a review on a "seems reasonable" basis.
  3. This goes in insta-stable, at which point is needs a full T-libs-api FCP.

Basically we only do 3 if forced (because some things can't go in unstable). So please make it unstable with a tracking issue, and then it can just be approved. (Consider also doing some commit squashing.)

/// The maximum number of bytes required to [encode](char::encode_utf8) a
/// `char` in UTF-8. Use [`char::MAX_UTF8_LEN`] instead.
#[stable(feature = "max_len", since = "1.63.0")]
pub const MAX_UTF8_LEN: usize = char::MAX_UTF8_LEN;
Copy link
Member

Choose a reason for hiding this comment

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

pondering: are the module-level constants still desirable, now that we can have type-associated ones? It's unclear to me how to apply precedent from #68490 here -- the char module certainly can't go away. But if the doc comment on this constant says not to use it, why add it?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeh i didn't think of type-associated ones, will change it to that

@bors
Copy link
Contributor

bors commented Jun 26, 2022

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

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2022
@Dylan-DPC Dylan-DPC 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2022
@JohnCSimon
Copy link
Member

@Dylan-DPC
ping from triage - can you post your status on this PR? This has sat untouched for a while. Thanks!

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@Dylan-DPC
Copy link
Member Author

closing this for the time being. will create a new PR with the changes when I get to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

[std::char] Add MAX_UTF8_LEN and MAX_UTF16_LEN
9 participants