From 95c06a29707c8b2f811495c05b0cd009743e29de Mon Sep 17 00:00:00 2001 From: Mateusz MikuĊ‚a Date: Thu, 5 Sep 2019 13:30:30 +0200 Subject: Apply clippy::needless_return suggestions --- src/liballoc/collections/vec_deque.rs | 2 +- src/liballoc/str.rs | 2 +- src/liballoc/sync.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 0bf573f5e25..8f3dfabd888 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -1817,7 +1817,7 @@ impl VecDeque { } } - return elem; + elem } /// Splits the `VecDeque` into two at the given index. diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 9231c2d3f1d..83816d8b954 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -456,7 +456,7 @@ impl str { } } } - return s; + s } /// Converts a [`Box`] into a [`String`] without copying or allocating. diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 69f8f71197c..80d6c6e0d43 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1638,7 +1638,7 @@ impl Clone for Weak { } } - return Weak { ptr: self.ptr }; + Weak { ptr: self.ptr } } } -- cgit 1.4.1-3-g733a5 From eeb549bfc31c27c6cec98eb852409a51f0a8162c Mon Sep 17 00:00:00 2001 From: Clar Fon Date: Sat, 5 Oct 2019 18:23:37 -0400 Subject: Add Cow::is_borrowed and Cow::is_owned --- src/liballoc/borrow.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/liballoc/lib.rs | 1 + 2 files changed, 42 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/borrow.rs b/src/liballoc/borrow.rs index a9c5bce4c25..d2bdda83fa9 100644 --- a/src/liballoc/borrow.rs +++ b/src/liballoc/borrow.rs @@ -207,6 +207,47 @@ impl Clone for Cow<'_, B> { } impl Cow<'_, B> { + /// Returns true if the data is borrowed, i.e. if `to_mut` would require additional work. + /// + /// # Examples + /// + /// ``` + /// #![feature(cow_is_borrowed)] + /// use std::borrow::Cow; + /// + /// let cow = Cow::Borrowed("moo"); + /// assert!(cow.is_borrowed()); + /// + /// let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string()); + /// assert!(!bull.is_borrowed()); + /// ``` + #[unstable(feature = "cow_is_borrowed", issue = "65143")] + pub fn is_borrowed(&self) -> bool { + match *self { + Borrowed(_) => true, + Owned(_) => false, + } + } + + /// Returns true if the data is owned, i.e. if `to_mut` would be a no-op. + /// + /// # Examples + /// + /// ``` + /// #![feature(cow_is_borrowed)] + /// use std::borrow::Cow; + /// + /// let cow: Cow<'_, str> = Cow::Owned("moo".to_string()); + /// assert!(cow.is_owned()); + /// + /// let bull = Cow::Borrowed("...moo?"); + /// assert!(!bull.is_owned()); + /// ``` + #[unstable(feature = "cow_is_borrowed", issue = "65143")] + pub fn is_owned(&self) -> bool { + !self.is_borrowed() + } + /// Acquires a mutable reference to the owned form of the data. /// /// Clones the data if it is not already owned. diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 3684162d8b1..94379afc2bd 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -85,6 +85,7 @@ #![feature(const_generic_impls_guard)] #![feature(const_generics)] #![feature(const_in_array_repeat_expressions)] +#![feature(cow_is_borrowed)] #![feature(dispatch_from_dyn)] #![feature(core_intrinsics)] #![feature(container_error_extra)] -- cgit 1.4.1-3-g733a5