about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2025-06-03 15:34:37 -0700
committerJosh Triplett <josh@joshtriplett.org>2025-06-03 15:41:47 -0700
commit7ba5d26636b61ffbbefe1999254e66348e652c1a (patch)
tree94bfef79a7ae8e9268348b381a72b9a4d39e1109
parentf412d05e50d0a682502e225b41db77bf4aa302e2 (diff)
downloadrust-7ba5d26636b61ffbbefe1999254e66348e652c1a.tar.gz
rust-7ba5d26636b61ffbbefe1999254e66348e652c1a.zip
`FromStr`: Rework explanation of `FromStr`/`Display` round-tripping
- Drop the phrasing "usually a mistake".
- Mention that `Display` may not be lossless.
- Drop a misplaced parenthetical about round-tripping that didn't fit
  the paragraph it was in.
-rw-r--r--library/core/src/str/traits.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs
index 2f425c82dc8..b9559c83171 100644
--- a/library/core/src/str/traits.rs
+++ b/library/core/src/str/traits.rs
@@ -756,20 +756,19 @@ unsafe impl SliceIndex<str> for ops::RangeToInclusive<usize> {
 /// parse an `i32` with `FromStr`, but not a `&i32`. You can parse a struct that
 /// contains an `i32`, but not one that contains an `&i32`.
 ///
-/// # Input format
+/// # Input format and round-tripping
 ///
 /// The input format expected by a type's `FromStr` implementation depends on the type. Check the
 /// type's documentation for the input formats it knows how to parse. Note that the input format of
 /// a type's `FromStr` implementation might not necessarily accept the output format of its
-/// `Display` implementation; thus, calling `.parse()` on the output from `Display` is usually a
-/// mistake, unless the type has provided and documented additional guarantees about its `Display`
-/// and `FromStr` implementations.
+/// `Display` implementation, and even if it does, the `Display` implementation may not be lossless
+/// so the round-trip may lose information.
 ///
-/// If a type happens to have a lossless `Display` implementation whose output is meant to be
+/// However, if a type has a lossless `Display` implementation whose output is meant to be
 /// conveniently machine-parseable and not just meant for human consumption, then the type may wish
 /// to accept the same format in `FromStr`, and document that usage. Having both `Display` and
 /// `FromStr` implementations where the result of `Display` cannot be parsed with `FromStr` may
-/// surprise users. (However, the result of such parsing may not have the same value as the input.)
+/// surprise users.
 ///
 /// # Examples
 ///