Skip to content

Commit 8cb8d9c

Browse files
authored
Rollup merge of #71165 - lcnr:patch-2, r=Amanieu
`slice::fill`: use `T` instead of generic arg implements #70758 (comment) As the discussion in #70758 has shifted, I now use `T` instead of `&T`.
2 parents 0a675c5 + 902aa62 commit 8cb8d9c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libcore/slice/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// * The `raw` and `bytes` submodules.
2424
// * Boilerplate trait implementations.
2525

26-
use crate::borrow::Borrow;
2726
use crate::cmp;
2827
use crate::cmp::Ordering::{self, Equal, Greater, Less};
2928
use crate::fmt;
@@ -2157,14 +2156,16 @@ impl<T> [T] {
21572156
/// assert_eq!(buf, vec![1; 10]);
21582157
/// ```
21592158
#[unstable(feature = "slice_fill", issue = "70758")]
2160-
pub fn fill<V>(&mut self, value: V)
2159+
pub fn fill(&mut self, value: T)
21612160
where
2162-
V: Borrow<T>,
21632161
T: Clone,
21642162
{
2165-
let value = value.borrow();
2166-
for el in self {
2167-
el.clone_from(value)
2163+
if let Some((last, elems)) = self.split_last_mut() {
2164+
for el in elems {
2165+
el.clone_from(&value);
2166+
}
2167+
2168+
*last = value
21682169
}
21692170
}
21702171

0 commit comments

Comments
 (0)