]> git.lizzy.rs Git - rust.git/commitdiff
[std::str] Rename from_utf8_opt() to from_utf8(), drop the old from_utf8() behavior
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 23 Dec 2013 16:30:49 +0000 (17:30 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Tue, 21 Jan 2014 23:48:48 +0000 (15:48 -0800)
20 files changed:
src/compiletest/runtest.rs
src/libextra/ebml.rs
src/libextra/test.rs
src/librustc/back/archive.rs
src/librustc/metadata/tydecode.rs
src/librustc/metadata/tyencode.rs
src/librustdoc/html/markdown.rs
src/librustpkg/lib.rs
src/librustpkg/tests.rs
src/librustpkg/version.rs
src/librustuv/file.rs
src/libstd/c_str.rs
src/libstd/fmt/mod.rs
src/libstd/io/fs.rs
src/libstd/io/mod.rs
src/libstd/io/process.rs
src/libstd/path/mod.rs
src/libstd/path/posix.rs
src/libstd/str.rs
src/test/run-pass/hashmap-memory.rs

index bbfba84cc9e6622d5e5e63b12eda8fd87a59b5c7..7fede7f855d12c319249bf75f33e374bfe04e7f7 100644 (file)
@@ -308,7 +308,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
 
             let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
                                   config.adb_test_dir.clone(), config.adb_test_dir.clone(),
-                                  str::from_utf8(exe_file.filename().unwrap()));
+                                  str::from_utf8(exe_file.filename().unwrap()).unwrap());
 
             let mut process = procsrv::run_background("", config.adb_path,
                                                       [~"shell",adb_arg.clone()],
index 8cce47b03f80b178aa971a7bd79598066abcca65..aac8253b8428add2924158e230bc861662771a09 100644 (file)
@@ -30,7 +30,7 @@ pub fn get<'a>(&'a self, tag: uint) -> Doc<'a> {
     }
 
     pub fn as_str_slice<'a>(&'a self) -> &'a str {
-        str::from_utf8(self.data.slice(self.start, self.end))
+        str::from_utf8(self.data.slice(self.start, self.end)).unwrap()
     }
 
     pub fn as_str(&self) -> ~str {
index 5f0270beb80e5b298246613df424936c769703f5..1b98a9af548ae69064db118a6e76a25dc62a5e26 100644 (file)
@@ -704,7 +704,7 @@ fn should_sort_failures_before_printing_them() {
 
     st.write_failures();
     let s = match st.out {
-        Raw(ref m) => str::from_utf8(m.get_ref()),
+        Raw(ref m) => str::from_utf8(m.get_ref()).unwrap(),
         Pretty(_) => unreachable!()
     };
 
index 5f1542f750116702615a0e47230c922d70e7eac8..661ae5b7297b2fd0c8293db433569c1a132407a5 100644 (file)
@@ -57,8 +57,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
             if !o.status.success() {
                 sess.err(format!("{} {} failed with: {}", ar, args.connect(" "),
                                  o.status));
-                sess.note(format!("stdout ---\n{}", str::from_utf8(o.output)));
-                sess.note(format!("stderr ---\n{}", str::from_utf8(o.error)));
+                sess.note(format!("stdout ---\n{}", str::from_utf8(o.output).unwrap()));
+                sess.note(format!("stderr ---\n{}", str::from_utf8(o.error).unwrap()));
                 sess.abort_if_errors();
             }
             o
@@ -141,7 +141,7 @@ pub fn update_symbols(&mut self) {
     /// Lists all files in an archive
     pub fn files(&self) -> ~[~str] {
         let output = run_ar(self.sess, "t", None, [&self.dst]);
-        str::from_utf8(output.output).lines().map(|s| s.to_owned()).collect()
+        str::from_utf8(output.output).unwrap().lines().map(|s| s.to_owned()).collect()
     }
 
     fn add_archive(&mut self, archive: &Path, name: &str, skip: &[&str]) {
index 1f33ef2f41be6790ee63b3ea9f3783e68512a3a4..4f19d461c854c7216d0f42fc67a8d4407e0f6199 100644 (file)
@@ -97,7 +97,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
 
 fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
     scan(st, is_last, |bytes| {
-            st.tcx.sess.ident_of(str::from_utf8(bytes))
+            st.tcx.sess.ident_of(str::from_utf8(bytes).unwrap())
         })
 }
 
@@ -476,7 +476,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
     let mut abis = AbiSet::empty();
     while peek(st) != ']' {
          scan(st, |c| c == ',', |bytes| {
-                 let abi_str = str::from_utf8(bytes).to_owned();
+                 let abi_str = str::from_utf8(bytes).unwrap().to_owned();
                  let abi = abi::lookup(abi_str).expect(abi_str);
                  abis.add(abi);
               });
index 657522b836b3adc1e14821c99ec261a17e513238..965aab31f142682272e137bdd637d64aa3ac8146 100644 (file)
@@ -72,7 +72,7 @@ pub fn enc_ty(w: &mut MemWriter, cx: @ctxt, t: ty::t) {
             None => {
                 let wr = &mut MemWriter::new();
                 enc_sty(wr, cx, &ty::get(t).sty);
-                let s = str::from_utf8(wr.get_ref()).to_managed();
+                let s = str::from_utf8(wr.get_ref()).unwrap().to_managed();
                 let mut short_names_cache = cx.tcx
                                               .short_names_cache
                                               .borrow_mut();
index 8fa8b573bca93f3d832d350da5ec3b5b6e7c376e..5d0728c8cdf77c6ff4ac6df1216a8f53d1ab6830 100644 (file)
@@ -112,7 +112,7 @@ pub fn render(w: &mut io::Writer, s: &str) {
         unsafe {
             let my_opaque: &my_opaque = cast::transmute(opaque);
             vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
-                let text = str::from_utf8(text);
+                let text = str::from_utf8(text).unwrap();
                 let mut lines = text.lines().filter(|l| stripped_filtered_line(*l).is_none());
                 let text = lines.to_owned_vec().connect("\n");
 
@@ -172,14 +172,14 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
             let (test, shouldfail, ignore) =
                 vec::raw::buf_as_slice((*lang).data,
                                        (*lang).size as uint, |lang| {
-                    let s = str::from_utf8(lang);
+                    let s = str::from_utf8(lang).unwrap();
                     (s.contains("rust"), s.contains("should_fail"),
                      s.contains("ignore"))
                 });
             if !test { return }
             vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
                 let tests: &mut ::test::Collector = intrinsics::transmute(opaque);
-                let text = str::from_utf8(text);
+                let text = str::from_utf8(text).unwrap();
                 let mut lines = text.lines().map(|l| stripped_filtered_line(l).unwrap_or(l));
                 let text = lines.to_owned_vec().connect("\n");
                 tests.add_test(text, ignore, shouldfail);
index ac94c477e7836bfe2b4e578423f1d6af5a98b873..c9db8af0b8a9ce17e9b5547a93e2a521515b0456 100644 (file)
@@ -193,7 +193,7 @@ fn run_custom(exe: &Path, sysroot: &Path) -> Option<(~[~str], process::ProcessEx
                         Some(output) => {
                             debug!("run_custom: second pkg command did {:?}", output.status);
                             // Run the configs() function to get the configs
-                            let cfgs = str::from_utf8(output.output).words()
+                            let cfgs = str::from_utf8(output.output).unwrap().words()
                                 .map(|w| w.to_owned()).collect();
                             Some((cfgs, output.status))
                         },
index 0e78e907de052e0a9257bee961da4963c66e57f3..b2cc568ee5e60d89097b38c9bdce94abc00e2917 100644 (file)
@@ -143,7 +143,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
     let rslt = prog.finish_with_output();
     if !rslt.status.success() {
         fail!("{} [git returned {:?}, output = {}, error = {}]", err_msg,
-           rslt.status, str::from_utf8(rslt.output), str::from_utf8(rslt.error));
+           rslt.status, str::from_utf8(rslt.output).unwrap(), str::from_utf8(rslt.error).unwrap());
     }
 }
 
@@ -279,13 +279,13 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
     }).expect(format!("failed to exec `{}`", cmd));
     let output = prog.finish_with_output();
     debug!("Output from command {} with args {:?} was {} \\{{}\\}[{:?}]",
-           cmd, args, str::from_utf8(output.output),
-           str::from_utf8(output.error),
+           cmd, args, str::from_utf8(output.output).unwrap(),
+           str::from_utf8(output.error).unwrap(),
            output.status);
     if !output.status.success() {
         debug!("Command {} {:?} failed with exit code {:?}; its output was --- {} {} ---",
               cmd, args, output.status,
-              str::from_utf8(output.output), str::from_utf8(output.error));
+              str::from_utf8(output.output).unwrap(), str::from_utf8(output.error).unwrap());
         Fail(output)
     }
     else {
@@ -445,7 +445,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool {
 fn command_line_test_output(args: &[~str]) -> ~[~str] {
     let mut result = ~[];
     let p_output = command_line_test(args, &os::getcwd());
-    let test_output = str::from_utf8(p_output.output);
+    let test_output = str::from_utf8(p_output.output).unwrap();
     for s in test_output.split('\n') {
         result.push(s.to_owned());
     }
@@ -459,7 +459,7 @@ fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~
         Fail(_) => fail!("Command-line test failed"),
         Success(r) => r
     };
-    let test_output = str::from_utf8(p_output.output);
+    let test_output = str::from_utf8(p_output.output).unwrap();
     for s in test_output.split('\n') {
         result.push(s.to_owned());
     }
@@ -1199,7 +1199,7 @@ fn test_uninstall() {
     let workspace = create_local_package(&CrateId::new("foo"));
     command_line_test([~"uninstall", ~"foo"], workspace.path());
     let output = command_line_test([~"list"], workspace.path());
-    assert!(!str::from_utf8(output.output).contains("foo"));
+    assert!(!str::from_utf8(output.output).unwrap().contains("foo"));
 }
 
 #[test]
@@ -1269,8 +1269,8 @@ fn test_extern_mod() {
     let outp = prog.finish_with_output();
     if !outp.status.success() {
         fail!("output was {}, error was {}",
-              str::from_utf8(outp.output),
-              str::from_utf8(outp.error));
+              str::from_utf8(outp.output).unwrap(),
+              str::from_utf8(outp.error).unwrap());
     }
     assert!(exec_file.exists() && is_executable(&exec_file));
 }
@@ -1324,8 +1324,8 @@ fn test_extern_mod_simpler() {
     let outp = prog.finish_with_output();
     if !outp.status.success() {
         fail!("output was {}, error was {}",
-              str::from_utf8(outp.output),
-              str::from_utf8(outp.error));
+              str::from_utf8(outp.output).unwrap(),
+              str::from_utf8(outp.error).unwrap());
     }
     assert!(exec_file.exists() && is_executable(&exec_file));
 }
@@ -2092,7 +2092,7 @@ fn test_rustpkg_test_creates_exec() {
 fn test_rustpkg_test_output() {
     let workspace = create_local_package_with_test(&CrateId::new("foo"));
     let output = command_line_test([~"test", ~"foo"], workspace.path());
-    let output_str = str::from_utf8(output.output);
+    let output_str = str::from_utf8(output.output).unwrap();
     // The first two assertions are separate because test output may
     // contain color codes, which could appear between "test f" and "ok".
     assert!(output_str.contains("test f"));
@@ -2123,7 +2123,7 @@ fn test_rustpkg_test_cfg() {
               "#[test] #[cfg(not(foobar))] fn f() { assert!('a' != 'a'); }");
     let output = command_line_test([~"test", ~"--cfg", ~"foobar", ~"foo"],
                                    foo_workspace);
-    let output_str = str::from_utf8(output.output);
+    let output_str = str::from_utf8(output.output).unwrap();
     assert!(output_str.contains("0 passed; 0 failed; 0 ignored; 0 measured"));
 }
 
@@ -2424,8 +2424,8 @@ fn correct_error_dependency() {
         Fail(ProcessOutput{ error: error, output: output, .. }) => {
             assert!(str::is_utf8(error));
             assert!(str::is_utf8(output));
-            let error_str = str::from_utf8(error);
-            let out_str   = str::from_utf8(output);
+            let error_str = str::from_utf8(error).unwrap();
+            let out_str   = str::from_utf8(output).unwrap();
             debug!("ss = {}", error_str);
             debug!("out_str = {}", out_str);
             if out_str.contains("Package badpkg depends on some_package_that_doesnt_exist") &&
index e9ccfccb126a1b3a71893f8a92d15efe18eebe9d..77dbb33551808351ab15a2fcf04833d7c5c9057b 100644 (file)
@@ -115,7 +115,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
         }
 
         let mut output = None;
-        let output_text = str::from_utf8(outp.output);
+        let output_text = str::from_utf8(outp.output).unwrap();
         for l in output_text.lines() {
             if !l.is_whitespace() {
                 output = Some(l);
@@ -147,8 +147,8 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
         let outp = opt_outp.expect("Failed to exec `git`");
         if outp.status.success() {
             debug!("Cloned it... ( {}, {} )",
-                   str::from_utf8(outp.output),
-                   str::from_utf8(outp.error));
+                   str::from_utf8(outp.output).unwrap(),
+                   str::from_utf8(outp.error).unwrap());
             let mut output = None;
             let git_dir = tmp_dir.join(".git");
             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> {
                                                ["--git-dir=" + git_dir.as_str().unwrap(),
                                                 ~"tag", ~"-l"]);
             let outp = opt_outp.expect("Failed to exec `git`");
-            let output_text = str::from_utf8(outp.output);
+            let output_text = str::from_utf8(outp.output).unwrap();
             debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
             for l in output_text.lines() {
                 debug!("A line of output: {}", l);
index 82d0fd823a32078d56ccf2a683ecb9759c579884..8f7ced93fb0c6a7defbc7fa3e19a65d3a99dd90c 100644 (file)
@@ -488,7 +488,7 @@ fn file_test_full_simple_sync() {
 
             let nread = result.unwrap();
             assert!(nread > 0);
-            let read_str = str::from_utf8(read_mem.slice_to(nread as uint));
+            let read_str = str::from_utf8(read_mem.slice_to(nread as uint)).unwrap();
             assert_eq!(read_str, "hello");
         }
         // unlink
index 301df329f49eea81c37bf6ff8ef5bd058471fe8a..c735e325068247e0ed7bfaefa70a16081beed8c6 100644 (file)
@@ -167,7 +167,7 @@ pub fn as_str<'a>(&'a self) -> Option<&'a str> {
         if self.buf.is_null() { return None; }
         let buf = self.as_bytes();
         let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL
-        str::from_utf8_opt(buf)
+        str::from_utf8(buf)
     }
 
     /// Return a CString iterator.
index 8a945d09bfcffa4cede9334749fb5620c05261de..4bee1f42b86cdebd9bd2eebffc8cecccde053546 100644 (file)
@@ -812,7 +812,7 @@ fn execute(&mut self, method: &rt::Method, arg: Argument) {
 
     fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) {
         ::uint::to_str_bytes(value, 10, |buf| {
-            let valuestr = str::from_utf8(buf);
+            let valuestr = str::from_utf8(buf).unwrap();
             for piece in pieces.iter() {
                 self.run(piece, Some(valuestr));
             }
index 80dbaebe01c042a65da92f505f8e15dda237133d..0564311ad2270df38c7644041ca137ecb09b91fa 100644 (file)
@@ -805,7 +805,7 @@ pub fn tmpdir() -> TempDir {
             }
         }
         unlink(filename);
-        let read_str = str::from_utf8(read_mem);
+        let read_str = str::from_utf8(read_mem).unwrap();
         assert_eq!(read_str, message);
     })
 
@@ -829,7 +829,7 @@ pub fn tmpdir() -> TempDir {
             tell_pos_post_read = read_stream.tell();
         }
         unlink(filename);
-        let read_str = str::from_utf8(read_mem);
+        let read_str = str::from_utf8(read_mem).unwrap();
         assert_eq!(read_str, message.slice(4, 8));
         assert_eq!(tell_pos_pre_read, set_cursor);
         assert_eq!(tell_pos_post_read, message.len() as u64);
@@ -854,7 +854,7 @@ pub fn tmpdir() -> TempDir {
             read_stream.read(read_mem);
         }
         unlink(filename);
-        let read_str = str::from_utf8(read_mem);
+        let read_str = str::from_utf8(read_mem).unwrap();
         assert!(read_str == final_msg.to_owned());
     })
 
@@ -876,15 +876,15 @@ pub fn tmpdir() -> TempDir {
 
             read_stream.seek(-4, SeekEnd);
             read_stream.read(read_mem);
-            assert_eq!(str::from_utf8(read_mem), chunk_three);
+            assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_three);
 
             read_stream.seek(-9, SeekCur);
             read_stream.read(read_mem);
-            assert_eq!(str::from_utf8(read_mem), chunk_two);
+            assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_two);
 
             read_stream.seek(0, SeekSet);
             read_stream.read(read_mem);
-            assert_eq!(str::from_utf8(read_mem), chunk_one);
+            assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_one);
         }
         unlink(filename);
     })
@@ -958,7 +958,7 @@ pub fn tmpdir() -> TempDir {
             {
                 let n = f.filestem_str();
                 File::open(f).read(mem);
-                let read_str = str::from_utf8(mem);
+                let read_str = str::from_utf8(mem).unwrap();
                 let expected = match n {
                     None|Some("") => fail!("really shouldn't happen.."),
                     Some(n) => prefix+n
index 871809805418d5c17ef113b8c2f139d4ed311be5..b12adbf230fd0597c3c2f0b5369579acb0cc3581 100644 (file)
@@ -1202,7 +1202,7 @@ fn read_char(&mut self) -> Option<char> {
                 }
             }
         }
-        match str::from_utf8_opt(buf.slice_to(width)) {
+        match str::from_utf8(buf.slice_to(width)) {
             Some(s) => Some(s.char_at(0)),
             None => None
         }
index a0c451647d34ac04caff8bd5f62208339c64fa17..c3fb3e97edfde7f8fef9fde17c3182f694342b2b 100644 (file)
@@ -254,7 +254,7 @@ pub fn read_all(input: &mut Reader) -> ~str {
         loop {
             match input.read(buf) {
                 None => { break }
-                Some(n) => { ret.push_str(str::from_utf8(buf.slice_to(n))); }
+                Some(n) => { ret.push_str(str::from_utf8(buf.slice_to(n)).unwrap()); }
             }
         }
         return ret;
index b2de3cd9178c440a487777a788c0805c16f07b6a..6464d6021ee53e3adf3b2f30822bf05ff9781b6d 100644 (file)
@@ -189,7 +189,7 @@ fn new_opt<T: BytesContainer>(path: T) -> Option<Self> {
     /// If the path is not representable in utf-8, this returns None.
     #[inline]
     fn as_str<'a>(&'a self) -> Option<&'a str> {
-        str::from_utf8_opt(self.as_vec())
+        str::from_utf8(self.as_vec())
     }
 
     /// Returns the path as a byte vector
@@ -220,7 +220,7 @@ fn filename_display<'a>(&'a self) -> Display<'a, Self> {
     /// See `dirname` for details.
     #[inline]
     fn dirname_str<'a>(&'a self) -> Option<&'a str> {
-        str::from_utf8_opt(self.dirname())
+        str::from_utf8(self.dirname())
     }
     /// Returns the file component of `self`, as a byte vector.
     /// If `self` represents the root of the file hierarchy, returns None.
@@ -230,7 +230,7 @@ fn dirname_str<'a>(&'a self) -> Option<&'a str> {
     /// See `filename` for details.
     #[inline]
     fn filename_str<'a>(&'a self) -> Option<&'a str> {
-        self.filename().and_then(str::from_utf8_opt)
+        self.filename().and_then(str::from_utf8)
     }
     /// Returns the stem of the filename of `self`, as a byte vector.
     /// The stem is the portion of the filename just before the last '.'.
@@ -252,7 +252,7 @@ fn filestem<'a>(&'a self) -> Option<&'a [u8]> {
     /// See `filestem` for details.
     #[inline]
     fn filestem_str<'a>(&'a self) -> Option<&'a str> {
-        self.filestem().and_then(str::from_utf8_opt)
+        self.filestem().and_then(str::from_utf8)
     }
     /// Returns the extension of the filename of `self`, as an optional byte vector.
     /// The extension is the portion of the filename just after the last '.'.
@@ -275,7 +275,7 @@ fn extension<'a>(&'a self) -> Option<&'a [u8]> {
     /// See `extension` for details.
     #[inline]
     fn extension_str<'a>(&'a self) -> Option<&'a str> {
-        self.extension().and_then(str::from_utf8_opt)
+        self.extension().and_then(str::from_utf8)
     }
 
     /// Replaces the filename portion of the path with the given byte vector or string.
@@ -502,7 +502,7 @@ fn container_into_owned_bytes(self) -> ~[u8] {
     /// Returns the receiver interpreted as a utf-8 string, if possible
     #[inline]
     fn container_as_str<'a>(&'a self) -> Option<&'a str> {
-        str::from_utf8_opt(self.container_as_bytes())
+        str::from_utf8(self.container_as_bytes())
     }
     /// Returns whether .container_as_str() is guaranteed to not fail
     // FIXME (#8888): Remove unused arg once ::<for T> works
index dc547d702ba29e5da9c28fa9df31500017465b8e..e95bd2d8ca2f3ddfd7dcbcd3ae87e51f0b1a4f09 100644 (file)
@@ -402,13 +402,13 @@ pub fn rev_components<'a>(&'a self) -> RevComponents<'a> {
     /// Returns an iterator that yields each component of the path as Option<&str>.
     /// See components() for details.
     pub fn str_components<'a>(&'a self) -> StrComponents<'a> {
-        self.components().map(str::from_utf8_opt)
+        self.components().map(str::from_utf8)
     }
 
     /// Returns an iterator that yields each component of the path in reverse as Option<&str>.
     /// See components() for details.
     pub fn rev_str_components<'a>(&'a self) -> RevStrComponents<'a> {
-        self.rev_components().map(str::from_utf8_opt)
+        self.rev_components().map(str::from_utf8)
     }
 }
 
@@ -691,7 +691,7 @@ macro_rules! t(
             (s: $path:expr, $op:ident, $exp:expr, opt) => (
                 {
                     let path = Path::new($path);
-                    let left = path.$op().map(|x| str::from_utf8(x));
+                    let left = path.$op().map(|x| str::from_utf8(x).unwrap());
                     assert_eq!(left, $exp);
                 }
             );
index f59cd855c32c940076b6126ab2f6c50002e553e6..c266ddfea4b924df3174ad464033f8c19edf036a 100644 (file)
@@ -161,17 +161,8 @@ pub fn from_utf8_owned_opt(vv: ~[u8]) -> Option<~str> {
 /// Once the slice has been validated as utf-8, it is transmuted in-place and
 /// returned as a '&str' instead of a '&[u8]'
 ///
-/// # Failure
-///
-/// Fails if invalid UTF-8
-pub fn from_utf8<'a>(v: &'a [u8]) -> &'a str {
-    from_utf8_opt(v).expect("from_utf8: not utf-8")
-}
-
-/// Converts a vector to a string slice without performing any allocations.
-///
 /// Returns None if the slice is not utf-8.
-pub fn from_utf8_opt<'a>(v: &'a [u8]) -> Option<&'a str> {
+pub fn from_utf8<'a>(v: &'a [u8]) -> Option<&'a str> {
     if is_utf8(v) {
         Some(unsafe { raw::from_utf8(v) })
     } else { None }
@@ -3436,7 +3427,7 @@ fn vec_str_conversions() {
         let s1: ~str = ~"All mimsy were the borogoves";
 
         let v: ~[u8] = s1.as_bytes().to_owned();
-        let s2: ~str = from_utf8(v).to_owned();
+        let s2: ~str = from_utf8(v).unwrap().to_owned();
         let mut i: uint = 0u;
         let n1: uint = s1.len();
         let n2: uint = v.len();
@@ -3961,29 +3952,13 @@ fn test_str_truncate_split_codepoint() {
     #[test]
     fn test_str_from_utf8() {
         let xs = bytes!("hello");
-        assert_eq!(from_utf8(xs), "hello");
-
-        let xs = bytes!("ศไทย中华Việt Nam");
-        assert_eq!(from_utf8(xs), "ศไทย中华Việt Nam");
-    }
-
-    #[test]
-    #[should_fail]
-    fn test_str_from_utf8_invalid() {
-        let xs = bytes!("hello", 0xff);
-        let _ = from_utf8(xs);
-    }
-
-    #[test]
-    fn test_str_from_utf8_opt() {
-        let xs = bytes!("hello");
-        assert_eq!(from_utf8_opt(xs), Some("hello"));
+        assert_eq!(from_utf8(xs), Some("hello"));
 
         let xs = bytes!("ศไทย中华Việt Nam");
-        assert_eq!(from_utf8_opt(xs), Some("ศไทย中华Việt Nam"));
+        assert_eq!(from_utf8(xs), Some("ศไทย中华Việt Nam"));
 
         let xs = bytes!("hello", 0xff);
-        assert_eq!(from_utf8_opt(xs), None);
+        assert_eq!(from_utf8(xs), None);
     }
 
     #[test]
index 905fa42635b9be59ff0e879c68d3192ff2dc5735..96a6e1c4f6061973fa227443fe5ca9a4ef172c71 100644 (file)
@@ -81,7 +81,7 @@ pub fn map_reduce(inputs: ~[~str]) {
               mapper_done => { num_mappers -= 1; }
               find_reducer(k, cc) => {
                 let mut c;
-                match reducers.find(&str::from_utf8(k).to_owned()) {
+                match reducers.find(&str::from_utf8(k).unwrap().to_owned()) {
                   Some(&_c) => { c = _c; }
                   None => { c = 0; }
                 }