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

+1-1
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

+1-1
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

+1-1
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

+3-3
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

+2-2
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

+1-1
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

+3-3
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

+1-1
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

+15-15
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

+4-4
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);

src/librustuv/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ mod test {
488488

489489
let nread = result.unwrap();
490490
assert!(nread > 0);
491-
let read_str = str::from_utf8(read_mem.slice_to(nread as uint));
491+
let read_str = str::from_utf8(read_mem.slice_to(nread as uint)).unwrap();
492492
assert_eq!(read_str, "hello");
493493
}
494494
// unlink

src/libstd/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CString {
167167
if self.buf.is_null() { return None; }
168168
let buf = self.as_bytes();
169169
let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL
170-
str::from_utf8_opt(buf)
170+
str::from_utf8(buf)
171171
}
172172

173173
/// Return a CString iterator.

src/libstd/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ impl<'a> Formatter<'a> {
812812

813813
fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) {
814814
::uint::to_str_bytes(value, 10, |buf| {
815-
let valuestr = str::from_utf8(buf);
815+
let valuestr = str::from_utf8(buf).unwrap();
816816
for piece in pieces.iter() {
817817
self.run(piece, Some(valuestr));
818818
}

src/libstd/io/fs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ mod test {
805805
}
806806
}
807807
unlink(filename);
808-
let read_str = str::from_utf8(read_mem);
808+
let read_str = str::from_utf8(read_mem).unwrap();
809809
assert_eq!(read_str, message);
810810
})
811811

@@ -829,7 +829,7 @@ mod test {
829829
tell_pos_post_read = read_stream.tell();
830830
}
831831
unlink(filename);
832-
let read_str = str::from_utf8(read_mem);
832+
let read_str = str::from_utf8(read_mem).unwrap();
833833
assert_eq!(read_str, message.slice(4, 8));
834834
assert_eq!(tell_pos_pre_read, set_cursor);
835835
assert_eq!(tell_pos_post_read, message.len() as u64);
@@ -854,7 +854,7 @@ mod test {
854854
read_stream.read(read_mem);
855855
}
856856
unlink(filename);
857-
let read_str = str::from_utf8(read_mem);
857+
let read_str = str::from_utf8(read_mem).unwrap();
858858
assert!(read_str == final_msg.to_owned());
859859
})
860860

@@ -876,15 +876,15 @@ mod test {
876876

877877
read_stream.seek(-4, SeekEnd);
878878
read_stream.read(read_mem);
879-
assert_eq!(str::from_utf8(read_mem), chunk_three);
879+
assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_three);
880880

881881
read_stream.seek(-9, SeekCur);
882882
read_stream.read(read_mem);
883-
assert_eq!(str::from_utf8(read_mem), chunk_two);
883+
assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_two);
884884

885885
read_stream.seek(0, SeekSet);
886886
read_stream.read(read_mem);
887-
assert_eq!(str::from_utf8(read_mem), chunk_one);
887+
assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_one);
888888
}
889889
unlink(filename);
890890
})
@@ -958,7 +958,7 @@ mod test {
958958
{
959959
let n = f.filestem_str();
960960
File::open(f).read(mem);
961-
let read_str = str::from_utf8(mem);
961+
let read_str = str::from_utf8(mem).unwrap();
962962
let expected = match n {
963963
None|Some("") => fail!("really shouldn't happen.."),
964964
Some(n) => prefix+n

src/libstd/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ pub trait Buffer: Reader {
12021202
}
12031203
}
12041204
}
1205-
match str::from_utf8_opt(buf.slice_to(width)) {
1205+
match str::from_utf8(buf.slice_to(width)) {
12061206
Some(s) => Some(s.char_at(0)),
12071207
None => None
12081208
}

src/libstd/io/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ mod tests {
254254
loop {
255255
match input.read(buf) {
256256
None => { break }
257-
Some(n) => { ret.push_str(str::from_utf8(buf.slice_to(n))); }
257+
Some(n) => { ret.push_str(str::from_utf8(buf.slice_to(n)).unwrap()); }
258258
}
259259
}
260260
return ret;

src/libstd/path/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
189189
/// If the path is not representable in utf-8, this returns None.
190190
#[inline]
191191
fn as_str<'a>(&'a self) -> Option<&'a str> {
192-
str::from_utf8_opt(self.as_vec())
192+
str::from_utf8(self.as_vec())
193193
}
194194

195195
/// Returns the path as a byte vector
@@ -220,7 +220,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
220220
/// See `dirname` for details.
221221
#[inline]
222222
fn dirname_str<'a>(&'a self) -> Option<&'a str> {
223-
str::from_utf8_opt(self.dirname())
223+
str::from_utf8(self.dirname())
224224
}
225225
/// Returns the file component of `self`, as a byte vector.
226226
/// If `self` represents the root of the file hierarchy, returns None.
@@ -230,7 +230,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
230230
/// See `filename` for details.
231231
#[inline]
232232
fn filename_str<'a>(&'a self) -> Option<&'a str> {
233-
self.filename().and_then(str::from_utf8_opt)
233+
self.filename().and_then(str::from_utf8)
234234
}
235235
/// Returns the stem of the filename of `self`, as a byte vector.
236236
/// The stem is the portion of the filename just before the last '.'.
@@ -252,7 +252,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
252252
/// See `filestem` for details.
253253
#[inline]
254254
fn filestem_str<'a>(&'a self) -> Option<&'a str> {
255-
self.filestem().and_then(str::from_utf8_opt)
255+
self.filestem().and_then(str::from_utf8)
256256
}
257257
/// Returns the extension of the filename of `self`, as an optional byte vector.
258258
/// The extension is the portion of the filename just after the last '.'.
@@ -275,7 +275,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
275275
/// See `extension` for details.
276276
#[inline]
277277
fn extension_str<'a>(&'a self) -> Option<&'a str> {
278-
self.extension().and_then(str::from_utf8_opt)
278+
self.extension().and_then(str::from_utf8)
279279
}
280280

281281
/// Replaces the filename portion of the path with the given byte vector or string.
@@ -502,7 +502,7 @@ pub trait BytesContainer {
502502
/// Returns the receiver interpreted as a utf-8 string, if possible
503503
#[inline]
504504
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
505-
str::from_utf8_opt(self.container_as_bytes())
505+
str::from_utf8(self.container_as_bytes())
506506
}
507507
/// Returns whether .container_as_str() is guaranteed to not fail
508508
// FIXME (#8888): Remove unused arg once ::<for T> works

0 commit comments

Comments
 (0)