diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index a1bf3a4d7a706..d4299a19383b9 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -931,6 +931,15 @@ pub use macros::Debug; /// [tostring]: ../../std/string/trait.ToString.html /// [tostring_function]: ../../std/string/trait.ToString.html#tymethod.to_string /// +/// # Completeness and parseability +/// +/// `Display` for a type might not necessarily be a lossless or complete representation of the type. +/// 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. +/// /// # Internationalization /// /// Because a type can only have one `Display` implementation, it is often preferable diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index 77c70b978fd15..5597b73acc5a8 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -752,6 +752,21 @@ unsafe impl SliceIndex for ops::RangeToInclusive { /// 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 +/// +/// 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. +/// +/// If a type happens to have 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.) +/// /// # Examples /// /// Basic implementation of `FromStr` on an example `Point` type: