about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2025-06-03 15:39:46 -0700
committerJosh Triplett <josh@joshtriplett.org>2025-06-03 15:41:47 -0700
commit742014e7e3576f3053e7c63fc930c4d5b5b7a477 (patch)
tree3dafc61ce8cd2be8941fc4697093a34b1d61edc0
parent7ba5d26636b61ffbbefe1999254e66348e652c1a (diff)
downloadrust-742014e7e3576f3053e7c63fc930c4d5b5b7a477.tar.gz
rust-742014e7e3576f3053e7c63fc930c4d5b5b7a477.zip
`Display`: Rework explanation of `FromStr`/`Display` round-tripping
- Drop "usually a mistake"
- Add phrasing from `FromStr` about round-tripping, and about how the
  inability to round-trip may surprise users.
-rw-r--r--library/core/src/fmt/mod.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index c25ef9ba512..145e581d1fb 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -934,8 +934,13 @@ pub use macros::Debug;
 /// It may omit internal state, precision, or other information the type does not consider important
 /// for user-facing output, as determined by the type. As such, the output of `Display` might not be
 /// possible to parse, and even if it is, the result of parsing might not exactly match the original
-/// value. 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.
+/// value.
+///
+/// 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.
 ///
 /// # Internationalization
 ///