Skip to content

Commit

Permalink
Rollup merge of #70359 - kornelski:mustsplit, r=Dylan-DPC
Browse files Browse the repository at this point in the history
must_use on split_off

A couple more for #70194
  • Loading branch information
Centril committed Mar 24, 2020
2 parents dc29016 + 42b10e5 commit db2c70b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit db2c70b

Please sign in to comment.