diff options
| author | Kornel <kornel@geekhood.net> | 2020-03-24 13:33:35 +0000 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2020-03-24 17:35:40 +0000 |
| commit | 42b10e51c18ad37f671dc289aa0f183d4dbceab9 (patch) | |
| tree | 61b09b23fd2e88dcd3f7234017304adefca17df6 | |
| parent | 374ab25585f0a817fe7bd6986737f12347b12d0b (diff) | |
| download | rust-42b10e51c18ad37f671dc289aa0f183d4dbceab9.tar.gz rust-42b10e51c18ad37f671dc289aa0f183d4dbceab9.zip | |
must_use on split_off
#70194
| -rw-r--r-- | src/liballoc/collections/vec_deque.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/string.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/tests/string.rs | 4 |
3 files changed, 4 insertions, 2 deletions
diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 9d56f17700a..69284fbf1b3 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -1876,6 +1876,7 @@ impl<T> VecDeque<T> { /// assert_eq!(buf2, [2, 3]); /// ``` #[inline] + #[must_use = "use `.truncate()` if you don't need the other half"] #[stable(feature = "split_off", since = "1.4.0")] pub fn split_off(&mut self, at: usize) -> Self { let len = self.len(); diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 0e48f1548e6..7c89d38caa4 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1461,6 +1461,7 @@ impl String { /// ``` #[inline] #[stable(feature = "string_split_off", since = "1.16.0")] + #[must_use = "use `.truncate()` if you don't need the other half"] pub fn split_off(&mut self, at: usize) -> String { assert!(self.is_char_boundary(at)); let other = self.vec.split_off(at); diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index 08859b2b24b..d2f09eb4a75 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -266,14 +266,14 @@ fn test_split_off_empty() { fn test_split_off_past_end() { let orig = "Hello, world!"; let mut split = String::from(orig); - split.split_off(orig.len() + 1); + let _ = split.split_off(orig.len() + 1); } #[test] #[should_panic] fn test_split_off_mid_char() { let mut orig = String::from("山"); - orig.split_off(1); + let _ = orig.split_off(1); } #[test] |
