Skip to content

deprecate std::char constants and functions#153873

Open
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:deprecate-char-max
Open

deprecate std::char constants and functions#153873
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:deprecate-char-max

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

@folkertdev folkertdev commented Mar 14, 2026

similar to how constants in those modules for numeric types have been deprecated. The std::char module contains:

Three stable constants that this PR deprecates. These already link to their method equivalents.

  • MAX
  • REPLACEMENT_CHARACTER
  • UNICODE_VERSION

two unstable constants that this PR removes. The constants are already stablized as associated constants on char.

  • MAX_LEN_UTF8
  • MAX_LEN_UTF16

Four stable functions that this PR deprecates. These already link to their method equivalents.

  • fn decode_utf16
  • fn from_digit
  • fn from_u32
  • fn from_u32_unchecked⚠

discussion at #t-libs > should `std::char::{MIN, MAX}` be deprecated?.

r? libs-api

@folkertdev folkertdev added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 14, 2026
@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 Mar 14, 2026
@folkertdev folkertdev changed the title deprecate std::char::MAX deprecate std::char constants and functions Mar 14, 2026
@rust-log-analyzer

This comment has been minimized.

Comment on lines -98 to -106
/// The maximum number of bytes required to [encode](char::encode_utf8) a `char` to
/// UTF-8 encoding.
#[unstable(feature = "char_max_len", issue = "121714")]
pub const MAX_LEN_UTF8: usize = char::MAX_LEN_UTF8;

/// The maximum number of two-byte units required to [encode](char::encode_utf16) a `char`
/// to UTF-16 encoding.
#[unstable(feature = "char_max_len", issue = "121714")]
pub const MAX_LEN_UTF16: usize = char::MAX_LEN_UTF16;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is currently no core::char::consts module, so currently these constants are just gone. Should they be added as associated consts, or should that core::char::consts module be added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note to self: the consts being gone completely is the cause of the char_max_len CI failure.

Copy link
Copy Markdown
Contributor

@pitaj pitaj Mar 15, 2026

Choose a reason for hiding this comment

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

They already are associated consts: https://doc.rust-lang.org/stable/std/primitive.char.html#associatedconstant.MAX_LEN_UTF8

And were stabilized under the feature char_max_len_assoc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice, these can probably just be removed then.

similar to how constants in those modules for numeric types have been deprecated
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 15, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Amanieu
Copy link
Copy Markdown
Member

Amanieu commented Mar 17, 2026

@rfcbot merge libs-api

@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 17, 2026
@rust-rfcbot
Copy link
Copy Markdown
Collaborator

rust-rfcbot commented Mar 17, 2026

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 17, 2026
@folkertdev folkertdev added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 24, 2026
@joshtriplett
Copy link
Copy Markdown
Member

joshtriplett commented Apr 7, 2026

The only downside of a deprecation is that we still don't support use char::REPLACEMENT_CHARACTER; for associated constants. But still, 👍.

@joshtriplett
Copy link
Copy Markdown
Member

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Apr 7, 2026
@rust-rfcbot
Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. 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. 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.

8 participants