Skip to content

Commit ffcbd2d

Browse files
authored
Auto merge of #35127 - Manishearth:rollup, r=Manishearth
Rollup of 8 pull requests - Successful merges: #35049, #35058, #35063, #35080, #35090, #35094, #35104, #35106 - Failed merges:
2 parents 7580534 + 0b64a56 commit ffcbd2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+338
-348
lines changed

src/libcollections/linked_list.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,22 @@ impl<T> LinkedList<T> {
203203
/// ```
204204
/// use std::collections::LinkedList;
205205
///
206-
/// let mut a = LinkedList::new();
207-
/// let mut b = LinkedList::new();
208-
/// a.push_back(1);
209-
/// a.push_back(2);
210-
/// b.push_back(3);
211-
/// b.push_back(4);
206+
/// let mut list1 = LinkedList::new();
207+
/// list1.push_back('a');
212208
///
213-
/// a.append(&mut b);
209+
/// let mut list2 = LinkedList::new();
210+
/// list2.push_back('b');
211+
/// list2.push_back('c');
214212
///
215-
/// for e in &a {
216-
/// println!("{}", e); // prints 1, then 2, then 3, then 4
217-
/// }
218-
/// println!("{}", b.len()); // prints 0
213+
/// list1.append(&mut list2);
214+
///
215+
/// let mut iter = list1.iter();
216+
/// assert_eq!(iter.next(), Some(&'a'));
217+
/// assert_eq!(iter.next(), Some(&'b'));
218+
/// assert_eq!(iter.next(), Some(&'c'));
219+
/// assert!(iter.next().is_none());
220+
///
221+
/// assert!(list2.is_empty());
219222
/// ```
220223
#[stable(feature = "rust1", since = "1.0.0")]
221224
pub fn append(&mut self, other: &mut Self) {

src/libcollectionstest/string.rs

+11
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ fn test_push_str() {
192192
assert_eq!(&s[0..], "abcประเทศไทย中华Việt Nam");
193193
}
194194

195+
#[test]
196+
fn test_add_assign() {
197+
let mut s = String::new();
198+
s += "";
199+
assert_eq!(s.as_str(), "");
200+
s += "abc";
201+
assert_eq!(s.as_str(), "abc");
202+
s += "ประเทศไทย中华Việt Nam";
203+
assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam");
204+
}
205+
195206
#[test]
196207
fn test_push() {
197208
let mut data = String::from("ประเทศไทย中");

src/libcore/num/mod.rs

+84
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,31 @@ macro_rules! int_impl {
611611
if b {None} else {Some(a)}
612612
}
613613

614+
/// Checked absolute value. Computes `self.abs()`, returning `None` if
615+
/// `self == MIN`.
616+
///
617+
/// # Examples
618+
///
619+
/// Basic usage:
620+
///
621+
/// ```
622+
/// # #![feature(no_panic_abs)]
623+
///
624+
/// use std::i32;
625+
///
626+
/// assert_eq!((-5i32).checked_abs(), Some(5));
627+
/// assert_eq!(i32::MIN.checked_abs(), None);
628+
/// ```
629+
#[unstable(feature = "no_panic_abs", issue = "35057")]
630+
#[inline]
631+
pub fn checked_abs(self) -> Option<Self> {
632+
if self.is_negative() {
633+
self.checked_neg()
634+
} else {
635+
Some(self)
636+
}
637+
}
638+
614639
/// Saturating integer addition. Computes `self + other`, saturating at
615640
/// the numeric bounds instead of overflowing.
616641
///
@@ -863,6 +888,36 @@ macro_rules! int_impl {
863888
self.overflowing_shr(rhs).0
864889
}
865890

891+
/// Wrapping (modular) absolute value. Computes `self.abs()`,
892+
/// wrapping around at the boundary of the type.
893+
///
894+
/// The only case where such wrapping can occur is when one takes
895+
/// the absolute value of the negative minimal value for the type
896+
/// this is a positive value that is too large to represent in the
897+
/// type. In such a case, this function returns `MIN` itself.
898+
///
899+
/// # Examples
900+
///
901+
/// Basic usage:
902+
///
903+
/// ```
904+
/// # #![feature(no_panic_abs)]
905+
///
906+
/// assert_eq!(100i8.wrapping_abs(), 100);
907+
/// assert_eq!((-100i8).wrapping_abs(), 100);
908+
/// assert_eq!((-128i8).wrapping_abs(), -128);
909+
/// assert_eq!((-128i8).wrapping_abs() as u8, 128);
910+
/// ```
911+
#[unstable(feature = "no_panic_abs", issue = "35057")]
912+
#[inline(always)]
913+
pub fn wrapping_abs(self) -> Self {
914+
if self.is_negative() {
915+
self.wrapping_neg()
916+
} else {
917+
self
918+
}
919+
}
920+
866921
/// Calculates `self` + `rhs`
867922
///
868923
/// Returns a tuple of the addition along with a boolean indicating
@@ -1071,6 +1126,35 @@ macro_rules! int_impl {
10711126
(self >> (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
10721127
}
10731128

1129+
/// Computes the absolute value of `self`.
1130+
///
1131+
/// Returns a tuple of the absolute version of self along with a
1132+
/// boolean indicating whether an overflow happened. If self is the
1133+
/// minimum value (e.g. i32::MIN for values of type i32), then the
1134+
/// minimum value will be returned again and true will be returned for
1135+
/// an overflow happening.
1136+
///
1137+
/// # Examples
1138+
///
1139+
/// Basic usage:
1140+
///
1141+
/// ```
1142+
/// # #![feature(no_panic_abs)]
1143+
///
1144+
/// assert_eq!(10i8.overflowing_abs(), (10,false));
1145+
/// assert_eq!((-10i8).overflowing_abs(), (10,false));
1146+
/// assert_eq!((-128i8).overflowing_abs(), (-128,true));
1147+
/// ```
1148+
#[unstable(feature = "no_panic_abs", issue = "35057")]
1149+
#[inline]
1150+
pub fn overflowing_abs(self) -> (Self, bool) {
1151+
if self.is_negative() {
1152+
self.overflowing_neg()
1153+
} else {
1154+
(self, false)
1155+
}
1156+
}
1157+
10741158
/// Raises self to the power of `exp`, using exponentiation by squaring.
10751159
///
10761160
/// # Examples

0 commit comments

Comments
 (0)