Skip to content

Commit df65f59

Browse files
committed
replace deprecated as_slice()
1 parent 6cf3b0b commit df65f59

File tree

24 files changed

+41
-42
lines changed

24 files changed

+41
-42
lines changed

src/liballoc/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use heap::deallocate;
110110
/// let child_numbers = shared_numbers.clone();
111111
///
112112
/// thread::spawn(move || {
113-
/// let local_numbers = child_numbers.as_slice();
113+
/// let local_numbers = &child_numbers[..];
114114
///
115115
/// // Work with the local numbers
116116
/// });

src/libcollections/slice.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ impl<T> [T] {
556556
/// ```rust
557557
/// # #![feature(core)]
558558
/// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
559-
/// let s = s.as_slice();
560559
///
561560
/// let seek = 13;
562561
/// assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Ok(9));
@@ -923,7 +922,6 @@ impl<T> [T] {
923922
/// ```rust
924923
/// # #![feature(core)]
925924
/// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
926-
/// let s = s.as_slice();
927925
///
928926
/// assert_eq!(s.binary_search(&13), Ok(9));
929927
/// assert_eq!(s.binary_search(&4), Err(7));

src/libcollections/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,12 +1473,12 @@ impl str {
14731473
/// let gr1 = "a\u{310}e\u{301}o\u{308}\u{332}".graphemes(true).collect::<Vec<&str>>();
14741474
/// let b: &[_] = &["a\u{310}", "e\u{301}", "o\u{308}\u{332}"];
14751475
///
1476-
/// assert_eq!(gr1.as_slice(), b);
1476+
/// assert_eq!(&gr1[..], b);
14771477
///
14781478
/// let gr2 = "a\r\nb🇷🇺🇸🇹".graphemes(true).collect::<Vec<&str>>();
14791479
/// let b: &[_] = &["a", "\r\n", "b", "🇷🇺🇸🇹"];
14801480
///
1481-
/// assert_eq!(gr2.as_slice(), b);
1481+
/// assert_eq!(&gr2[..], b);
14821482
/// ```
14831483
#[unstable(feature = "unicode",
14841484
reason = "this functionality may only be provided by libunicode")]
@@ -1496,7 +1496,7 @@ impl str {
14961496
/// let gr_inds = "a̐éö̲\r\n".grapheme_indices(true).collect::<Vec<(usize, &str)>>();
14971497
/// let b: &[_] = &[(0, "a̐"), (3, "é"), (6, "ö̲"), (11, "\r\n")];
14981498
///
1499-
/// assert_eq!(gr_inds.as_slice(), b);
1499+
/// assert_eq!(&gr_inds[..], b);
15001500
/// ```
15011501
#[unstable(feature = "unicode",
15021502
reason = "this functionality may only be provided by libunicode")]

src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl String {
9393
/// ```
9494
/// # #![feature(collections, core)]
9595
/// let s = String::from_str("hello");
96-
/// assert_eq!(s.as_slice(), "hello");
96+
/// assert_eq!(&s[..], "hello");
9797
/// ```
9898
#[inline]
9999
#[unstable(feature = "collections",

src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,13 @@ impl<T> Vec<T> {
821821
/// # #![feature(collections, core)]
822822
/// let v = vec![0, 1, 2];
823823
/// let w = v.map_in_place(|i| i + 3);
824-
/// assert_eq!(w.as_slice(), [3, 4, 5].as_slice());
824+
/// assert_eq!(&w[..], &[3, 4, 5]);
825825
///
826826
/// #[derive(PartialEq, Debug)]
827827
/// struct Newtype(u8);
828828
/// let bytes = vec![0x11, 0x22];
829829
/// let newtyped_bytes = bytes.map_in_place(|x| Newtype(x));
830-
/// assert_eq!(newtyped_bytes.as_slice(), [Newtype(0x11), Newtype(0x22)].as_slice());
830+
/// assert_eq!(&newtyped_bytes[..], &[Newtype(0x11), Newtype(0x22)]);
831831
/// ```
832832
#[unstable(feature = "collections",
833833
reason = "API may change to provide stronger guarantees")]

src/libcollections/vec_deque.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ impl<T> VecDeque<T> {
526526
/// buf.push_back(3);
527527
/// buf.push_back(4);
528528
/// let b: &[_] = &[&5, &3, &4];
529-
/// assert_eq!(buf.iter().collect::<Vec<&i32>>().as_slice(), b);
529+
/// let c: Vec<&i32> = buf.iter().collect();
530+
/// assert_eq!(&c[..], b);
530531
/// ```
531532
#[stable(feature = "rust1", since = "1.0.0")]
532533
pub fn iter(&self) -> Iter<T> {

src/libcollectionstest/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ use std::fmt;
1313
#[test]
1414
fn test_format() {
1515
let s = fmt::format(format_args!("Hello, {}!", "world"));
16-
assert_eq!(s.as_slice(), "Hello, world!");
16+
assert_eq!(&s[..], "Hello, world!");
1717
}

src/libcollectionstest/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn test_from_elem() {
5959
// Test on-heap from_elem.
6060
v = vec![20; 6];
6161
{
62-
let v = v.as_slice();
62+
let v = &v[..];
6363
assert_eq!(v[0], 20);
6464
assert_eq!(v[1], 20);
6565
assert_eq!(v[2], 20);

src/libcollectionstest/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,9 @@ fn test_split_strator() {
14701470
fn test_str_default() {
14711471
use std::default::Default;
14721472

1473-
fn t<S: Default + Str>() {
1473+
fn t<S: Default + AsRef<str>>() {
14741474
let s: S = Default::default();
1475-
assert_eq!(s.as_slice(), "");
1475+
assert_eq!(s.as_ref(), "");
14761476
}
14771477

14781478
t::<&str>();

src/libcore/iter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ pub trait Iterator {
624624
/// let a = [1, 2, 3, 4, 5];
625625
/// let mut it = a.iter();
626626
/// assert!(it.any(|x| *x == 3));
627-
/// assert_eq!(it.as_slice(), [4, 5]);
627+
/// assert_eq!(&it[..], [4, 5]);
628628
///
629629
/// ```
630630
#[inline]
@@ -648,7 +648,7 @@ pub trait Iterator {
648648
/// let a = [1, 2, 3, 4, 5];
649649
/// let mut it = a.iter();
650650
/// assert_eq!(it.find(|&x| *x == 3).unwrap(), &3);
651-
/// assert_eq!(it.as_slice(), [4, 5]);
651+
/// assert_eq!(&it[..], [4, 5]);
652652
#[inline]
653653
#[stable(feature = "rust1", since = "1.0.0")]
654654
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
@@ -672,7 +672,7 @@ pub trait Iterator {
672672
/// let a = [1, 2, 3, 4, 5];
673673
/// let mut it = a.iter();
674674
/// assert_eq!(it.position(|x| *x == 3).unwrap(), 2);
675-
/// assert_eq!(it.as_slice(), [4, 5]);
675+
/// assert_eq!(&it[..], [4, 5]);
676676
#[inline]
677677
#[stable(feature = "rust1", since = "1.0.0")]
678678
fn position<P>(&mut self, mut predicate: P) -> Option<usize> where
@@ -702,7 +702,7 @@ pub trait Iterator {
702702
/// let a = [1, 2, 2, 4, 5];
703703
/// let mut it = a.iter();
704704
/// assert_eq!(it.rposition(|x| *x == 2).unwrap(), 2);
705-
/// assert_eq!(it.as_slice(), [1, 2]);
705+
/// assert_eq!(&it[..], [1, 2]);
706706
#[inline]
707707
#[stable(feature = "rust1", since = "1.0.0")]
708708
fn rposition<P>(&mut self, mut predicate: P) -> Option<usize> where

src/libgraphviz/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
//!
8585
//! fn edges(&'a self) -> dot::Edges<'a,Ed> {
8686
//! let &Edges(ref edges) = self;
87-
//! edges.as_slice().into_cow()
87+
//! (&edges[..]).into_cow()
8888
//! }
8989
//!
9090
//! fn source(&self, e: &Ed) -> Nd { let &(s,_) = e; s }

src/librand/chacha.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl Rand for ChaChaRng {
198198
for word in &mut key {
199199
*word = other.gen();
200200
}
201-
SeedableRng::from_seed(key.as_slice())
201+
SeedableRng::from_seed(&key[..])
202202
}
203203
}
204204

src/librand/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub trait Rng : Sized {
153153
///
154154
/// let mut v = [0; 13579];
155155
/// thread_rng().fill_bytes(&mut v);
156-
/// println!("{:?}", v.as_slice());
156+
/// println!("{:?}", v);
157157
/// ```
158158
fn fill_bytes(&mut self, dest: &mut [u8]) {
159159
// this could, in theory, be done by transmuting dest to a
@@ -309,9 +309,9 @@ pub trait Rng : Sized {
309309
/// let mut rng = thread_rng();
310310
/// let mut y = [1, 2, 3];
311311
/// rng.shuffle(&mut y);
312-
/// println!("{:?}", y.as_slice());
312+
/// println!("{:?}", y);
313313
/// rng.shuffle(&mut y);
314-
/// println!("{:?}", y.as_slice());
314+
/// println!("{:?}", y);
315315
/// ```
316316
fn shuffle<T>(&mut self, values: &mut [T]) {
317317
let mut i = values.len();

src/libserialize/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
//! let encoded = json::encode(&object).unwrap();
101101
//!
102102
//! // Deserialize using `json::decode`
103-
//! let decoded: TestStruct = json::decode(encoded.as_slice()).unwrap();
103+
//! let decoded: TestStruct = json::decode(&encoded[..]).unwrap();
104104
//! }
105105
//! ```
106106
//!

src/libstd/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ mod tests {
13271327
check!(fs::copy(&input, &out));
13281328
let mut v = Vec::new();
13291329
check!(check!(File::open(&out)).read_to_end(&mut v));
1330-
assert_eq!(v.as_slice(), b"hello");
1330+
assert_eq!(&v[..], b"hello");
13311331

13321332
assert_eq!(check!(input.metadata()).permissions(),
13331333
check!(out.metadata()).permissions());
@@ -1622,7 +1622,7 @@ mod tests {
16221622
check!(check!(File::create(&tmpdir.join("test"))).write(&bytes));
16231623
let mut v = Vec::new();
16241624
check!(check!(File::open(&tmpdir.join("test"))).read_to_end(&mut v));
1625-
assert!(v == bytes.as_slice());
1625+
assert!(v == &bytes[..]);
16261626
}
16271627

16281628
#[test]

src/libstd/io/cursor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,19 @@ mod tests {
282282
#[test]
283283
fn test_slice_reader() {
284284
let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
285-
let mut reader = &mut in_buf.as_slice();
285+
let mut reader = &mut &in_buf[..];
286286
let mut buf = [];
287287
assert_eq!(reader.read(&mut buf), Ok(0));
288288
let mut buf = [0];
289289
assert_eq!(reader.read(&mut buf), Ok(1));
290290
assert_eq!(reader.len(), 7);
291291
let b: &[_] = &[0];
292-
assert_eq!(buf.as_slice(), b);
292+
assert_eq!(buf, b);
293293
let mut buf = [0; 4];
294294
assert_eq!(reader.read(&mut buf), Ok(4));
295295
assert_eq!(reader.len(), 3);
296296
let b: &[_] = &[1, 2, 3, 4];
297-
assert_eq!(buf.as_slice(), b);
297+
assert_eq!(buf, b);
298298
assert_eq!(reader.read(&mut buf), Ok(3));
299299
let b: &[_] = &[5, 6, 7];
300300
assert_eq!(&buf[..3], b);
@@ -304,7 +304,7 @@ mod tests {
304304
#[test]
305305
fn test_buf_reader() {
306306
let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
307-
let mut reader = Cursor::new(in_buf.as_slice());
307+
let mut reader = Cursor::new(&in_buf[..]);
308308
let mut buf = [];
309309
assert_eq!(reader.read(&mut buf), Ok(0));
310310
assert_eq!(reader.position(), 0);

src/libstd/old_io/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ mod test {
16391639

16401640
check!(File::create(&tmpdir.join("test")).write(&bytes));
16411641
let actual = check!(File::open(&tmpdir.join("test")).read_to_end());
1642-
assert!(actual == bytes.as_slice());
1642+
assert!(actual == &bytes[..]);
16431643
}
16441644

16451645
#[test]

src/libstd/old_io/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ mod test {
744744
wr.write(&[5; 10]).unwrap();
745745
}
746746
}
747-
assert_eq!(buf.as_slice(), [5; 100].as_slice());
747+
assert_eq!(buf.as_ref(), [5; 100].as_ref());
748748
});
749749
}
750750

src/libstd/old_io/net/ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub struct ParseError;
435435
/// let tcp_l = TcpListener::bind("localhost:12345");
436436
///
437437
/// let mut udp_s = UdpSocket::bind(("127.0.0.1", 23451)).unwrap();
438-
/// udp_s.send_to([7, 7, 7].as_slice(), (Ipv4Addr(127, 0, 0, 1), 23451));
438+
/// udp_s.send_to([7, 7, 7].as_ref(), (Ipv4Addr(127, 0, 0, 1), 23451));
439439
/// }
440440
/// ```
441441
pub trait ToSocketAddr {

src/libstd/old_io/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ impl Command {
376376
/// };
377377
///
378378
/// println!("status: {}", output.status);
379-
/// println!("stdout: {}", String::from_utf8_lossy(output.output.as_slice()));
380-
/// println!("stderr: {}", String::from_utf8_lossy(output.error.as_slice()));
379+
/// println!("stdout: {}", String::from_utf8_lossy(output.output.as_ref()));
380+
/// println!("stderr: {}", String::from_utf8_lossy(output.error.as_ref()));
381381
/// ```
382382
pub fn output(&self) -> IoResult<ProcessOutput> {
383383
self.spawn().and_then(|p| p.wait_with_output())

src/libstd/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn split_paths<T: BytesContainer>(unparsed: T) -> Vec<Path> {
311311
/// let key = "PATH";
312312
/// let mut paths = os::getenv_as_bytes(key).map_or(Vec::new(), os::split_paths);
313313
/// paths.push(Path::new("/home/xyz/bin"));
314-
/// os::setenv(key, os::join_paths(paths.as_slice()).unwrap());
314+
/// os::setenv(key, os::join_paths(&paths[..]).unwrap());
315315
/// ```
316316
#[unstable(feature = "os")]
317317
pub fn join_paths<T: BytesContainer>(paths: &[T]) -> Result<Vec<u8>, &'static str> {

src/libstd/process.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ mod tests {
678678
fn test_process_output_output() {
679679
let Output {status, stdout, stderr}
680680
= Command::new("echo").arg("hello").output().unwrap();
681-
let output_str = str::from_utf8(stdout.as_slice()).unwrap();
681+
let output_str = str::from_utf8(&stdout[..]).unwrap();
682682

683683
assert!(status.success());
684684
assert_eq!(output_str.trim().to_string(), "hello");
@@ -720,7 +720,7 @@ mod tests {
720720
let prog = Command::new("echo").arg("hello").stdout(Stdio::piped())
721721
.spawn().unwrap();
722722
let Output {status, stdout, stderr} = prog.wait_with_output().unwrap();
723-
let output_str = str::from_utf8(stdout.as_slice()).unwrap();
723+
let output_str = str::from_utf8(&stdout[..]).unwrap();
724724

725725
assert!(status.success());
726726
assert_eq!(output_str.trim().to_string(), "hello");
@@ -855,7 +855,7 @@ mod tests {
855855
cmd.env("PATH", &p);
856856
}
857857
let result = cmd.output().unwrap();
858-
let output = String::from_utf8_lossy(result.stdout.as_slice()).to_string();
858+
let output = String::from_utf8_lossy(&result.stdout[..]).to_string();
859859

860860
assert!(output.contains("RUN_TEST_NEW_ENV=123"),
861861
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
@@ -864,7 +864,7 @@ mod tests {
864864
#[test]
865865
fn test_add_to_env() {
866866
let result = env_cmd().env("RUN_TEST_NEW_ENV", "123").output().unwrap();
867-
let output = String::from_utf8_lossy(result.stdout.as_slice()).to_string();
867+
let output = String::from_utf8_lossy(&result.stdout[..]).to_string();
868868

869869
assert!(output.contains("RUN_TEST_NEW_ENV=123"),
870870
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);

src/test/run-pass-fulldeps/compiler-calls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ fn main() {
7777
let mut tc = TestCalls { count: 1 };
7878
// we should never get use this filename, but lets make sure they are valid args.
7979
let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
80-
rustc_driver::run_compiler(args.as_slice(), &mut tc);
80+
rustc_driver::run_compiler(&args[..], &mut tc);
8181
assert!(tc.count == 30);
8282
}

src/test/run-pass/regions-refcell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
2929
// supposed to match the lifetime `'a`) ...
3030
fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
3131
let one = [1];
32-
assert_eq!(map.borrow().get("one"), Some(&one.as_slice()));
32+
assert_eq!(map.borrow().get("one"), Some(&&one[..]));
3333
}
3434

3535
#[cfg(all(not(cannot_use_this_yet),not(cannot_use_this_yet_either)))]

0 commit comments

Comments
 (0)