Skip to content

Commit 05ae134

Browse files
committed
[std::str] Rename from_utf8_owned_opt() to from_utf8_owned(), drop the old from_utf8_owned() behavior
1 parent b8c4149 commit 05ae134

33 files changed

+65
-91
lines changed

src/compiletest/procsrv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ pub fn run(lib_path: &str,
6666

6767
Some(Result {
6868
status: status,
69-
out: str::from_utf8_owned(output),
70-
err: str::from_utf8_owned(error)
69+
out: str::from_utf8_owned(output).unwrap(),
70+
err: str::from_utf8_owned(error).unwrap()
7171
})
7272
},
7373
None => None

src/compiletest/runtest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
154154
match props.pp_exact { Some(_) => 1, None => 2 };
155155

156156
let src = File::open(testfile).read_to_end();
157-
let src = str::from_utf8_owned(src);
157+
let src = str::from_utf8_owned(src).unwrap();
158158
let mut srcs = ~[src];
159159

160160
let mut round = 0;
@@ -176,7 +176,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
176176
Some(ref file) => {
177177
let filepath = testfile.dir_path().join(file);
178178
let s = File::open(&filepath).read_to_end();
179-
str::from_utf8_owned(s)
179+
str::from_utf8_owned(s).unwrap()
180180
}
181181
None => { srcs[srcs.len() - 2u].clone() }
182182
};
@@ -1100,7 +1100,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
11001100

11011101
fn count_extracted_lines(p: &Path) -> uint {
11021102
let x = File::open(&p.with_extension("ll")).read_to_end();
1103-
let x = str::from_utf8_owned(x);
1103+
let x = str::from_utf8_owned(x).unwrap();
11041104
x.lines().len()
11051105
}
11061106

src/libextra/base64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a> FromBase64 for &'a str {
198198
* println!("base64 output: {}", hello_str);
199199
* let res = hello_str.from_base64();
200200
* if res.is_ok() {
201-
* let optBytes = str::from_utf8_owned_opt(res.unwrap());
201+
* let optBytes = str::from_utf8_owned(res.unwrap());
202202
* if optBytes.is_some() {
203203
* println!("decoded from base64: {}", optBytes.unwrap());
204204
* }

src/libextra/hex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a> FromHex for &'a str {
9696
* println!("{}", hello_str);
9797
* let bytes = hello_str.from_hex().unwrap();
9898
* println!("{:?}", bytes);
99-
* let result_str = str::from_utf8_owned(bytes);
99+
* let result_str = str::from_utf8_owned(bytes).unwrap();
100100
* println!("{}", result_str);
101101
* }
102102
* ```

src/libextra/json.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'a> Encoder<'a> {
312312
/// Encode the specified struct into a json str
313313
pub fn str_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~str {
314314
let buff:~[u8] = Encoder::buffer_encode(to_encode_object);
315-
str::from_utf8_owned(buff)
315+
str::from_utf8_owned(buff).unwrap()
316316
}
317317
}
318318

@@ -684,7 +684,7 @@ impl Json{
684684
pub fn to_pretty_str(&self) -> ~str {
685685
let mut s = MemWriter::new();
686686
self.to_pretty_writer(&mut s as &mut io::Writer);
687-
str::from_utf8_owned(s.unwrap())
687+
str::from_utf8_owned(s.unwrap()).unwrap()
688688
}
689689
}
690690

@@ -1067,7 +1067,7 @@ impl<T : Iterator<char>> Parser<T> {
10671067

10681068
/// Decodes a json value from an `&mut io::Reader`
10691069
pub fn from_reader(rdr: &mut io::Reader) -> Result<Json, Error> {
1070-
let s = str::from_utf8_owned(rdr.read_to_end());
1070+
let s = str::from_utf8_owned(rdr.read_to_end()).unwrap();
10711071
let mut parser = Parser::new(s.chars());
10721072
parser.parse()
10731073
}
@@ -1541,7 +1541,7 @@ impl to_str::ToStr for Json {
15411541
fn to_str(&self) -> ~str {
15421542
let mut s = MemWriter::new();
15431543
self.to_writer(&mut s as &mut io::Writer);
1544-
str::from_utf8_owned(s.unwrap())
1544+
str::from_utf8_owned(s.unwrap()).unwrap()
15451545
}
15461546
}
15471547

@@ -1732,7 +1732,7 @@ mod tests {
17321732
17331733
let mut m = MemWriter::new();
17341734
f(&mut m as &mut io::Writer);
1735-
str::from_utf8_owned(m.unwrap())
1735+
str::from_utf8_owned(m.unwrap()).unwrap()
17361736
}
17371737
17381738
#[test]

src/libextra/stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ mod tests {
10011001
use std::io::MemWriter;
10021002
let mut m = MemWriter::new();
10031003
write_boxplot(&mut m as &mut io::Writer, s, 30);
1004-
let out = str::from_utf8_owned(m.unwrap());
1004+
let out = str::from_utf8_owned(m.unwrap()).unwrap();
10051005
assert_eq!(out, expected);
10061006
}
10071007

src/libextra/terminfo/parser/compiled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn parse(file: &mut io::Reader,
216216
}
217217

218218
// don't read NUL
219-
let names_str = str::from_utf8_owned(file.read_bytes(names_bytes as uint - 1));
219+
let names_str = str::from_utf8_owned(file.read_bytes(names_bytes as uint - 1)).unwrap();
220220

221221
let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect();
222222

src/libextra/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str {
10301030
}
10311031
}
10321032
1033-
str::from_utf8_owned(buf)
1033+
str::from_utf8_owned(buf).unwrap()
10341034
}
10351035
10361036
#[cfg(test)]

src/libextra/uuid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl Uuid {
313313
s[i*2+0] = digit[0];
314314
s[i*2+1] = digit[1];
315315
}
316-
str::from_utf8_owned(s)
316+
str::from_utf8_owned(s).unwrap()
317317
}
318318

319319
/// Returns a string of hexadecimal digits, separated into groups with a hyphen.

src/libextra/workcache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ fn json_encode<'a, T:Encodable<json::Encoder<'a>>>(t: &T) -> ~str {
243243
let mut writer = MemWriter::new();
244244
let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);
245245
t.encode(&mut encoder);
246-
str::from_utf8_owned(writer.unwrap())
246+
str::from_utf8_owned(writer.unwrap()).unwrap()
247247
}
248248

249249
// FIXME(#5121)
@@ -491,7 +491,7 @@ fn test() {
491491
let subcx = cx.clone();
492492
let pth = pth.clone();
493493

494-
let file_content = from_utf8_owned(File::open(&pth).read_to_end());
494+
let file_content = from_utf8_owned(File::open(&pth).read_to_end()).unwrap();
495495

496496
// FIXME (#9639): This needs to handle non-utf8 paths
497497
prep.declare_input("file", pth.as_str().unwrap(), file_content);

src/librustc/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub mod write {
298298
if !prog.status.success() {
299299
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
300300
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
301-
sess.note(str::from_utf8_owned(prog.error + prog.output));
301+
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
302302
sess.abort_if_errors();
303303
}
304304
},
@@ -1007,7 +1007,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10071007
if !prog.status.success() {
10081008
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
10091009
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
1010-
sess.note(str::from_utf8_owned(prog.error + prog.output));
1010+
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
10111011
sess.abort_if_errors();
10121012
}
10131013
},

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
234234
1u => {
235235
let ifile = matches.free[0].as_slice();
236236
if "-" == ifile {
237-
let src = str::from_utf8_owned(io::stdin().read_to_end());
237+
let src = str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
238238
d::StrInput(src.to_managed())
239239
} else {
240240
d::FileInput(Path::new(ifile))

src/librustc/metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1989,5 +1989,5 @@ pub fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> ~str {
19891989
abbrevs: tyencode::ac_no_abbrevs};
19901990
let mut wr = MemWriter::new();
19911991
tyencode::enc_ty(&mut wr, cx, t);
1992-
str::from_utf8_owned(wr.get_ref().to_owned())
1992+
str::from_utf8_owned(wr.get_ref().to_owned()).unwrap()
19931993
}

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ impl Liveness {
825825
}
826826
}
827827
}
828-
str::from_utf8_owned(wr.unwrap())
828+
str::from_utf8_owned(wr.unwrap()).unwrap()
829829
}
830830

831831
pub fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) {

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a> SourceCollector<'a> {
427427
}
428428
}
429429
}
430-
let contents = str::from_utf8_owned(contents);
430+
let contents = str::from_utf8_owned(contents).unwrap();
431431

432432
// Create the intermediate directories
433433
let mut cur = self.dst.clone();

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
330330
let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
331331
crate.encode(&mut encoder);
332332
}
333-
str::from_utf8_owned(w.unwrap())
333+
str::from_utf8_owned(w.unwrap()).unwrap()
334334
};
335335
let crate_json = match json::from_str(crate_json_str) {
336336
Ok(j) => j,

src/librustpkg/source_control.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
3838
target.as_str().unwrap().to_owned()]);
3939
let outp = opt_outp.expect("Failed to exec `git`");
4040
if !outp.status.success() {
41-
println!("{}", str::from_utf8_owned(outp.output.clone()));
42-
println!("{}", str::from_utf8_owned(outp.error));
41+
println!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
42+
println!("{}", str::from_utf8_owned(outp.error).unwrap());
4343
return DirToUse(target.clone());
4444
}
4545
else {
@@ -54,8 +54,8 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
5454
format!("--git-dir={}", git_dir.as_str().unwrap().to_owned()),
5555
~"checkout", format!("{}", *s)]).expect("Failed to exec `git`");
5656
if !outp.status.success() {
57-
println!("{}", str::from_utf8_owned(outp.output.clone()));
58-
println!("{}", str::from_utf8_owned(outp.error));
57+
println!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
58+
println!("{}", str::from_utf8_owned(outp.error).unwrap());
5959
return DirToUse(target.clone());
6060
}
6161
}
@@ -114,8 +114,8 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
114114
target.as_str().unwrap().to_owned()]);
115115
let outp = opt_outp.expect("Failed to exec `git`");
116116
if !outp.status.success() {
117-
debug!("{}", str::from_utf8_owned(outp.output.clone()));
118-
debug!("{}", str::from_utf8_owned(outp.error));
117+
debug!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
118+
debug!("{}", str::from_utf8_owned(outp.error).unwrap());
119119
cond.raise((source.to_owned(), target.clone()))
120120
}
121121
else {
@@ -125,8 +125,8 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
125125
target);
126126
let outp = opt_outp.expect("Failed to exec `git`");
127127
if !outp.status.success() {
128-
debug!("{}", str::from_utf8_owned(outp.output.clone()));
129-
debug!("{}", str::from_utf8_owned(outp.error));
128+
debug!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
129+
debug!("{}", str::from_utf8_owned(outp.error).unwrap());
130130
cond.raise((source.to_owned(), target.clone()))
131131
}
132132
}

src/librustpkg/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ fn test_info() {
11911191
let expected_info = ~"package foo"; // fill in
11921192
let workspace = create_local_package(&CrateId::new("foo"));
11931193
let output = command_line_test([~"info", ~"foo"], workspace.path());
1194-
assert_eq!(str::from_utf8_owned(output.output), expected_info);
1194+
assert_eq!(str::from_utf8_owned(output.output).unwrap(), expected_info);
11951195
}
11961196
11971197
#[test]

src/libstd/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ pub fn format(args: &Arguments) -> ~str {
691691
pub unsafe fn format_unsafe(fmt: &[rt::Piece], args: &[Argument]) -> ~str {
692692
let mut output = MemWriter::new();
693693
write_unsafe(&mut output as &mut io::Writer, fmt, args);
694-
return str::from_utf8_owned(output.unwrap());
694+
return str::from_utf8_owned(output.unwrap()).unwrap();
695695
}
696696

697697
impl<'a> Formatter<'a> {

src/libstd/io/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ mod test {
754754
let mut read_buf = [0, .. 1028];
755755
let read_str = match read_stream.read(read_buf).unwrap() {
756756
-1|0 => fail!("shouldn't happen"),
757-
n => str::from_utf8_owned(read_buf.slice_to(n).to_owned())
757+
n => str::from_utf8_owned(read_buf.slice_to(n).to_owned()).unwrap()
758758
};
759759
assert_eq!(read_str, message.to_owned());
760760
}

src/libstd/io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ pub trait Reader {
607607
/// This function will raise all the same conditions as the `read` method,
608608
/// along with raising a condition if the input is not valid UTF-8.
609609
fn read_to_str(&mut self) -> ~str {
610-
match str::from_utf8_owned_opt(self.read_to_end()) {
610+
match str::from_utf8_owned(self.read_to_end()) {
611611
Some(s) => s,
612612
None => {
613613
io_error::cond.raise(standard_error(InvalidInput));
@@ -1117,7 +1117,7 @@ pub trait Buffer: Reader {
11171117
/// The task will also fail if sequence of bytes leading up to
11181118
/// the newline character are not valid UTF-8.
11191119
fn read_line(&mut self) -> Option<~str> {
1120-
self.read_until('\n' as u8).map(str::from_utf8_owned)
1120+
self.read_until('\n' as u8).map(|line| str::from_utf8_owned(line).unwrap())
11211121
}
11221122

11231123
/// Create an iterator that reads a line on each iteration until EOF.

src/libstd/num/strconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+Round+
427427
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
428428
let (bytes, special) = float_to_str_bytes_common(num, radix,
429429
negative_zero, sign, digits);
430-
(str::from_utf8_owned(bytes), special)
430+
(str::from_utf8_owned(bytes).unwrap(), special)
431431
}
432432

433433
// Some constants for from_str_bytes_common's input validation,

src/libstd/repr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ pub fn repr_to_str<T>(t: &T) -> ~str {
608608

609609
let mut result = io::MemWriter::new();
610610
write_repr(&mut result as &mut io::Writer, t);
611-
str::from_utf8_owned(result.unwrap())
611+
str::from_utf8_owned(result.unwrap()).unwrap()
612612
}
613613

614614
#[cfg(test)]
@@ -626,7 +626,7 @@ fn test_repr() {
626626
fn exact_test<T>(t: &T, e:&str) {
627627
let mut m = io::MemWriter::new();
628628
write_repr(&mut m as &mut io::Writer, t);
629-
let s = str::from_utf8_owned(m.unwrap());
629+
let s = str::from_utf8_owned(m.unwrap()).unwrap();
630630
assert_eq!(s.as_slice(), e);
631631
}
632632

0 commit comments

Comments
 (0)