Skip to content

Commit 584fbde

Browse files
committed
Fix errors
1 parent c6b82c7 commit 584fbde

File tree

22 files changed

+51
-110
lines changed

22 files changed

+51
-110
lines changed

src/libcollections/str.rs

+7-51
Original file line numberDiff line numberDiff line change
@@ -94,66 +94,26 @@ pub use unicode::{Words, UnicodeStrSlice};
9494
Section: Creating a string
9595
*/
9696

97-
/// Consumes a vector of bytes to create a new utf-8 string.
98-
///
99-
/// Returns `Err` with the original vector if the vector contains invalid
100-
/// UTF-8.
101-
///
102-
/// # Example
103-
///
104-
/// ```rust
105-
/// use std::str;
106-
/// let hello_vec = vec![104, 101, 108, 108, 111];
107-
/// let string = str::from_utf8_owned(hello_vec);
108-
/// assert_eq!(string, Ok("hello".to_string()));
109-
/// ```
97+
/// Deprecated. Replaced by `String::from_utf8`
11098
#[deprecated = "Replaced by `String::from_utf8`"]
11199
pub fn from_utf8_owned(vv: Vec<u8>) -> Result<String, Vec<u8>> {
112100
String::from_utf8(vv)
113101
}
114102

115-
/// Convert a byte to a UTF-8 string
116-
///
117-
/// # Failure
118-
///
119-
/// Fails if invalid UTF-8
120-
///
121-
/// # Example
122-
///
123-
/// ```rust
124-
/// use std::str;
125-
/// let string = str::from_byte(104);
126-
/// assert_eq!(string.as_slice(), "h");
127-
/// ```
103+
/// Deprecated. Replaced by `String::from_byte`
128104
#[deprecated = "Replaced by String::from_byte"]
129105
pub fn from_byte(b: u8) -> String {
130106
assert!(b < 128u8);
131107
String::from_char(1, b as char)
132108
}
133109

134-
/// Convert a char to a string
135-
///
136-
/// # Example
137-
///
138-
/// ```rust
139-
/// use std::str;
140-
/// let string = str::from_char('b');
141-
/// assert_eq!(string.as_slice(), "b");
142-
/// ```
110+
/// Deprecated. Use `String::from_char` or `char::to_string()` instead
143111
#[deprecated = "use String::from_char or char.to_string()"]
144112
pub fn from_char(ch: char) -> String {
145113
String::from_char(1, ch)
146114
}
147115

148-
/// Convert a vector of chars to a string
149-
///
150-
/// # Example
151-
///
152-
/// ```rust
153-
/// let chars = ['h', 'e', 'l', 'l', 'o'];
154-
/// let string = String::from_chars(chars);
155-
/// assert_eq!(string.as_slice(), "hello");
156-
/// ```
116+
/// Deprecated. Replaced by `String::from_chars`
157117
#[deprecated = "use String::from_chars instead"]
158118
pub fn from_chars(chs: &[char]) -> String {
159119
chs.iter().map(|c| *c).collect()
@@ -649,7 +609,6 @@ pub mod raw {
649609
#[test]
650610
fn test_from_buf_len() {
651611
use slice::ImmutableVector;
652-
use str::StrAllocating;
653612

654613
unsafe {
655614
let a = vec![65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
@@ -854,8 +813,7 @@ mod tests {
854813
use std::default::Default;
855814
use std::char::Char;
856815
use std::clone::Clone;
857-
use std::cmp::{Equal, Greater, Less, Ord, Eq, PartialOrd, PartialEq, Equiv};
858-
use std::result::{Ok, Err};
816+
use std::cmp::{Equal, Greater, Less, Ord, PartialOrd, Equiv};
859817
use std::option::{Some, None};
860818
use std::ptr::RawPtr;
861819
use std::iter::{Iterator, DoubleEndedIterator};
@@ -1546,7 +1504,7 @@ mod tests {
15461504
let mut pos = 0;
15471505
for ch in v.iter() {
15481506
assert!(s.char_at(pos) == *ch);
1549-
pos += from_char(*ch).len();
1507+
pos += String::from_char(1, *ch).len();
15501508
}
15511509
}
15521510

@@ -1557,7 +1515,7 @@ mod tests {
15571515
let mut pos = s.len();
15581516
for ch in v.iter().rev() {
15591517
assert!(s.char_at_reverse(pos) == *ch);
1560-
pos -= from_char(*ch).len();
1518+
pos -= String::from_char(1, *ch).len();
15611519
}
15621520
}
15631521

@@ -1996,10 +1954,8 @@ String::from_str("\u1111\u1171\u11b6"));
19961954
mod bench {
19971955
use test::Bencher;
19981956
use super::*;
1999-
use vec::Vec;
20001957
use std::iter::{Iterator, DoubleEndedIterator};
20011958
use std::collections::Collection;
2002-
use std::slice::Vector;
20031959

20041960
#[bench]
20051961
fn char_iterator(b: &mut Bencher) {

src/libcollections/string.rs

+27-22
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl String {
9999
///
100100
/// ```rust
101101
/// let input = b"Hello \xF0\x90\x80World";
102-
/// let output = std::str::from_utf8_lossy(input);
102+
/// let output = String::from_utf8_lossy(input);
103103
/// assert_eq!(output.as_slice(), "Hello \uFFFDWorld");
104104
/// ```
105105
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
@@ -218,18 +218,18 @@ impl String {
218218
Owned(res.into_string())
219219
}
220220

221-
/// Decode a UTF-16 encoded vector `v` into a string, returning `None`
221+
/// Decode a UTF-16 encoded vector `v` into a `String`, returning `None`
222222
/// if `v` contains any invalid data.
223223
///
224224
/// # Example
225225
///
226226
/// ```rust
227-
/// // 𝄞music
227+
/// // 𝄞music
228228
/// let mut v = [0xD834, 0xDD1E, 0x006d, 0x0075,
229229
/// 0x0073, 0x0069, 0x0063];
230-
/// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
230+
/// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
231231
///
232-
/// // 𝄞mu<invalid>ic
232+
/// // 𝄞mu<invalid>ic
233233
/// v[4] = 0xD800;
234234
/// assert_eq!(String::from_utf16(v), None);
235235
/// ```
@@ -249,13 +249,13 @@ impl String {
249249
///
250250
/// # Example
251251
/// ```rust
252-
/// // 𝄞mus<invalid>ic<invalid>
252+
/// // 𝄞mus<invalid>ic<invalid>
253253
/// let v = [0xD834, 0xDD1E, 0x006d, 0x0075,
254254
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
255255
/// 0xD834];
256256
///
257257
/// assert_eq!(String::from_utf16_lossy(v),
258-
/// "𝄞mus\uFFFDic\uFFFD".to_string());
258+
/// "𝄞mus\uFFFDic\uFFFD".to_string());
259259
/// ```
260260
pub fn from_utf16_lossy(v: &[u16]) -> String {
261261
str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
@@ -575,8 +575,9 @@ mod tests {
575575

576576
use Mutable;
577577
use str;
578-
use str::{Str, StrSlice, MaybeOwned, Owned, Slice};
578+
use str::{Str, StrSlice, Owned, Slice};
579579
use super::String;
580+
use vec::Vec;
580581

581582
#[test]
582583
fn test_from_str() {
@@ -587,10 +588,10 @@ mod tests {
587588
#[test]
588589
fn test_from_utf8() {
589590
let xs = Vec::from_slice(b"hello");
590-
assert_eq!(String::from_utf8(xs), Ok("hello".to_string()));
591+
assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello")));
591592

592-
let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes());
593-
assert_eq!(String::from_utf8(xs), Ok("ศไทย中华Việt Nam".to_string()));
593+
let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes());
594+
assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam")));
594595

595596
let xs = Vec::from_slice(b"hello\xFF");
596597
assert_eq!(String::from_utf8(xs),
@@ -602,21 +603,24 @@ mod tests {
602603
let xs = b"hello";
603604
assert_eq!(String::from_utf8_lossy(xs), Slice("hello"));
604605

605-
let xs = "ศไทย中华Việt Nam".as_bytes();
606-
assert_eq!(String::from_utf8_lossy(xs), Slice("ศไทย中华Việt Nam"));
606+
let xs = "ศไทย中华Việt Nam".as_bytes();
607+
assert_eq!(String::from_utf8_lossy(xs), Slice("ศไทย中华Việt Nam"));
607608

608609
let xs = b"Hello\xC2 There\xFF Goodbye";
609-
assert_eq!(String::from_utf8_lossy(xs), Owned(String::from_str("Hello\uFFFD There\uFFFD Goodbye")));
610+
assert_eq!(String::from_utf8_lossy(xs),
611+
Owned(String::from_str("Hello\uFFFD There\uFFFD Goodbye")));
610612

611613
let xs = b"Hello\xC0\x80 There\xE6\x83 Goodbye";
612614
assert_eq!(String::from_utf8_lossy(xs),
613615
Owned(String::from_str("Hello\uFFFD\uFFFD There\uFFFD Goodbye")));
614616

615617
let xs = b"\xF5foo\xF5\x80bar";
616-
assert_eq!(String::from_utf8_lossy(xs), Owned(String::from_str("\uFFFDfoo\uFFFD\uFFFDbar")));
618+
assert_eq!(String::from_utf8_lossy(xs),
619+
Owned(String::from_str("\uFFFDfoo\uFFFD\uFFFDbar")));
617620

618621
let xs = b"\xF1foo\xF1\x80bar\xF1\x80\x80baz";
619-
assert_eq!(String::from_utf8_lossy(xs), Owned(String::from_str("\uFFFDfoo\uFFFDbar\uFFFDbaz")));
622+
assert_eq!(String::from_utf8_lossy(xs),
623+
Owned(String::from_str("\uFFFDfoo\uFFFDbar\uFFFDbaz")));
620624

621625
let xs = b"\xF4foo\xF4\x80bar\xF4\xBFbaz";
622626
assert_eq!(String::from_utf8_lossy(xs),
@@ -635,21 +639,21 @@ mod tests {
635639
#[test]
636640
fn test_from_utf16() {
637641
let pairs =
638-
[(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
642+
[(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
639643
vec![0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
640644
0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16,
641645
0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16,
642646
0xd800_u16, 0xdf30_u16, 0x000a_u16]),
643647

644-
(String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
648+
(String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
645649
vec![0xd801_u16, 0xdc12_u16, 0xd801_u16,
646650
0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16,
647651
0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16,
648652
0xdc4b_u16, 0x0020_u16, 0xd801_u16, 0xdc0f_u16,
649653
0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16,
650654
0x000a_u16]),
651655

652-
(String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
656+
(String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
653657
vec![0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
654658
0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16,
655659
0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16,
@@ -658,7 +662,7 @@ mod tests {
658662
0xdf04_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16,
659663
0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]),
660664

661-
(String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
665+
(String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
662666
vec![0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
663667
0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16,
664668
0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16,
@@ -718,7 +722,7 @@ mod tests {
718722

719723
// general
720724
assert_eq!(String::from_utf16_lossy([0xD800, 0xd801, 0xdc8b, 0xD800]),
721-
String::from_str("\uFFFD𐒋\uFFFD"));
725+
String::from_str("\uFFFD𐒋\uFFFD"));
722726
}
723727

724728
#[test]
@@ -852,7 +856,8 @@ mod tests {
852856

853857
#[bench]
854858
fn from_utf8_lossy_100_multibyte(b: &mut Bencher) {
855-
let s = "𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰".as_bytes();
859+
let s = "𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة\
860+
الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰".as_bytes();
856861
assert_eq!(100, s.len());
857862
b.iter(|| {
858863
let _ = String::from_utf8_lossy(s);

src/libregex/parse.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::cmp;
1313
use std::fmt;
1414
use std::iter;
1515
use std::num;
16-
use std::str;
1716

1817
/// Static data containing Unicode ranges for general categories and scripts.
1918
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};

src/libregex/test/bench.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#![allow(non_snake_case_functions)]
1111

1212
use std::rand::{Rng, task_rng};
13-
use std::str;
1413
use stdtest::Bencher;
1514

1615
use regex::{Regex, NoExpand};

src/librustc/driver/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use metadata;
2020
use std::any::AnyRefExt;
2121
use std::io;
2222
use std::os;
23-
use std::str;
2423
use std::task::TaskBuilder;
2524

2625
use syntax::ast;

src/librustc/metadata/encoder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use std::hash::Hash;
3535
use std::hash;
3636
use std::io::MemWriter;
3737
use std::mem;
38-
use std::str;
3938
use std::collections::HashMap;
4039
use syntax::abi;
4140
use syntax::ast::*;
@@ -619,7 +618,7 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
619618
Public => 'y',
620619
Inherited => 'i',
621620
};
622-
ebml_w.wr_str(ch.to_str().as_slice());
621+
ebml_w.wr_str(ch.to_string().as_slice());
623622
ebml_w.end_tag();
624623
}
625624

@@ -1922,5 +1921,5 @@ pub fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> String {
19221921
tcx: tcx,
19231922
abbrevs: &RefCell::new(HashMap::new())
19241923
}, t);
1925-
str::from_utf8(wr.get_ref()).unwrap().to_string()
1924+
String::from_utf8(wr.unwrap()).unwrap()
19261925
}

src/librustdoc/html/highlight.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! This module uses libsyntax's lexer to provide token-based highlighting for
1414
//! the HTML documentation generated by rustdoc.
1515
16-
use std::str;
1716
use std::io;
1817

1918
use syntax::parse;

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,9 @@ impl<'a> SourceCollector<'a> {
723723

724724
// Remove the utf-8 BOM if any
725725
let contents = if contents.starts_with("\ufeff") {
726-
contents.as_slice().slice_from(3)
726+
contents.slice_from(3)
727727
} else {
728-
contents.as_slice()
728+
contents
729729
};
730730

731731
// Create the intermediate directories

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ extern crate time;
2929

3030
use std::io;
3131
use std::io::{File, MemWriter};
32-
use std::str;
3332
use std::gc::Gc;
3433
use serialize::{json, Decodable, Encodable};
3534
use externalfiles::ExternalHtml;

0 commit comments

Comments
 (0)