diff options
| author | Kevin Reid <kpreid@google.com> | 2021-10-13 08:46:34 -0700 |
|---|---|---|
| committer | Kevin Reid <kpreid@google.com> | 2021-12-04 07:46:36 -0800 |
| commit | 6fd5cf51c1528c16f8a186ced5d6d21b1d70e319 (patch) | |
| tree | 7b11d73338ef78e2cbabedf073c3f52b2b033c06 /library/alloc/src/vec | |
| parent | 887999d163bace7e79370b952bdd1f930ff4cdd5 (diff) | |
| download | rust-6fd5cf51c1528c16f8a186ced5d6d21b1d70e319.tar.gz rust-6fd5cf51c1528c16f8a186ced5d6d21b1d70e319.zip | |
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. * 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/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 88bde6e8ce4..0cc4a55dc99 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2908,10 +2908,6 @@ impl<T: Clone> From<&mut [T]> for Vec<T> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] impl<T, const N: usize> From<[T; N]> for Vec<T> { - #[cfg(not(test))] - fn from(s: [T; N]) -> Vec<T> { - <[T]>::into_vec(box s) - } /// Allocate a `Vec<T>` and move `s`'s items into it. /// /// # Examples @@ -2919,6 +2915,11 @@ impl<T, const N: usize> From<[T; N]> for Vec<T> { /// ``` /// assert_eq!(Vec::from([1, 2, 3]), vec![1, 2, 3]); /// ``` + #[cfg(not(test))] + fn from(s: [T; N]) -> Vec<T> { + <[T]>::into_vec(box s) + } + #[cfg(test)] fn from(s: [T; N]) -> Vec<T> { crate::slice::into_vec(box s) |
