]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc/borrow.rs
compiletest: Do not run debuginfo tests with gdb on msvc targets
[rust.git] / src / liballoc / borrow.rs
index d2bdda83fa998ae4e8e195d955627c7c88887fba..51c233a21f1a41ced54ac718792c333dec3f3cae 100644 (file)
@@ -16,8 +16,9 @@
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
-    where B: ToOwned,
-          <B as ToOwned>::Owned: 'a
+where
+    B: ToOwned,
+    <B as ToOwned>::Owned: 'a,
 {
     fn borrow(&self) -> &B {
         &**self
@@ -69,9 +70,7 @@ pub trait ToOwned {
     /// let mut v: Vec<i32> = Vec::new();
     /// [1, 2][..].clone_into(&mut v);
     /// ```
-    #[unstable(feature = "toowned_clone_into",
-               reason = "recently added",
-               issue = "41263")]
+    #[unstable(feature = "toowned_clone_into", reason = "recently added", issue = "41263")]
     fn clone_into(&self, target: &mut Self::Owned) {
         *target = self.to_owned();
     }
@@ -79,7 +78,8 @@ fn clone_into(&self, target: &mut Self::Owned) {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ToOwned for T
-    where T: Clone
+where
+    T: Clone,
 {
     type Owned = T;
     fn to_owned(&self) -> T {
@@ -169,17 +169,16 @@ fn clone_into(&self, target: &mut T) {
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub enum Cow<'a, B: ?Sized + 'a>
-    where B: ToOwned
+where
+    B: ToOwned,
 {
     /// Borrowed data.
     #[stable(feature = "rust1", since = "1.0.0")]
-    Borrowed(#[stable(feature = "rust1", since = "1.0.0")]
-             &'a B),
+    Borrowed(#[stable(feature = "rust1", since = "1.0.0")] &'a B),
 
     /// Owned data.
     #[stable(feature = "rust1", since = "1.0.0")]
-    Owned(#[stable(feature = "rust1", since = "1.0.0")]
-          <B as ToOwned>::Owned),
+    Owned(#[stable(feature = "rust1", since = "1.0.0")] <B as ToOwned>::Owned),
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -195,14 +194,10 @@ fn clone(&self) -> Self {
     }
 
     fn clone_from(&mut self, source: &Self) {
-        if let Owned(ref mut dest) = *self {
-            if let Owned(ref o) = *source {
-                o.borrow().clone_into(dest);
-                return;
-            }
+        match (self, source) {
+            (&mut Owned(ref mut dest), &Owned(ref o)) => o.borrow().clone_into(dest),
+            (t, s) => *t = s.clone(),
         }
-
-        *self = source.clone();
     }
 }
 
@@ -339,7 +334,8 @@ impl<B: ?Sized> Eq for Cow<'_, B> where B: Eq + ToOwned {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<B: ?Sized> Ord for Cow<'_, B>
-    where B: Ord + ToOwned
+where
+    B: Ord + ToOwned,
 {
     #[inline]
     fn cmp(&self, other: &Self) -> Ordering {
@@ -349,8 +345,9 @@ fn cmp(&self, other: &Self) -> Ordering {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B>
-    where B: PartialEq<C> + ToOwned,
-          C: ToOwned
+where
+    B: PartialEq<C> + ToOwned,
+    C: ToOwned,
 {
     #[inline]
     fn eq(&self, other: &Cow<'b, C>) -> bool {
@@ -360,7 +357,8 @@ fn eq(&self, other: &Cow<'b, C>) -> bool {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, B: ?Sized> PartialOrd for Cow<'a, B>
-    where B: PartialOrd + ToOwned
+where
+    B: PartialOrd + ToOwned,
 {
     #[inline]
     fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
@@ -407,7 +405,8 @@ fn default() -> Self {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<B: ?Sized> Hash for Cow<'_, B>
-    where B: Hash + ToOwned
+where
+    B: Hash + ToOwned,
 {
     #[inline]
     fn hash<H: Hasher>(&self, state: &mut H) {
@@ -449,9 +448,7 @@ impl<'a> AddAssign<&'a str> for Cow<'a, str> {
     fn add_assign(&mut self, rhs: &'a str) {
         if self.is_empty() {
             *self = Cow::Borrowed(rhs)
-        } else if rhs.is_empty() {
-            return;
-        } else {
+        } else if !rhs.is_empty() {
             if let Cow::Borrowed(lhs) = *self {
                 let mut s = String::with_capacity(lhs.len() + rhs.len());
                 s.push_str(lhs);
@@ -467,9 +464,7 @@ impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
     fn add_assign(&mut self, rhs: Cow<'a, str>) {
         if self.is_empty() {
             *self = rhs
-        } else if rhs.is_empty() {
-            return;
-        } else {
+        } else if !rhs.is_empty() {
             if let Cow::Borrowed(lhs) = *self {
                 let mut s = String::with_capacity(lhs.len() + rhs.len());
                 s.push_str(lhs);