Skip to content

Commit b8c4149

Browse files
committed
[std::str] Rename from_utf8_opt() to from_utf8(), drop the old from_utf8() behavior
1 parent 46b0164 commit b8c4149

File tree

20 files changed

+59
-84
lines changed

20 files changed

+59
-84
lines changed

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
308308

309309
let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
310310
config.adb_test_dir.clone(), config.adb_test_dir.clone(),
311-
str::from_utf8(exe_file.filename().unwrap()));
311+
str::from_utf8(exe_file.filename().unwrap()).unwrap());
312312

313313
let mut process = procsrv::run_background("", config.adb_path,
314314
[~"shell",adb_arg.clone()],

src/libextra/ebml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'doc> Doc<'doc> {
3030
}
3131

3232
pub fn as_str_slice<'a>(&'a self) -> &'a str {
33-
str::from_utf8(self.data.slice(self.start, self.end))
33+
str::from_utf8(self.data.slice(self.start, self.end)).unwrap()
3434
}
3535

3636
pub fn as_str(&self) -> ~str {

src/libextra/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ fn should_sort_failures_before_printing_them() {
704704

705705
st.write_failures();
706706
let s = match st.out {
707-
Raw(ref m) => str::from_utf8(m.get_ref()),
707+
Raw(ref m) => str::from_utf8(m.get_ref()).unwrap(),
708708
Pretty(_) => unreachable!()
709709
};
710710

src/librustc/back/archive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
5757
if !o.status.success() {
5858
sess.err(format!("{} {} failed with: {}", ar, args.connect(" "),
5959
o.status));
60-
sess.note(format!("stdout ---\n{}", str::from_utf8(o.output)));
61-
sess.note(format!("stderr ---\n{}", str::from_utf8(o.error)));
60+
sess.note(format!("stdout ---\n{}", str::from_utf8(o.output).unwrap()));
61+
sess.note(format!("stderr ---\n{}", str::from_utf8(o.error).unwrap()));
6262
sess.abort_if_errors();
6363
}
6464
o
@@ -141,7 +141,7 @@ impl Archive {
141141
/// Lists all files in an archive
142142
pub fn files(&self) -> ~[~str] {
143143
let output = run_ar(self.sess, "t", None, [&self.dst]);
144-
str::from_utf8(output.output).lines().map(|s| s.to_owned()).collect()
144+
str::from_utf8(output.output).unwrap().lines().map(|s| s.to_owned()).collect()
145145
}
146146

147147
fn add_archive(&mut self, archive: &Path, name: &str, skip: &[&str]) {

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
9797

9898
fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
9999
scan(st, is_last, |bytes| {
100-
st.tcx.sess.ident_of(str::from_utf8(bytes))
100+
st.tcx.sess.ident_of(str::from_utf8(bytes).unwrap())
101101
})
102102
}
103103

@@ -476,7 +476,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
476476
let mut abis = AbiSet::empty();
477477
while peek(st) != ']' {
478478
scan(st, |c| c == ',', |bytes| {
479-
let abi_str = str::from_utf8(bytes).to_owned();
479+
let abi_str = str::from_utf8(bytes).unwrap().to_owned();
480480
let abi = abi::lookup(abi_str).expect(abi_str);
481481
abis.add(abi);
482482
});

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn enc_ty(w: &mut MemWriter, cx: @ctxt, t: ty::t) {
7272
None => {
7373
let wr = &mut MemWriter::new();
7474
enc_sty(wr, cx, &ty::get(t).sty);
75-
let s = str::from_utf8(wr.get_ref()).to_managed();
75+
let s = str::from_utf8(wr.get_ref()).unwrap().to_managed();
7676
let mut short_names_cache = cx.tcx
7777
.short_names_cache
7878
.borrow_mut();

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn render(w: &mut io::Writer, s: &str) {
112112
unsafe {
113113
let my_opaque: &my_opaque = cast::transmute(opaque);
114114
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
115-
let text = str::from_utf8(text);
115+
let text = str::from_utf8(text).unwrap();
116116
let mut lines = text.lines().filter(|l| stripped_filtered_line(*l).is_none());
117117
let text = lines.to_owned_vec().connect("\n");
118118

@@ -172,14 +172,14 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
172172
let (test, shouldfail, ignore) =
173173
vec::raw::buf_as_slice((*lang).data,
174174
(*lang).size as uint, |lang| {
175-
let s = str::from_utf8(lang);
175+
let s = str::from_utf8(lang).unwrap();
176176
(s.contains("rust"), s.contains("should_fail"),
177177
s.contains("ignore"))
178178
});
179179
if !test { return }
180180
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
181181
let tests: &mut ::test::Collector = intrinsics::transmute(opaque);
182-
let text = str::from_utf8(text);
182+
let text = str::from_utf8(text).unwrap();
183183
let mut lines = text.lines().map(|l| stripped_filtered_line(l).unwrap_or(l));
184184
let text = lines.to_owned_vec().connect("\n");
185185
tests.add_test(text, ignore, shouldfail);

src/librustpkg/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a> PkgScript<'a> {
193193
Some(output) => {
194194
debug!("run_custom: second pkg command did {:?}", output.status);
195195
// Run the configs() function to get the configs
196-
let cfgs = str::from_utf8(output.output).words()
196+
let cfgs = str::from_utf8(output.output).unwrap().words()
197197
.map(|w| w.to_owned()).collect();
198198
Some((cfgs, output.status))
199199
},

src/librustpkg/tests.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
143143
let rslt = prog.finish_with_output();
144144
if !rslt.status.success() {
145145
fail!("{} [git returned {:?}, output = {}, error = {}]", err_msg,
146-
rslt.status, str::from_utf8(rslt.output), str::from_utf8(rslt.error));
146+
rslt.status, str::from_utf8(rslt.output).unwrap(), str::from_utf8(rslt.error).unwrap());
147147
}
148148
}
149149

@@ -279,13 +279,13 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
279279
}).expect(format!("failed to exec `{}`", cmd));
280280
let output = prog.finish_with_output();
281281
debug!("Output from command {} with args {:?} was {} \\{{}\\}[{:?}]",
282-
cmd, args, str::from_utf8(output.output),
283-
str::from_utf8(output.error),
282+
cmd, args, str::from_utf8(output.output).unwrap(),
283+
str::from_utf8(output.error).unwrap(),
284284
output.status);
285285
if !output.status.success() {
286286
debug!("Command {} {:?} failed with exit code {:?}; its output was --- {} {} ---",
287287
cmd, args, output.status,
288-
str::from_utf8(output.output), str::from_utf8(output.error));
288+
str::from_utf8(output.output).unwrap(), str::from_utf8(output.error).unwrap());
289289
Fail(output)
290290
}
291291
else {
@@ -445,7 +445,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool {
445445
fn command_line_test_output(args: &[~str]) -> ~[~str] {
446446
let mut result = ~[];
447447
let p_output = command_line_test(args, &os::getcwd());
448-
let test_output = str::from_utf8(p_output.output);
448+
let test_output = str::from_utf8(p_output.output).unwrap();
449449
for s in test_output.split('\n') {
450450
result.push(s.to_owned());
451451
}
@@ -459,7 +459,7 @@ fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~
459459
Fail(_) => fail!("Command-line test failed"),
460460
Success(r) => r
461461
};
462-
let test_output = str::from_utf8(p_output.output);
462+
let test_output = str::from_utf8(p_output.output).unwrap();
463463
for s in test_output.split('\n') {
464464
result.push(s.to_owned());
465465
}
@@ -1199,7 +1199,7 @@ fn test_uninstall() {
11991199
let workspace = create_local_package(&CrateId::new("foo"));
12001200
command_line_test([~"uninstall", ~"foo"], workspace.path());
12011201
let output = command_line_test([~"list"], workspace.path());
1202-
assert!(!str::from_utf8(output.output).contains("foo"));
1202+
assert!(!str::from_utf8(output.output).unwrap().contains("foo"));
12031203
}
12041204
12051205
#[test]
@@ -1269,8 +1269,8 @@ fn test_extern_mod() {
12691269
let outp = prog.finish_with_output();
12701270
if !outp.status.success() {
12711271
fail!("output was {}, error was {}",
1272-
str::from_utf8(outp.output),
1273-
str::from_utf8(outp.error));
1272+
str::from_utf8(outp.output).unwrap(),
1273+
str::from_utf8(outp.error).unwrap());
12741274
}
12751275
assert!(exec_file.exists() && is_executable(&exec_file));
12761276
}
@@ -1324,8 +1324,8 @@ fn test_extern_mod_simpler() {
13241324
let outp = prog.finish_with_output();
13251325
if !outp.status.success() {
13261326
fail!("output was {}, error was {}",
1327-
str::from_utf8(outp.output),
1328-
str::from_utf8(outp.error));
1327+
str::from_utf8(outp.output).unwrap(),
1328+
str::from_utf8(outp.error).unwrap());
13291329
}
13301330
assert!(exec_file.exists() && is_executable(&exec_file));
13311331
}
@@ -2092,7 +2092,7 @@ fn test_rustpkg_test_creates_exec() {
20922092
fn test_rustpkg_test_output() {
20932093
let workspace = create_local_package_with_test(&CrateId::new("foo"));
20942094
let output = command_line_test([~"test", ~"foo"], workspace.path());
2095-
let output_str = str::from_utf8(output.output);
2095+
let output_str = str::from_utf8(output.output).unwrap();
20962096
// The first two assertions are separate because test output may
20972097
// contain color codes, which could appear between "test f" and "ok".
20982098
assert!(output_str.contains("test f"));
@@ -2123,7 +2123,7 @@ fn test_rustpkg_test_cfg() {
21232123
"#[test] #[cfg(not(foobar))] fn f() { assert!('a' != 'a'); }");
21242124
let output = command_line_test([~"test", ~"--cfg", ~"foobar", ~"foo"],
21252125
foo_workspace);
2126-
let output_str = str::from_utf8(output.output);
2126+
let output_str = str::from_utf8(output.output).unwrap();
21272127
assert!(output_str.contains("0 passed; 0 failed; 0 ignored; 0 measured"));
21282128
}
21292129
@@ -2424,8 +2424,8 @@ fn correct_error_dependency() {
24242424
Fail(ProcessOutput{ error: error, output: output, .. }) => {
24252425
assert!(str::is_utf8(error));
24262426
assert!(str::is_utf8(output));
2427-
let error_str = str::from_utf8(error);
2428-
let out_str = str::from_utf8(output);
2427+
let error_str = str::from_utf8(error).unwrap();
2428+
let out_str = str::from_utf8(output).unwrap();
24292429
debug!("ss = {}", error_str);
24302430
debug!("out_str = {}", out_str);
24312431
if out_str.contains("Package badpkg depends on some_package_that_doesnt_exist") &&

src/librustpkg/version.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
115115
}
116116

117117
let mut output = None;
118-
let output_text = str::from_utf8(outp.output);
118+
let output_text = str::from_utf8(outp.output).unwrap();
119119
for l in output_text.lines() {
120120
if !l.is_whitespace() {
121121
output = Some(l);
@@ -147,8 +147,8 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
147147
let outp = opt_outp.expect("Failed to exec `git`");
148148
if outp.status.success() {
149149
debug!("Cloned it... ( {}, {} )",
150-
str::from_utf8(outp.output),
151-
str::from_utf8(outp.error));
150+
str::from_utf8(outp.output).unwrap(),
151+
str::from_utf8(outp.error).unwrap());
152152
let mut output = None;
153153
let git_dir = tmp_dir.join(".git");
154154
debug!("(getting version, now getting tags) executing \\{git --git-dir={} tag -l\\}",
@@ -158,7 +158,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
158158
["--git-dir=" + git_dir.as_str().unwrap(),
159159
~"tag", ~"-l"]);
160160
let outp = opt_outp.expect("Failed to exec `git`");
161-
let output_text = str::from_utf8(outp.output);
161+
let output_text = str::from_utf8(outp.output).unwrap();
162162
debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
163163
for l in output_text.lines() {
164164
debug!("A line of output: {}", l);

0 commit comments

Comments
 (0)