Skip to content

fix: handle multi-byte UTF-8 identifiers in NameGenerator::suggest_name#21793

Merged
A4-Tacks merged 1 commit intorust-lang:masterfrom
guoyucode:fix/suggest-name-multibyte-utf8
Mar 10, 2026
Merged

fix: handle multi-byte UTF-8 identifiers in NameGenerator::suggest_name#21793
A4-Tacks merged 1 commit intorust-lang:masterfrom
guoyucode:fix/suggest-name-multibyte-utf8

Conversation

@guoyucode
Copy link

split_numeric_suffix used rfind to locate the last non-numeric character and then split at pos + 1. Since rfind returns a byte offset, this panics when the last non-numeric character is multi-byte (e.g. CJK identifiers like 日本語).

Use str::ceil_char_boundary to advance past the full character before splitting.

Added doctests covering CJK and accented Latin identifiers with numeric suffixes.

…ame`

`split_numeric_suffix` used `rfind` to locate the last non-numeric
character and then split at `pos + 1`. Since `rfind` returns a byte
offset, this panics when the last non-numeric character is multi-byte
(e.g. CJK identifiers like `日本語`).

Use `str::ceil_char_boundary` to advance past the full character before
splitting.
Copilot AI review requested due to automatic review settings March 10, 2026 13:53
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a UTF-8 boundary bug in NameGenerator::split_numeric_suffix so that identifiers ending with multi-byte characters (e.g., CJK or accented Latin) no longer risk panicking when splitting off numeric suffixes.

Changes:

  • Add doctests covering multi-byte UTF-8 identifiers with and without numeric suffixes.
  • Fix split_numeric_suffix to split at a valid UTF-8 character boundary using str::ceil_char_boundary.
  • Update the split_numeric_suffix doc example to reflect its actual return value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@A4-Tacks A4-Tacks added this pull request to the merge queue Mar 10, 2026
Merged via the queue into rust-lang:master with commit 129a4b1 Mar 10, 2026
20 of 21 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants