From 81d1feb9804f66034df4f218cc8fb0209c7450a7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Sep 2014 10:47:05 -0700 Subject: [PATCH] Remove #[allow(deprecated)] from libstd --- src/libstd/ascii.rs | 19 ++++++++--------- src/libstd/collections/hashmap/map.rs | 3 ++- src/libstd/collections/hashmap/table.rs | 4 ++-- src/libstd/failure.rs | 4 ++-- src/libstd/io/buffered.rs | 10 ++++----- src/libstd/io/extensions.rs | 28 ++++++++++++------------- src/libstd/io/net/ip.rs | 16 ++++++++++---- src/libstd/io/tempfile.rs | 2 +- src/libstd/lib.rs | 1 - src/libstd/os.rs | 9 ++++---- src/libstd/path/posix.rs | 4 ++-- src/libstd/path/windows.rs | 14 ++++++------- src/libstd/sync/task_pool.rs | 2 +- 13 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index fd8432ded8b..fe2b8a15c73 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -21,8 +21,7 @@ use mem; use option::{Option, Some, None}; use slice::{ImmutableSlice, MutableSlice, Slice}; use str::{Str, StrSlice}; -use str; -use string::String; +use string::{mod, String}; use to_string::IntoStr; use vec::Vec; @@ -113,7 +112,7 @@ impl Ascii { /// Check if the character is a letter or number #[inline] pub fn is_alphanumeric(&self) -> bool { - self.is_alpha() || self.is_digit() + self.is_alphabetic() || self.is_digit() } /// Check if the character is a space or horizontal tab @@ -169,7 +168,7 @@ impl Ascii { /// Checks if the character is punctuation #[inline] pub fn is_punctuation(&self) -> bool { - self.is_graph() && !self.is_alnum() + self.is_graph() && !self.is_alphanumeric() } /// Checks if the character is a valid hex digit @@ -338,12 +337,12 @@ impl<'a> AsciiStr for &'a [Ascii] { #[inline] fn to_lower(&self) -> Vec { - self.iter().map(|a| a.to_lower()).collect() + self.iter().map(|a| a.to_lowercase()).collect() } #[inline] fn to_upper(&self) -> Vec { - self.iter().map(|a| a.to_upper()).collect() + self.iter().map(|a| a.to_uppercase()).collect() } #[inline] @@ -410,13 +409,13 @@ impl<'a> AsciiExt for &'a str { #[inline] fn to_ascii_upper(&self) -> String { // Vec::to_ascii_upper() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.as_bytes().to_ascii_upper()) } + unsafe { string::raw::from_utf8(self.as_bytes().to_ascii_upper()) } } #[inline] fn to_ascii_lower(&self) -> String { // Vec::to_ascii_lower() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.as_bytes().to_ascii_lower()) } + unsafe { string::raw::from_utf8(self.as_bytes().to_ascii_lower()) } } #[inline] @@ -429,13 +428,13 @@ impl OwnedAsciiExt for String { #[inline] fn into_ascii_upper(self) -> String { // Vec::into_ascii_upper() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.into_bytes().into_ascii_upper()) } + unsafe { string::raw::from_utf8(self.into_bytes().into_ascii_upper()) } } #[inline] fn into_ascii_lower(self) -> String { // Vec::into_ascii_lower() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.into_bytes().into_ascii_lower()) } + unsafe { string::raw::from_utf8(self.into_bytes().into_ascii_lower()) } } } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index e8c5eecc6f2..b0604e13163 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -1288,7 +1288,7 @@ impl, V: Clone, S, H: Hasher> HashMap { /// let s: String = map.get_copy(&1); /// ``` pub fn get_copy(&self, k: &K) -> V { - (*self.get(k)).clone() + self[*k].clone() } } @@ -1325,6 +1325,7 @@ impl, V, S, H: Hasher + Default> Default for HashMap impl, V, S, H: Hasher> Index for HashMap { #[inline] + #[allow(deprecated)] fn index<'a>(&'a self, index: &K) -> &'a V { self.get(index) } diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index 87a5cc1484a..45ca633b41f 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -846,8 +846,8 @@ impl Clone for RawTable { (full.hash(), k.clone(), v.clone()) }; *new_buckets.raw.hash = h.inspect(); - mem::overwrite(new_buckets.raw.key, k); - mem::overwrite(new_buckets.raw.val, v); + ptr::write(new_buckets.raw.key, k); + ptr::write(new_buckets.raw.val, v); } Empty(..) => { *new_buckets.raw.hash = EMPTY_BUCKET; diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index 8d715de16e6..a7de84184ff 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -38,9 +38,9 @@ impl Writer for Stdio { } pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) { - let msg = match obj.as_ref::<&'static str>() { + let msg = match obj.downcast_ref::<&'static str>() { Some(s) => *s, - None => match obj.as_ref::() { + None => match obj.downcast_ref::() { Some(s) => s.as_slice(), None => "Box", } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a777a372ad1..d9543a06b35 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -162,7 +162,7 @@ impl BufferedWriter { fn flush_buf(&mut self) -> IoResult<()> { if self.pos != 0 { - let ret = self.inner.get_mut_ref().write(self.buf.slice_to(self.pos)); + let ret = self.inner.as_mut().unwrap().write(self.buf.slice_to(self.pos)); self.pos = 0; ret } else { @@ -174,7 +174,7 @@ impl BufferedWriter { /// /// This type does not expose the ability to get a mutable reference to the /// underlying reader because that could possibly corrupt the buffer. - pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.get_ref() } + pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.as_ref().unwrap() } /// Unwraps this `BufferedWriter`, returning the underlying writer. /// @@ -193,7 +193,7 @@ impl Writer for BufferedWriter { } if buf.len() > self.buf.len() { - self.inner.get_mut_ref().write(buf) + self.inner.as_mut().unwrap().write(buf) } else { let dst = self.buf.slice_from_mut(self.pos); slice::bytes::copy_memory(dst, buf); @@ -203,7 +203,7 @@ impl Writer for BufferedWriter { } fn flush(&mut self) -> IoResult<()> { - self.flush_buf().and_then(|()| self.inner.get_mut_ref().flush()) + self.flush_buf().and_then(|()| self.inner.as_mut().unwrap().flush()) } } @@ -273,7 +273,7 @@ impl InternalBufferedWriter { impl Reader for InternalBufferedWriter { fn read(&mut self, buf: &mut [u8]) -> IoResult { - self.get_mut().inner.get_mut_ref().read(buf) + self.get_mut().inner.as_mut().unwrap().read(buf) } } diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index b61e7c6b441..a93f9826fa5 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -16,13 +16,14 @@ // FIXME: Iteration should probably be considered separately use collections::{Collection, MutableSeq}; -use iter::Iterator; -use option::{Option, Some, None}; -use result::{Ok, Err}; -use io; use io::{IoError, IoResult, Reader}; -use slice::{ImmutableSlice, Slice}; +use io; +use iter::Iterator; +use num::Int; +use option::{Option, Some, None}; use ptr::RawPtr; +use result::{Ok, Err}; +use slice::{ImmutableSlice, Slice}; /// An iterator that reads a single byte on each iteration, /// until `.read_byte()` returns `EndOfFile`. @@ -76,16 +77,15 @@ impl<'r, R: Reader> Iterator> for Bytes<'r, R> { /// /// This function returns the value returned by the callback, for convenience. pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { - use mem::{to_le16, to_le32, to_le64}; use mem::transmute; // LLVM fails to properly optimize this when using shifts instead of the to_le* intrinsics assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_le16(n as u16)) }), - 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_le32(n as u32)) }), - 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_le64(n)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_le()) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_le()) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_le()) }), _ => { let mut bytes = vec!(); @@ -116,16 +116,15 @@ pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// /// This function returns the value returned by the callback, for convenience. pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { - use mem::{to_be16, to_be32, to_be64}; use mem::transmute; // LLVM fails to properly optimize this when using shifts instead of the to_be* intrinsics assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_be16(n as u16)) }), - 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_be32(n as u32)) }), - 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_be64(n)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_be()) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_be()) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_be()) }), _ => { let mut bytes = vec!(); let mut i = size; @@ -152,7 +151,6 @@ pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// 32-bit value is parsed. pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { use ptr::{copy_nonoverlapping_memory}; - use mem::from_be64; use slice::MutableSlice; assert!(size <= 8u); @@ -166,7 +164,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { let ptr = data.as_ptr().offset(start as int); let out = buf.as_mut_ptr(); copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size); - from_be64(*(out as *const u64)) + (*(out as *const u64)).to_be() } } diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 1141cd22eeb..6eb7d1c02fb 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -103,7 +103,12 @@ impl<'a> Parser<'a> { // Commit only if parser read till EOF fn read_till_eof(&mut self, cb: |&mut Parser| -> Option) -> Option { - self.read_atomically(|p| cb(p).filtered(|_| p.is_eof())) + self.read_atomically(|p| { + match cb(p) { + Some(x) => if p.is_eof() {Some(x)} else {None}, + None => None, + } + }) } // Return result of first successful parser @@ -152,7 +157,10 @@ impl<'a> Parser<'a> { // Return char and advance iff next char is equal to requested fn read_given_char(&mut self, c: char) -> Option { self.read_atomically(|p| { - p.read_char().filtered(|&next| next == c) + match p.read_char() { + Some(next) if next == c => Some(next), + _ => None, + } }) } @@ -232,8 +240,8 @@ impl<'a> Parser<'a> { fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> IpAddr { assert!(head.len() + tail.len() <= 8); let mut gs = [0u16, ..8]; - gs.copy_from(head); - gs.slice_mut(8 - tail.len(), 8).copy_from(tail); + gs.clone_from_slice(head); + gs.slice_mut(8 - tail.len(), 8).clone_from_slice(tail); Ipv6Addr(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7]) } diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs index 6c9f10e19ae..9d6713b25b7 100644 --- a/src/libstd/io/tempfile.rs +++ b/src/libstd/io/tempfile.rs @@ -79,7 +79,7 @@ impl TempDir { /// Access the wrapped `std::path::Path` to the temporary directory. pub fn path<'a>(&'a self) -> &'a Path { - self.path.get_ref() + self.path.as_ref().unwrap() } /// Close and remove the temporary directory diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 23643542c4f..299e41f7219 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -112,7 +112,6 @@ // Don't link to std. We are std. #![no_std] -#![allow(deprecated)] #![deny(missing_doc)] #![reexport_test_harness_main = "test_main"] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index f1480eb7d45..594a1cd131a 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -276,17 +276,18 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { extern { fn rust_env_pairs() -> *const *const c_char; } - let environ = rust_env_pairs(); + let mut environ = rust_env_pairs(); if environ as uint == 0 { fail!("os::env() failure getting env string from OS: {}", os::last_os_error()); } let mut result = Vec::new(); - ptr::array_each(environ, |e| { + while *environ != 0 as *const _ { let env_pair = - Vec::from_slice(CString::new(e, false).as_bytes_no_nul()); + Vec::from_slice(CString::new(*environ, false).as_bytes_no_nul()); result.push(env_pair); - }); + environ = environ.offset(1); + } result } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index c654d3a668a..7d3c7ea71f6 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -264,7 +264,7 @@ impl GenericPath for Path { #[inline] fn is_absolute(&self) -> bool { - *self.repr.get(0) == SEP_BYTE + self.repr[0] == SEP_BYTE } fn is_ancestor_of(&self, other: &Path) -> bool { @@ -409,7 +409,7 @@ impl Path { /// /a/b/c and a/b/c yield the same set of components. /// A path of "/" yields no components. A path of "." yields one component. pub fn components<'a>(&'a self) -> Components<'a> { - let v = if *self.repr.get(0) == SEP_BYTE { + let v = if self.repr[0] == SEP_BYTE { self.repr.slice_from(1) } else { self.repr.as_slice() }; let mut ret = v.split(is_sep_byte); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index e68c8bdb07d..e703bfae610 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -264,10 +264,10 @@ impl GenericPathUnsafe for Path { let repr = me.repr.as_slice(); match me.prefix { Some(DiskPrefix) => { - repr.as_bytes()[0] == path.as_bytes()[0].to_ascii().to_upper().to_byte() + repr.as_bytes()[0] == path.as_bytes()[0].to_ascii().to_uppercase().to_byte() } Some(VerbatimDiskPrefix) => { - repr.as_bytes()[4] == path.as_bytes()[0].to_ascii().to_upper().to_byte() + repr.as_bytes()[4] == path.as_bytes()[0].to_ascii().to_uppercase().to_byte() } _ => false } @@ -776,9 +776,9 @@ impl Path { let mut s = String::from_str(s.slice_to(len)); unsafe { let v = s.as_mut_vec(); - *v.get_mut(0) = v.get(0) + *v.get_mut(0) = (*v)[0] .to_ascii() - .to_upper() + .to_uppercase() .to_byte(); } if is_abs { @@ -794,7 +794,7 @@ impl Path { let mut s = String::from_str(s.slice_to(len)); unsafe { let v = s.as_mut_vec(); - *v.get_mut(4) = v.get(4).to_ascii().to_upper().to_byte(); + *v.get_mut(4) = (*v)[4].to_ascii().to_uppercase().to_byte(); } Some(s) } @@ -815,12 +815,12 @@ impl Path { let mut s = String::with_capacity(n); match prefix { Some(DiskPrefix) => { - s.push_char(prefix_.as_bytes()[0].to_ascii().to_upper().to_char()); + s.push_char(prefix_.as_bytes()[0].to_ascii().to_uppercase().to_char()); s.push_char(':'); } Some(VerbatimDiskPrefix) => { s.push_str(prefix_.slice_to(4)); - s.push_char(prefix_.as_bytes()[4].to_ascii().to_upper().to_char()); + s.push_char(prefix_.as_bytes()[4].to_ascii().to_uppercase().to_char()); s.push_str(prefix_.slice_from(5)); } Some(UNCPrefix(a,b)) => { diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 23ba582ec0a..a00eeb1f938 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -79,7 +79,7 @@ impl TaskPool { /// Executes the function `f` on a task in the pool. The function /// receives a reference to the local data returned by the `init_fn`. pub fn execute(&mut self, f: proc(&T):Send) { - self.channels.get(self.next_index).send(Execute(f)); + self.channels[self.next_index].send(Execute(f)); self.next_index += 1; if self.next_index == self.channels.len() { self.next_index = 0; } }