diff --git a/src/libcore/time.rs b/src/libcore/time.rs old mode 100755 new mode 100644 diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8de415e8aed5cc25ec6577e59f8a461034076098..b95449d11eac372900526e1d758506f47402e6aa 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -36,7 +36,7 @@ impl DefaultResizePolicy { #[inline] - fn new() -> DefaultResizePolicy { + const fn new() -> DefaultResizePolicy { DefaultResizePolicy } @@ -69,7 +69,7 @@ fn raw_capacity(&self, len: usize) -> usize { /// The capacity of the given raw capacity. #[inline] - fn capacity(&self, raw_cap: usize) -> usize { + const fn capacity(&self, raw_cap: usize) -> usize { // This doesn't have to be checked for overflow since allocation size // in bytes will overflow earlier than multiplication by 10. // @@ -3013,7 +3013,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> { /// assert_eq!(map.entry("poneyland").key(), &"poneyland"); /// ``` #[stable(feature = "map_entry_keys", since = "1.10.0")] - pub fn key(&self) -> &K { + pub const fn key(&self) -> &K { &self.key } diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 547f97cc8acee1bccb45bae7ef94922087be66a3..0df20395b012b36669da69fe570f971b09a4f163 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -247,7 +247,7 @@ unsafe fn hash_pair(&self) -> (*mut HashUint, *mut (K, V)) { // Buckets hold references to the table. impl FullBucket { /// Borrow a reference to the table. - pub fn table(&self) -> &M { + pub const fn table(&self) -> &M { &self.table } /// Borrow a mutable reference to the table. @@ -259,18 +259,18 @@ pub fn into_table(self) -> M { self.table } /// Get the raw index. - pub fn index(&self) -> usize { + pub const fn index(&self) -> usize { self.raw.idx } /// Get the raw bucket. - pub fn raw(&self) -> RawBucket { + pub const fn raw(&self) -> RawBucket { self.raw } } impl EmptyBucket { /// Borrow a reference to the table. - pub fn table(&self) -> &M { + pub const fn table(&self) -> &M { &self.table } /// Borrow a mutable reference to the table. @@ -281,7 +281,7 @@ pub fn table_mut(&mut self) -> &mut M { impl Bucket { /// Get the raw index. - pub fn index(&self) -> usize { + pub const fn index(&self) -> usize { self.raw.idx } /// get the table. @@ -772,7 +772,7 @@ pub fn capacity(&self) -> usize { /// The number of elements ever `put` in the hashtable, minus the number /// of elements ever `take`n. - pub fn size(&self) -> usize { + pub const fn size(&self) -> usize { self.size } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index dfec13cd2ec007e74d4d0a1f9447b602890b1d34..feff65bff3f2acbed7b75be49cbbb422425569aa 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -265,12 +265,12 @@ enum FromBytesWithNulErrorKind { } impl FromBytesWithNulError { - fn interior_nul(pos: usize) -> FromBytesWithNulError { + const fn interior_nul(pos: usize) -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::InteriorNul(pos), } } - fn not_nul_terminated() -> FromBytesWithNulError { + const fn not_nul_terminated() -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::NotNulTerminated, } @@ -833,7 +833,7 @@ impl NulError { /// assert_eq!(nul_error.nul_position(), 7); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn nul_position(&self) -> usize { self.0 } + pub const fn nul_position(&self) -> usize { self.0 } /// Consumes this error, returning the underlying vector of bytes which /// generated the error in the first place. @@ -909,7 +909,7 @@ pub fn into_cstring(self) -> CString { /// Access the underlying UTF-8 error that was the cause of this error. #[stable(feature = "cstring_into", since = "1.7.0")] - pub fn utf8_error(&self) -> Utf8Error { + pub const fn utf8_error(&self) -> Utf8Error { self.error } } @@ -1091,7 +1091,7 @@ pub fn from_bytes_with_nul(bytes: &[u8]) /// [`CString`]: struct.CString.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn as_ptr(&self) -> *const c_char { + pub const fn as_ptr(&self) -> *const c_char { self.inner.as_ptr() } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index e26e6d391f84d3f12bee12a774746e5506811d09..bde9c57c57cc547e461b9c7921630bca69af76b6 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -633,7 +633,7 @@ impl IntoInnerError { /// }; /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn error(&self) -> &Error { &self.1 } + pub const fn error(&self) -> &Error { &self.1 } /// Returns the buffered writer instance which generated the error. /// diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 14f20151dca861c9ef6e3518392fdac9b4e49ce1..05bee19c93f545ae179fa30274338ad5ce9dcbce 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -104,7 +104,7 @@ impl Cursor { /// # force_inference(&buff); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(inner: T) -> Cursor { + pub const fn new(inner: T) -> Cursor { Cursor { pos: 0, inner: inner } } @@ -138,7 +138,7 @@ pub fn into_inner(self) -> T { self.inner } /// let reference = buff.get_ref(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn get_ref(&self) -> &T { &self.inner } + pub const fn get_ref(&self) -> &T { &self.inner } /// Gets a mutable reference to the underlying value in this cursor. /// @@ -179,7 +179,7 @@ pub fn get_mut(&mut self) -> &mut T { &mut self.inner } /// assert_eq!(buff.position(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn position(&self) -> u64 { self.pos } + pub const fn position(&self) -> u64 { self.pos } /// Sets the position of this cursor. /// diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index e263db24fc2c80cf9b429c2d4e150e6952bbc3f1..4c3117260feebe2456346cb827fa301cbb72164a 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -885,7 +885,7 @@ impl Initializer { /// Returns a new `Initializer` which will zero out buffers. #[unstable(feature = "read_initializer", issue = "42788")] #[inline] - pub fn zeroing() -> Initializer { + pub const fn zeroing() -> Initializer { Initializer(true) } @@ -906,7 +906,7 @@ pub unsafe fn nop() -> Initializer { /// Indicates if a buffer should be initialized. #[unstable(feature = "read_initializer", issue = "42788")] #[inline] - pub fn should_initialize(&self) -> bool { + pub const fn should_initialize(&self) -> bool { self.0 } @@ -1653,7 +1653,7 @@ pub fn into_inner(self) -> (T, U) { /// } /// ``` #[stable(feature = "more_io_inner_methods", since = "1.20.0")] - pub fn get_ref(&self) -> (&T, &U) { + pub const fn get_ref(&self) -> (&T, &U) { (&self.first, &self.second) } @@ -1780,7 +1780,7 @@ impl Take { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn limit(&self) -> u64 { self.limit } + pub const fn limit(&self) -> u64 { self.limit } /// Sets the number of bytes that can be read before this instance will /// return EOF. This is the same as constructing a new `Take` instance, so @@ -1856,7 +1856,7 @@ pub fn into_inner(self) -> T { /// } /// ``` #[stable(feature = "more_io_inner_methods", since = "1.20.0")] - pub fn get_ref(&self) -> &T { + pub const fn get_ref(&self) -> &T { &self.inner } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 12995d08683450175af2c3fe2b5b1377c70ab320..d0db4cfc704bea757c7b5492dd99a9c9639a3724 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -99,7 +99,7 @@ pub struct Empty { _priv: () } /// assert!(buffer.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn empty() -> Empty { Empty { _priv: () } } +pub const fn empty() -> Empty { Empty { _priv: () } } #[stable(feature = "rust1", since = "1.0.0")] impl Read for Empty { @@ -199,7 +199,7 @@ pub struct Sink { _priv: () } /// assert_eq!(num_bytes, 5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn sink() -> Sink { Sink { _priv: () } } +pub const fn sink() -> Sink { Sink { _priv: () } } #[stable(feature = "rust1", since = "1.0.0")] impl Write for Sink { diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index ff35325ab4fdaaacded38db1c1cb484410f67926..fc2e8104782638156e05b23a44f51a77873603b0 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -475,7 +475,7 @@ pub fn set_port(&mut self, new_port: u16) { /// assert_eq!(socket.flowinfo(), 10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn flowinfo(&self) -> u32 { + pub const fn flowinfo(&self) -> u32 { self.inner.sin6_flowinfo } @@ -515,7 +515,7 @@ pub fn set_flowinfo(&mut self, new_flowinfo: u32) { /// assert_eq!(socket.scope_id(), 78); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn scope_id(&self) -> u32 { + pub const fn scope_id(&self) -> u32 { self.inner.sin6_scope_id } diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index d45a66ef6653257455594c7239fe002bc91acbb9..c5106c9abb9b4588c20884b6bbc02e435af44e20 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -402,7 +402,7 @@ pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { /// assert_eq!(addr.octets(), [127, 0, 0, 1]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn octets(&self) -> [u8; 4] { + pub fn octets(&self) -> [u8; 4] { let bits = u32::from_be(self.inner.s_addr); [(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8] } @@ -424,7 +424,7 @@ pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false); /// ``` #[stable(feature = "ip_shared", since = "1.12.0")] - pub fn is_unspecified(&self) -> bool { + pub const fn is_unspecified(&self) -> bool { self.inner.s_addr == 0 } @@ -862,7 +862,6 @@ impl Ipv6Addr { /// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ip")] pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { Ipv6Addr { @@ -1224,7 +1223,7 @@ pub fn to_ipv4(&self) -> Option { /// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); /// ``` #[stable(feature = "ipv6_to_octets", since = "1.12.0")] - pub fn octets(&self) -> [u8; 16] { + pub const fn octets(&self) -> [u8; 16] { self.inner.s6_addr } } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index a153456370c6f45cbf50c3632b34467d5b3edaf7..71f39ff85e71ae39c28db1b17ae21f6cfce2cca0 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -439,7 +439,7 @@ impl<'a> PrefixComponent<'a> { /// /// [`Prefix`]: enum.Prefix.html #[stable(feature = "rust1", since = "1.0.0")] - pub fn kind(&self) -> Prefix<'a> { + pub const fn kind(&self) -> Prefix<'a> { self.parsed } @@ -447,7 +447,7 @@ pub fn kind(&self) -> Prefix<'a> { /// /// [`OsStr`]: ../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] - pub fn as_os_str(&self) -> &'a OsStr { + pub const fn as_os_str(&self) -> &'a OsStr { self.raw } } @@ -1918,7 +1918,7 @@ pub fn parent(&self) -> Option<&Path> { /// [`None`]: ../../std/option/enum.Option.html#variant.None /// [`parent`]: struct.Path.html#method.parent #[stable(feature = "path_ancestors", since = "1.28.0")] - pub fn ancestors(&self) -> Ancestors { + pub const fn ancestors(&self) -> Ancestors { Ancestors { next: Some(&self), } @@ -2267,7 +2267,7 @@ pub fn iter(&self) -> Iter { /// println!("{}", path.display()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn display(&self) -> Display { + pub const fn display(&self) -> Display { Display { path: self } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index a9219f75362db4dddb74cb879b98b305d05d5731..d5047ef6ad728498cf295e413a5f3cfbd8f2f060 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -926,7 +926,7 @@ impl Stdio { /// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n"); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } + pub const fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } /// The child inherits from the corresponding parent descriptor. /// @@ -961,7 +961,7 @@ pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } /// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout)); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } + pub const fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } /// This stream will be ignored. This is the equivalent of attaching the /// stream to `/dev/null` @@ -998,7 +998,7 @@ pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } /// // Ignores any piped-in input /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn null() -> Stdio { Stdio(imp::Stdio::Null) } + pub const fn null() -> Stdio { Stdio(imp::Stdio::Null) } } impl FromInner for Stdio { diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 3014283da5b271edc067f78d4c0df488a36e617a..1c6cc9cb361e5a866f6ccd4387b6d36842243a11 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -72,7 +72,7 @@ impl WaitTimeoutResult { /// } /// ``` #[stable(feature = "wait_timeout", since = "1.5.0")] - pub fn timed_out(&self) -> bool { + pub const fn timed_out(&self) -> bool { self.0 } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 059ced4f56efda5f3fea5e7ebcc63681d8d4f698..2a2e5c030b32fe80d7fc017418714a1f97825b9d 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -785,7 +785,7 @@ pub fn sync_channel(bound: usize) -> (SyncSender, Receiver) { //////////////////////////////////////////////////////////////////////////////// impl Sender { - fn new(inner: Flavor) -> Sender { + const fn new(inner: Flavor) -> Sender { Sender { inner: UnsafeCell::new(inner), } @@ -1469,7 +1469,7 @@ pub fn recv_deadline(&self, deadline: Instant) -> Result { /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn iter(&self) -> Iter { + pub const fn iter(&self) -> Iter { Iter { rx: self } } @@ -1512,7 +1512,7 @@ pub fn iter(&self) -> Iter { /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "receiver_try_iter", since = "1.15.0")] - pub fn try_iter(&self) -> TryIter { + pub const fn try_iter(&self) -> TryIter { TryIter { rx: self } } diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index b8e50c9297b647c852eed8d5d4ed5e803c575047..273644cb902db6e70897eea8edd66cb06a886214 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -89,7 +89,7 @@ enum MyUpgrade { } impl Packet { - pub fn new() -> Packet { + pub const fn new() -> Packet { Packet { data: UnsafeCell::new(None), upgrade: UnsafeCell::new(NothingSent), diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index cf9698cb2a9712b6a2439314503c0aef40e63ffd..4dd37ec387884389f12a6f7da07712049e9327fb 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -517,7 +517,7 @@ impl OnceState { /// assert!(!state.poisoned()); /// }); #[unstable(feature = "once_poison", issue = "33577")] - pub fn poisoned(&self) -> bool { + pub const fn poisoned(&self) -> bool { self.poisoned } } diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs index c6d531c7a1ac59cbb3b641ea96fc645a3b2f6d2d..dc9edb306de0d74b942bfcf67b8da8f7cf87dd67 100644 --- a/src/libstd/sys_common/mutex.rs +++ b/src/libstd/sys_common/mutex.rs @@ -80,7 +80,7 @@ pub unsafe fn destroy(&self) { self.0.destroy() } } // not meant to be exported to the outside world, just the containing module -pub fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } +pub const fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } #[must_use] /// A simple RAII utility for the above Mutex without the poisoning semantics. diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index d09a233ed896f296529bbf597613a28285909639..f58c26ef4280a897529909a16cc7cb7b276eabc5 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -199,7 +199,7 @@ pub fn connect_timeout(addr: &SocketAddr, timeout: Duration) -> io::Result &Socket { &self.inner } + pub const fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -339,7 +339,7 @@ pub fn bind(addr: &SocketAddr) -> io::Result { Ok(TcpListener { inner: sock }) } - pub fn socket(&self) -> &Socket { &self.inner } + pub const fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -427,7 +427,7 @@ pub fn bind(addr: &SocketAddr) -> io::Result { Ok(UdpSocket { inner: sock }) } - pub fn socket(&self) -> &Socket { &self.inner } + pub const fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 19ce932aa1233f6985158b03ef75fa05d5d641eb..5f6747a1224aeca2fcd0f3c1ded6644ea7de563c 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -85,13 +85,13 @@ pub fn from_u32(value: u32) -> Option { /// /// Since all Unicode scalar values are code points, this always succeeds. #[inline] - pub fn from_char(value: char) -> CodePoint { + pub const fn from_char(value: char) -> CodePoint { CodePoint { value: value as u32 } } /// Returns the numeric value of the code point. #[inline] - pub fn to_u32(&self) -> u32 { + pub const fn to_u32(&self) -> u32 { self.value } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index a57b8dc7237678489baf2476a7350cc6f26e7b09..3a3d2450014c1686758e3788c5833d5691ef437a 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -286,7 +286,7 @@ impl Builder { /// handler.join().unwrap(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new() -> Builder { + pub const fn new() -> Builder { Builder { name: None, stack_size: None, @@ -1391,7 +1391,7 @@ impl JoinHandle { /// println!("thread id: {:?}", thread.id()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn thread(&self) -> &Thread { + pub const fn thread(&self) -> &Thread { &self.0.thread } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 90ab349159915cad86c8a10d386558cc3a729cce..a9344941f4218d34f466b27559a9582b9dffbfa0 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -449,7 +449,7 @@ impl SystemTimeError { /// } /// ``` #[stable(feature = "time2", since = "1.8.0")] - pub fn duration(&self) -> Duration { + pub const fn duration(&self) -> Duration { self.0 } }