Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
constify parts of liballoc.
  • Loading branch information
Centril committed Nov 10, 2018
commit 061d345c1657a86a9d94e90f916a0be8c966d062
2 changes: 1 addition & 1 deletion src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl<'a, T> Hole<'a, T> {
}

#[inline]
fn pos(&self) -> usize {
const fn pos(&self) -> usize {
self.pos
}

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,7 +2074,7 @@ impl<K, V> BTreeMap<K, V> {
/// assert_eq!(a.len(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.length
}

Expand All @@ -2093,7 +2093,7 @@ impl<K, V> BTreeMap<K, V> {
/// assert!(!a.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {

/// Returns the height of this node in the whole tree. Zero height denotes the
/// leaf level.
pub fn height(&self) -> usize {
pub const fn height(&self) -> usize {
self.height
}

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ impl<T> BTreeSet<T> {
/// assert_eq!(v.len(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.map.len()
}

Expand All @@ -747,7 +747,7 @@ impl<T> BTreeSet<T> {
/// assert!(!v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
}

impl<T> Node<T> {
fn new(element: T) -> Self {
const fn new(element: T) -> Self {
Node {
next: None,
prev: None,
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<T> LinkedList<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> Self {
pub const fn new() -> Self {
LinkedList {
head: None,
tail: None,
Expand Down Expand Up @@ -341,7 +341,7 @@ impl<T> LinkedList<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
pub const fn iter(&self) -> Iter<T> {
Iter {
head: self.head,
tail: self.tail,
Expand Down Expand Up @@ -401,8 +401,8 @@ impl<T> LinkedList<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.head.is_none()
pub const fn is_empty(&self) -> bool {
self.len() == 0
}

/// Returns the length of the `LinkedList`.
Expand All @@ -427,7 +427,7 @@ impl<T> LinkedList<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.len
}

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ impl<T> VecDeque<T> {
/// assert!(!v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.tail == self.head
}

Expand Down Expand Up @@ -1275,7 +1275,7 @@ impl<T> VecDeque<T> {
}

#[inline]
fn is_contiguous(&self) -> bool {
const fn is_contiguous(&self) -> bool {
self.tail <= self.head
}

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<T, A: Alloc> RawVec<T, A> {
/// Gets a raw pointer to the start of the allocation. Note that this is
/// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must
/// be careful.
pub fn ptr(&self) -> *mut T {
pub const fn ptr(&self) -> *mut T {
self.ptr.as_ptr()
}

Expand All @@ -221,7 +221,7 @@ impl<T, A: Alloc> RawVec<T, A> {
}

/// Returns a shared reference to the allocator backing this RawVec.
pub fn alloc(&self) -> &A {
pub const fn alloc(&self) -> &A {
&self.a
}

Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ impl String {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.vec.len()
}

Expand All @@ -1395,7 +1395,7 @@ impl String {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len() == 0
}

Expand Down Expand Up @@ -1662,7 +1662,7 @@ impl FromUtf8Error {
/// assert_eq!(1, error.valid_up_to());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn utf8_error(&self) -> Utf8Error {
pub const fn utf8_error(&self) -> Utf8Error {
self.error
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ impl<T> Vec<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.len
}

Expand All @@ -1181,7 +1181,7 @@ impl<T> Vec<T> {
/// assert!(!v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len() == 0
}

Expand Down