about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-05-03 14:17:53 +0530
committerGitHub <noreply@github.com>2020-05-03 14:17:53 +0530
commit8cb8d9cfe26d9044efca0343067857229fd90b97 (patch)
tree24311fde57457f6526337741172b87c44dd09a60 /src/libcore
parent0a675c5e02e6ecfda7d4e04aabd23a9935e0c4bf (diff)
parent902aa62d51210403787f54b881918319e51866c2 (diff)
downloadrust-8cb8d9cfe26d9044efca0343067857229fd90b97.tar.gz
rust-8cb8d9cfe26d9044efca0343067857229fd90b97.zip
Rollup merge of #71165 - lcnr:patch-2, r=Amanieu
`slice::fill`: use `T` instead of generic arg

implements https://github.com/rust-lang/rust/issues/70758#issuecomment-613994427

As the discussion in #70758 has shifted, I now use `T` instead of `&T`.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/slice/mod.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index 7b357bb487a..f74c6862006 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -23,7 +23,6 @@
 // * The `raw` and `bytes` submodules.
 // * Boilerplate trait implementations.
 
-use crate::borrow::Borrow;
 use crate::cmp;
 use crate::cmp::Ordering::{self, Equal, Greater, Less};
 use crate::fmt;
@@ -2157,14 +2156,16 @@ impl<T> [T] {
     /// assert_eq!(buf, vec![1; 10]);
     /// ```
     #[unstable(feature = "slice_fill", issue = "70758")]
-    pub fn fill<V>(&mut self, value: V)
+    pub fn fill(&mut self, value: T)
     where
-        V: Borrow<T>,
         T: Clone,
     {
-        let value = value.borrow();
-        for el in self {
-            el.clone_from(value)
+        if let Some((last, elems)) = self.split_last_mut() {
+            for el in elems {
+                el.clone_from(&value);
+            }
+
+            *last = value
         }
     }