about summary refs log tree commit diff
path: root/library/core/src/convert
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-17 06:29:57 +0100
committerGitHub <noreply@github.com>2022-02-17 06:29:57 +0100
commit1cc0ae4cbbcb9909035b5b99fc20bf6b79f4010c (patch)
tree5a6133d1341637821d26a31af27b8923e244e134 /library/core/src/convert
parent930fc4f59ddeb9f26d554a2c75c5355989189540 (diff)
parent6fd5cf51c1528c16f8a186ced5d6d21b1d70e319 (diff)
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
Add documentation to more `From::from` implementations.

For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy.

Notes on specific cases:
* The new documentation for `From<T> for T` explains that it is not a conversion at all.
* Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion.
* The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set.
* I did not add documentation to conversions of a specific error type to a more general error type.
* I did not add documentation to unstable code.

This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
Diffstat (limited to 'library/core/src/convert')
-rw-r--r--library/core/src/convert/mod.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs
index 5566c2ffe87..0ceedf93633 100644
--- a/library/core/src/convert/mod.rs
+++ b/library/core/src/convert/mod.rs
@@ -538,6 +538,10 @@ impl<T, U> const Into<U> for T
 where
     U: ~const From<T>,
 {
+    /// Calls `U::from(self)`.
+    ///
+    /// That is, this conversion is whatever the implementation of
+    /// <code>[From]&lt;T&gt; for U</code> chooses to do.
     fn into(self) -> U {
         U::from(self)
     }
@@ -547,6 +551,7 @@ where
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_const_unstable(feature = "const_convert", issue = "88674")]
 impl<T> const From<T> for T {
+    /// Returns the argument unchanged.
     fn from(t: T) -> T {
         t
     }