missing/confusing documentation of behavior of str::{floor_char_boundary, ceil_char_boundary} when index > len

オープン 初心者向け
#165,295 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@ericseppanen がすでに取り組んでいます。

2026年11月3日 から。

  • #165431 @ericseppanen による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
documentation

調査の方向性

作業内容は、標準ライブラリのソースコードにある str::floor_char_boundary と str::ceil_char_boundary のドキュメントコメントの修正です。両方のメソッドを見つけ、ceil_char_boundary の既存コメントを読んでください。そのコメントでは、インデックスが末尾を超えている場合の結果は文字列の長さだとしたうえで、その値を「index より小さくない」と呼んでおり、矛盾しています。範囲外の場合の同じ動作を述べる一文を floor_char_boundary に追加し、ceil_char_boundary の注記は言い換えてください。両方のドキュメントが矛盾なくクランプの動作を説明し、ドキュメントテストが引き続き通ることで完了です。

索引モデルが issue の本文から書いたものです。

説明

A-docs needs-triage
Location (URL)

https://doc.rust-lang.org/1.99.1/std/primitive.str.html#method.floor_char_boundary
https://doc.rust-lang.org/1.99.1/std/primitive.str.html#method.ceil_char_boundary

Summary

The documentation for str::floor_char_boundary doesn't say what happens if the requested index is greater than the string length: will it panic? return the input value? clamp to the string length?

It appears the result will always be clamped to a valid byte index, i.e. if the input is past the end, then the return value will be the string length. This means that truncating a string with &s[..s.floor_char_boundary(i)] will do the expected thing (and never panic).

Additionally, str::ceil_char_boundary does document its behavior in this case, but that documentation somewhat contradicts itself:

/// Finds the closest `x` not below `index` where [`is_char_boundary(x)`] is `true`.
///
/// If `index` is greater than the length of the string, this returns the length of the string.

This is confusing because "the length of the string" is a possible return value that could be below index. Perhaps there's a better way to write that?

主要言語
Rust
スター
121k
フォーク
17.3k
平均マージ
2日 20時間
マージ済み PR(30日)
534

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust のほかの issue

rust-lang/rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。