Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #35127

Merged
merged 18 commits into from
Jul 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
132bff9
If a single import resolves to an inaccessible name in some but not a…
jseyfried Jul 25, 2016
8205691
Fix fallout in tests.
jseyfried Jul 26, 2016
6ac83de
Add test for string AddAssign
Jul 26, 2016
cfdaca0
Rename _ to {numerics} for unknown numeric types
Jul 27, 2016
cdc6afe
Add non-panicking abs() functions to all signed integer types.
Jul 26, 2016
ea77049
Move to {integer} and {float}
Jul 28, 2016
6dc98cf
Revert "Remove unused methods from MultiSpan"
mcarton Jul 28, 2016
f459e80
Rewrite `collections::LinkedList::append` doc example.
frewsxcv Jul 29, 2016
2a41b31
syntax_ext: format: fix ICE with bad named arguments
xen0n Jul 29, 2016
415fde4
intravisit: Fold functionality of IdVisitor into the regular Visitor.
michaelwoerister Jul 28, 2016
96e3972
Rollup merge of #35049 - knight42:add-test, r=alexcrichton
Manishearth Jul 30, 2016
6234610
Rollup merge of #35058 - jethrogb:no_panic_abs, r=alexcrichton
Manishearth Jul 30, 2016
8c6421f
Rollup merge of #35063 - jseyfried:avoid_importing_inaccessible_names…
Manishearth Jul 30, 2016
26e22b8
Rollup merge of #35080 - jonathandturner:fix_numeric_expected_found, …
Manishearth Jul 30, 2016
e649a25
Rollup merge of #35090 - michaelwoerister:get-rid-of-id-visitor, r=eddyb
Manishearth Jul 30, 2016
6ea3ef7
Rollup merge of #35094 - mcarton:multispan, r=jonathandturner
Manishearth Jul 30, 2016
ce79972
Rollup merge of #35104 - frewsxcv:linked-list-append, r=steveklabnik
Manishearth Jul 30, 2016
0b64a56
Rollup merge of #35106 - xen0n:issue-35082, r=alexcrichton
Manishearth Jul 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,22 @@ impl<T> LinkedList<T> {
/// ```
/// use std::collections::LinkedList;
///
/// let mut a = LinkedList::new();
/// let mut b = LinkedList::new();
/// a.push_back(1);
/// a.push_back(2);
/// b.push_back(3);
/// b.push_back(4);
/// let mut list1 = LinkedList::new();
/// list1.push_back('a');
///
/// a.append(&mut b);
/// let mut list2 = LinkedList::new();
/// list2.push_back('b');
/// list2.push_back('c');
///
/// for e in &a {
/// println!("{}", e); // prints 1, then 2, then 3, then 4
/// }
/// println!("{}", b.len()); // prints 0
/// list1.append(&mut list2);
///
/// let mut iter = list1.iter();
/// assert_eq!(iter.next(), Some(&'a'));
/// assert_eq!(iter.next(), Some(&'b'));
/// assert_eq!(iter.next(), Some(&'c'));
/// assert!(iter.next().is_none());
///
/// assert!(list2.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn append(&mut self, other: &mut Self) {
Expand Down
11 changes: 11 additions & 0 deletions src/libcollectionstest/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ fn test_push_str() {
assert_eq!(&s[0..], "abcประเทศไทย中华Việt Nam");
}

#[test]
fn test_add_assign() {
let mut s = String::new();
s += "";
assert_eq!(s.as_str(), "");
s += "abc";
assert_eq!(s.as_str(), "abc");
s += "ประเทศไทย中华Việt Nam";
assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam");
}

#[test]
fn test_push() {
let mut data = String::from("ประเทศไทย中");
Expand Down
84 changes: 84 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,31 @@ macro_rules! int_impl {
if b {None} else {Some(a)}
}

/// Checked absolute value. Computes `self.abs()`, returning `None` if
/// `self == MIN`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # #![feature(no_panic_abs)]
///
/// use std::i32;
///
/// assert_eq!((-5i32).checked_abs(), Some(5));
/// assert_eq!(i32::MIN.checked_abs(), None);
/// ```
#[unstable(feature = "no_panic_abs", issue = "35057")]
#[inline]
pub fn checked_abs(self) -> Option<Self> {
if self.is_negative() {
self.checked_neg()
} else {
Some(self)
}
}

/// Saturating integer addition. Computes `self + other`, saturating at
/// the numeric bounds instead of overflowing.
///
Expand Down Expand Up @@ -863,6 +888,36 @@ macro_rules! int_impl {
self.overflowing_shr(rhs).0
}

/// Wrapping (modular) absolute value. Computes `self.abs()`,
/// wrapping around at the boundary of the type.
///
/// The only case where such wrapping can occur is when one takes
/// the absolute value of the negative minimal value for the type
/// this is a positive value that is too large to represent in the
/// type. In such a case, this function returns `MIN` itself.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # #![feature(no_panic_abs)]
///
/// assert_eq!(100i8.wrapping_abs(), 100);
/// assert_eq!((-100i8).wrapping_abs(), 100);
/// assert_eq!((-128i8).wrapping_abs(), -128);
/// assert_eq!((-128i8).wrapping_abs() as u8, 128);
/// ```
#[unstable(feature = "no_panic_abs", issue = "35057")]
#[inline(always)]
pub fn wrapping_abs(self) -> Self {
if self.is_negative() {
self.wrapping_neg()
} else {
self
}
}

/// Calculates `self` + `rhs`
///
/// Returns a tuple of the addition along with a boolean indicating
Expand Down Expand Up @@ -1071,6 +1126,35 @@ macro_rules! int_impl {
(self >> (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}

/// Computes the absolute value of `self`.
///
/// Returns a tuple of the absolute version of self along with a
/// boolean indicating whether an overflow happened. If self is the
/// minimum value (e.g. i32::MIN for values of type i32), then the
/// minimum value will be returned again and true will be returned for
/// an overflow happening.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # #![feature(no_panic_abs)]
///
/// assert_eq!(10i8.overflowing_abs(), (10,false));
/// assert_eq!((-10i8).overflowing_abs(), (10,false));
/// assert_eq!((-128i8).overflowing_abs(), (-128,true));
/// ```
#[unstable(feature = "no_panic_abs", issue = "35057")]
#[inline]
pub fn overflowing_abs(self) -> (Self, bool) {
if self.is_negative() {
self.overflowing_neg()
} else {
(self, false)
}
}

/// Raises self to the power of `exp`, using exponentiation by squaring.
///
/// # Examples
Expand Down
Loading