Skip to content

Commit 061d345

Browse files
committed
constify parts of liballoc.
1 parent 5b89877 commit 061d345

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

src/liballoc/collections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ impl<'a, T> Hole<'a, T> {
884884
}
885885

886886
#[inline]
887-
fn pos(&self) -> usize {
887+
const fn pos(&self) -> usize {
888888
self.pos
889889
}
890890

src/liballoc/collections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ impl<K, V> BTreeMap<K, V> {
20742074
/// assert_eq!(a.len(), 1);
20752075
/// ```
20762076
#[stable(feature = "rust1", since = "1.0.0")]
2077-
pub fn len(&self) -> usize {
2077+
pub const fn len(&self) -> usize {
20782078
self.length
20792079
}
20802080

@@ -2093,7 +2093,7 @@ impl<K, V> BTreeMap<K, V> {
20932093
/// assert!(!a.is_empty());
20942094
/// ```
20952095
#[stable(feature = "rust1", since = "1.0.0")]
2096-
pub fn is_empty(&self) -> bool {
2096+
pub const fn is_empty(&self) -> bool {
20972097
self.len() == 0
20982098
}
20992099
}

src/liballoc/collections/btree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
357357

358358
/// Returns the height of this node in the whole tree. Zero height denotes the
359359
/// leaf level.
360-
pub fn height(&self) -> usize {
360+
pub const fn height(&self) -> usize {
361361
self.height
362362
}
363363

src/liballoc/collections/btree/set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ impl<T> BTreeSet<T> {
730730
/// assert_eq!(v.len(), 1);
731731
/// ```
732732
#[stable(feature = "rust1", since = "1.0.0")]
733-
pub fn len(&self) -> usize {
733+
pub const fn len(&self) -> usize {
734734
self.map.len()
735735
}
736736

@@ -747,7 +747,7 @@ impl<T> BTreeSet<T> {
747747
/// assert!(!v.is_empty());
748748
/// ```
749749
#[stable(feature = "rust1", since = "1.0.0")]
750-
pub fn is_empty(&self) -> bool {
750+
pub const fn is_empty(&self) -> bool {
751751
self.len() == 0
752752
}
753753
}

src/liballoc/collections/linked_list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
135135
}
136136

137137
impl<T> Node<T> {
138-
fn new(element: T) -> Self {
138+
const fn new(element: T) -> Self {
139139
Node {
140140
next: None,
141141
prev: None,
@@ -264,7 +264,7 @@ impl<T> LinkedList<T> {
264264
/// ```
265265
#[inline]
266266
#[stable(feature = "rust1", since = "1.0.0")]
267-
pub fn new() -> Self {
267+
pub const fn new() -> Self {
268268
LinkedList {
269269
head: None,
270270
tail: None,
@@ -341,7 +341,7 @@ impl<T> LinkedList<T> {
341341
/// ```
342342
#[inline]
343343
#[stable(feature = "rust1", since = "1.0.0")]
344-
pub fn iter(&self) -> Iter<T> {
344+
pub const fn iter(&self) -> Iter<T> {
345345
Iter {
346346
head: self.head,
347347
tail: self.tail,
@@ -401,8 +401,8 @@ impl<T> LinkedList<T> {
401401
/// ```
402402
#[inline]
403403
#[stable(feature = "rust1", since = "1.0.0")]
404-
pub fn is_empty(&self) -> bool {
405-
self.head.is_none()
404+
pub const fn is_empty(&self) -> bool {
405+
self.len() == 0
406406
}
407407

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

src/liballoc/collections/vec_deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ impl<T> VecDeque<T> {
933933
/// assert!(!v.is_empty());
934934
/// ```
935935
#[stable(feature = "rust1", since = "1.0.0")]
936-
pub fn is_empty(&self) -> bool {
936+
pub const fn is_empty(&self) -> bool {
937937
self.tail == self.head
938938
}
939939

@@ -1275,7 +1275,7 @@ impl<T> VecDeque<T> {
12751275
}
12761276

12771277
#[inline]
1278-
fn is_contiguous(&self) -> bool {
1278+
const fn is_contiguous(&self) -> bool {
12791279
self.tail <= self.head
12801280
}
12811281

src/liballoc/raw_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<T, A: Alloc> RawVec<T, A> {
204204
/// Gets a raw pointer to the start of the allocation. Note that this is
205205
/// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must
206206
/// be careful.
207-
pub fn ptr(&self) -> *mut T {
207+
pub const fn ptr(&self) -> *mut T {
208208
self.ptr.as_ptr()
209209
}
210210

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

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

src/liballoc/string.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ impl String {
13741374
/// ```
13751375
#[inline]
13761376
#[stable(feature = "rust1", since = "1.0.0")]
1377-
pub fn len(&self) -> usize {
1377+
pub const fn len(&self) -> usize {
13781378
self.vec.len()
13791379
}
13801380

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

@@ -1662,7 +1662,7 @@ impl FromUtf8Error {
16621662
/// assert_eq!(1, error.valid_up_to());
16631663
/// ```
16641664
#[stable(feature = "rust1", since = "1.0.0")]
1665-
pub fn utf8_error(&self) -> Utf8Error {
1665+
pub const fn utf8_error(&self) -> Utf8Error {
16661666
self.error
16671667
}
16681668
}

src/liballoc/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ impl<T> Vec<T> {
11651165
/// ```
11661166
#[inline]
11671167
#[stable(feature = "rust1", since = "1.0.0")]
1168-
pub fn len(&self) -> usize {
1168+
pub const fn len(&self) -> usize {
11691169
self.len
11701170
}
11711171

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

0 commit comments

Comments
 (0)