]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 17 Feb 2022 05:29:57 +0000 (06:29 +0100)
committerGitHub <noreply@github.com>
Thu, 17 Feb 2022 05:29:57 +0000 (06:29 +0100)
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.

15 files changed:
1  2 
library/alloc/src/collections/btree/map.rs
library/alloc/src/collections/btree/set.rs
library/alloc/src/collections/linked_list.rs
library/alloc/src/collections/vec_deque/mod.rs
library/alloc/src/vec/mod.rs
library/core/src/cell.rs
library/core/src/convert/mod.rs
library/core/src/lazy.rs
library/core/src/ptr/non_null.rs
library/core/src/ptr/unique.rs
library/core/src/sync/atomic.rs
library/std/src/ffi/c_str.rs
library/std/src/ffi/os_str.rs
library/std/src/path.rs
library/std/src/process.rs

Simple merge
Simple merge
index 5566c2ffe87deeed0a75bb26e745f2527cd5e079,de23dda1d0f4dc0f7dbff4b97c2deec45f17e4f7..0ceedf936333d6d4659998664d0e0b89d6b8d168
@@@ -533,11 -534,14 +533,15 @@@ wher
  
  // From implies Into
  #[stable(feature = "rust1", since = "1.0.0")]
 -impl<T, U> Into<U> for T
 +#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
 +impl<T, U> const Into<U> for T
  where
 -    U: From<T>,
 +    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)
      }
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge