Skip to content

Commit f65b630

Browse files
committed
constify parts of libstd.
1 parent 061d345 commit f65b630

File tree

21 files changed

+52
-53
lines changed

21 files changed

+52
-53
lines changed

src/libcore/time.rs

100755100644
File mode changed.

src/libstd/collections/hash/map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct DefaultResizePolicy;
3636

3737
impl DefaultResizePolicy {
3838
#[inline]
39-
fn new() -> DefaultResizePolicy {
39+
const fn new() -> DefaultResizePolicy {
4040
DefaultResizePolicy
4141
}
4242

@@ -69,7 +69,7 @@ impl DefaultResizePolicy {
6969

7070
/// The capacity of the given raw capacity.
7171
#[inline]
72-
fn capacity(&self, raw_cap: usize) -> usize {
72+
const fn capacity(&self, raw_cap: usize) -> usize {
7373
// This doesn't have to be checked for overflow since allocation size
7474
// in bytes will overflow earlier than multiplication by 10.
7575
//
@@ -3013,7 +3013,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
30133013
/// assert_eq!(map.entry("poneyland").key(), &"poneyland");
30143014
/// ```
30153015
#[stable(feature = "map_entry_keys", since = "1.10.0")]
3016-
pub fn key(&self) -> &K {
3016+
pub const fn key(&self) -> &K {
30173017
&self.key
30183018
}
30193019

src/libstd/collections/hash/table.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<K, V> RawBucket<K, V> {
247247
// Buckets hold references to the table.
248248
impl<K, V, M> FullBucket<K, V, M> {
249249
/// Borrow a reference to the table.
250-
pub fn table(&self) -> &M {
250+
pub const fn table(&self) -> &M {
251251
&self.table
252252
}
253253
/// Borrow a mutable reference to the table.
@@ -259,18 +259,18 @@ impl<K, V, M> FullBucket<K, V, M> {
259259
self.table
260260
}
261261
/// Get the raw index.
262-
pub fn index(&self) -> usize {
262+
pub const fn index(&self) -> usize {
263263
self.raw.idx
264264
}
265265
/// Get the raw bucket.
266-
pub fn raw(&self) -> RawBucket<K, V> {
266+
pub const fn raw(&self) -> RawBucket<K, V> {
267267
self.raw
268268
}
269269
}
270270

271271
impl<K, V, M> EmptyBucket<K, V, M> {
272272
/// Borrow a reference to the table.
273-
pub fn table(&self) -> &M {
273+
pub const fn table(&self) -> &M {
274274
&self.table
275275
}
276276
/// Borrow a mutable reference to the table.
@@ -281,7 +281,7 @@ impl<K, V, M> EmptyBucket<K, V, M> {
281281

282282
impl<K, V, M> Bucket<K, V, M> {
283283
/// Get the raw index.
284-
pub fn index(&self) -> usize {
284+
pub const fn index(&self) -> usize {
285285
self.raw.idx
286286
}
287287
/// get the table.
@@ -772,7 +772,7 @@ impl<K, V> RawTable<K, V> {
772772

773773
/// The number of elements ever `put` in the hashtable, minus the number
774774
/// of elements ever `take`n.
775-
pub fn size(&self) -> usize {
775+
pub const fn size(&self) -> usize {
776776
self.size
777777
}
778778

src/libstd/ffi/c_str.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ enum FromBytesWithNulErrorKind {
265265
}
266266

267267
impl FromBytesWithNulError {
268-
fn interior_nul(pos: usize) -> FromBytesWithNulError {
268+
const fn interior_nul(pos: usize) -> FromBytesWithNulError {
269269
FromBytesWithNulError {
270270
kind: FromBytesWithNulErrorKind::InteriorNul(pos),
271271
}
272272
}
273-
fn not_nul_terminated() -> FromBytesWithNulError {
273+
const fn not_nul_terminated() -> FromBytesWithNulError {
274274
FromBytesWithNulError {
275275
kind: FromBytesWithNulErrorKind::NotNulTerminated,
276276
}
@@ -833,7 +833,7 @@ impl NulError {
833833
/// assert_eq!(nul_error.nul_position(), 7);
834834
/// ```
835835
#[stable(feature = "rust1", since = "1.0.0")]
836-
pub fn nul_position(&self) -> usize { self.0 }
836+
pub const fn nul_position(&self) -> usize { self.0 }
837837

838838
/// Consumes this error, returning the underlying vector of bytes which
839839
/// generated the error in the first place.
@@ -909,7 +909,7 @@ impl IntoStringError {
909909

910910
/// Access the underlying UTF-8 error that was the cause of this error.
911911
#[stable(feature = "cstring_into", since = "1.7.0")]
912-
pub fn utf8_error(&self) -> Utf8Error {
912+
pub const fn utf8_error(&self) -> Utf8Error {
913913
self.error
914914
}
915915
}
@@ -1091,7 +1091,7 @@ impl CStr {
10911091
/// [`CString`]: struct.CString.html
10921092
#[inline]
10931093
#[stable(feature = "rust1", since = "1.0.0")]
1094-
pub fn as_ptr(&self) -> *const c_char {
1094+
pub const fn as_ptr(&self) -> *const c_char {
10951095
self.inner.as_ptr()
10961096
}
10971097

src/libstd/io/buffered.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ impl<W> IntoInnerError<W> {
633633
/// };
634634
/// ```
635635
#[stable(feature = "rust1", since = "1.0.0")]
636-
pub fn error(&self) -> &Error { &self.1 }
636+
pub const fn error(&self) -> &Error { &self.1 }
637637

638638
/// Returns the buffered writer instance which generated the error.
639639
///

src/libstd/io/cursor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<T> Cursor<T> {
104104
/// # force_inference(&buff);
105105
/// ```
106106
#[stable(feature = "rust1", since = "1.0.0")]
107-
pub fn new(inner: T) -> Cursor<T> {
107+
pub const fn new(inner: T) -> Cursor<T> {
108108
Cursor { pos: 0, inner: inner }
109109
}
110110

@@ -138,7 +138,7 @@ impl<T> Cursor<T> {
138138
/// let reference = buff.get_ref();
139139
/// ```
140140
#[stable(feature = "rust1", since = "1.0.0")]
141-
pub fn get_ref(&self) -> &T { &self.inner }
141+
pub const fn get_ref(&self) -> &T { &self.inner }
142142

143143
/// Gets a mutable reference to the underlying value in this cursor.
144144
///
@@ -179,7 +179,7 @@ impl<T> Cursor<T> {
179179
/// assert_eq!(buff.position(), 1);
180180
/// ```
181181
#[stable(feature = "rust1", since = "1.0.0")]
182-
pub fn position(&self) -> u64 { self.pos }
182+
pub const fn position(&self) -> u64 { self.pos }
183183

184184
/// Sets the position of this cursor.
185185
///

src/libstd/io/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ impl Initializer {
885885
/// Returns a new `Initializer` which will zero out buffers.
886886
#[unstable(feature = "read_initializer", issue = "42788")]
887887
#[inline]
888-
pub fn zeroing() -> Initializer {
888+
pub const fn zeroing() -> Initializer {
889889
Initializer(true)
890890
}
891891

@@ -906,7 +906,7 @@ impl Initializer {
906906
/// Indicates if a buffer should be initialized.
907907
#[unstable(feature = "read_initializer", issue = "42788")]
908908
#[inline]
909-
pub fn should_initialize(&self) -> bool {
909+
pub const fn should_initialize(&self) -> bool {
910910
self.0
911911
}
912912

@@ -1653,7 +1653,7 @@ impl<T, U> Chain<T, U> {
16531653
/// }
16541654
/// ```
16551655
#[stable(feature = "more_io_inner_methods", since = "1.20.0")]
1656-
pub fn get_ref(&self) -> (&T, &U) {
1656+
pub const fn get_ref(&self) -> (&T, &U) {
16571657
(&self.first, &self.second)
16581658
}
16591659

@@ -1780,7 +1780,7 @@ impl<T> Take<T> {
17801780
/// }
17811781
/// ```
17821782
#[stable(feature = "rust1", since = "1.0.0")]
1783-
pub fn limit(&self) -> u64 { self.limit }
1783+
pub const fn limit(&self) -> u64 { self.limit }
17841784

17851785
/// Sets the number of bytes that can be read before this instance will
17861786
/// return EOF. This is the same as constructing a new `Take` instance, so
@@ -1856,7 +1856,7 @@ impl<T> Take<T> {
18561856
/// }
18571857
/// ```
18581858
#[stable(feature = "more_io_inner_methods", since = "1.20.0")]
1859-
pub fn get_ref(&self) -> &T {
1859+
pub const fn get_ref(&self) -> &T {
18601860
&self.inner
18611861
}
18621862

src/libstd/io/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub struct Empty { _priv: () }
9999
/// assert!(buffer.is_empty());
100100
/// ```
101101
#[stable(feature = "rust1", since = "1.0.0")]
102-
pub fn empty() -> Empty { Empty { _priv: () } }
102+
pub const fn empty() -> Empty { Empty { _priv: () } }
103103

104104
#[stable(feature = "rust1", since = "1.0.0")]
105105
impl Read for Empty {
@@ -199,7 +199,7 @@ pub struct Sink { _priv: () }
199199
/// assert_eq!(num_bytes, 5);
200200
/// ```
201201
#[stable(feature = "rust1", since = "1.0.0")]
202-
pub fn sink() -> Sink { Sink { _priv: () } }
202+
pub const fn sink() -> Sink { Sink { _priv: () } }
203203

204204
#[stable(feature = "rust1", since = "1.0.0")]
205205
impl Write for Sink {

src/libstd/net/addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl SocketAddrV6 {
475475
/// assert_eq!(socket.flowinfo(), 10);
476476
/// ```
477477
#[stable(feature = "rust1", since = "1.0.0")]
478-
pub fn flowinfo(&self) -> u32 {
478+
pub const fn flowinfo(&self) -> u32 {
479479
self.inner.sin6_flowinfo
480480
}
481481

@@ -515,7 +515,7 @@ impl SocketAddrV6 {
515515
/// assert_eq!(socket.scope_id(), 78);
516516
/// ```
517517
#[stable(feature = "rust1", since = "1.0.0")]
518-
pub fn scope_id(&self) -> u32 {
518+
pub const fn scope_id(&self) -> u32 {
519519
self.inner.sin6_scope_id
520520
}
521521

src/libstd/net/ip.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl Ipv4Addr {
402402
/// assert_eq!(addr.octets(), [127, 0, 0, 1]);
403403
/// ```
404404
#[stable(feature = "rust1", since = "1.0.0")]
405-
pub fn octets(&self) -> [u8; 4] {
405+
pub fn octets(&self) -> [u8; 4] {
406406
let bits = u32::from_be(self.inner.s_addr);
407407
[(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8]
408408
}
@@ -424,7 +424,7 @@ impl Ipv4Addr {
424424
/// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false);
425425
/// ```
426426
#[stable(feature = "ip_shared", since = "1.12.0")]
427-
pub fn is_unspecified(&self) -> bool {
427+
pub const fn is_unspecified(&self) -> bool {
428428
self.inner.s_addr == 0
429429
}
430430

@@ -862,7 +862,6 @@ impl Ipv6Addr {
862862
/// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff);
863863
/// ```
864864
#[stable(feature = "rust1", since = "1.0.0")]
865-
#[rustc_const_unstable(feature = "const_ip")]
866865
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16,
867866
g: u16, h: u16) -> Ipv6Addr {
868867
Ipv6Addr {
@@ -1224,7 +1223,7 @@ impl Ipv6Addr {
12241223
/// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
12251224
/// ```
12261225
#[stable(feature = "ipv6_to_octets", since = "1.12.0")]
1227-
pub fn octets(&self) -> [u8; 16] {
1226+
pub const fn octets(&self) -> [u8; 16] {
12281227
self.inner.s6_addr
12291228
}
12301229
}

0 commit comments

Comments
 (0)