Skip to content

Commit ed52372

Browse files
committed
Amended with the suggested syntax+improvements
1 parent 76a3b55 commit ed52372

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/liballoc/borrow.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,17 +480,14 @@ impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
480480
}
481481
}
482482

483-
impl<'a> AddAssign<char> for Cow<'a, str> {
483+
#[stable(feature = "cow_str_add_assign_char", since = "1.41.0")]
484+
impl AddAssign<char> for Cow<'_, str> {
484485
fn add_assign(&mut self, rhs: char) {
485-
if self.is_empty() {
486-
*self = rhs.to_string()
487-
} else {
488-
if let Cow::Borrowed(lhs) = *self {
489-
let mut s = String::with_capacity(lhs.len() + rhs.len_utf8());
490-
s.push_str(lhs);
491-
*self = Cow::Owned(s);
492-
}
493-
self.to_mut().push(rhs);
486+
if let Cow::Borrowed(lhs) = *self {
487+
let mut s = String::with_capacity(lhs.len() + rhs.len_utf8());
488+
s.push_str(lhs);
489+
*self = Cow::Owned(s);
494490
}
491+
self.to_mut().push(rhs);
495492
}
496493
}

0 commit comments

Comments
 (0)