about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-04-14 10:55:41 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-04-14 10:55:41 -0700
commit34603b0c19f134f446dc3180a02212b7839f316a (patch)
treeb5455b3f215a58c4c8bda114cec79a5b44e26949 /src/libcollections
parent88a145ea36967f8afb920af4e096113271432fc5 (diff)
parentf329030b095aa30ce29be0c3459615d85506747b (diff)
downloadrust-34603b0c19f134f446dc3180a02212b7839f316a.tar.gz
rust-34603b0c19f134f446dc3180a02212b7839f316a.zip
rollup merge of #24310: alexcrichton/stabilize-utf8-error
The meaning of each variant of this enum was somewhat ambiguous and it's uncler
that we wouldn't even want to add more enumeration values in the future. As a
result this error has been altered to instead become an opaque structure.
Learning about the "first invalid byte index" is still an unstable feature, but
the type itself is now stable.
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/lib.rs1
-rw-r--r--src/libcollections/string.rs16
2 files changed, 7 insertions, 10 deletions
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs
index 7658611d809..5179b04f882 100644
--- a/src/libcollections/lib.rs
+++ b/src/libcollections/lib.rs
@@ -40,6 +40,7 @@
 #![feature(str_char)]
 #![feature(slice_patterns)]
 #![feature(debug_builders)]
+#![feature(utf8_error)]
 #![cfg_attr(test, feature(rand, rustc_private, test, hash, collections))]
 #![cfg_attr(test, allow(deprecated))] // rand
 
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index 441d0f2c5df..9c9f2d628b8 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -132,7 +132,7 @@ impl String {
     ///
     /// let invalid_vec = vec![240, 144, 128];
     /// let s = String::from_utf8(invalid_vec).err().unwrap();
-    /// assert_eq!(s.utf8_error(), Utf8Error::TooShort);
+    /// let err = s.utf8_error();
     /// assert_eq!(s.into_bytes(), [240, 144, 128]);
     /// ```
     #[inline]
@@ -156,14 +156,10 @@ impl String {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
-        let mut i = 0;
+        let mut i;
         match str::from_utf8(v) {
             Ok(s) => return Cow::Borrowed(s),
-            Err(e) => {
-                if let Utf8Error::InvalidByte(firstbad) = e {
-                    i = firstbad;
-                }
-            }
+            Err(e) => i = e.valid_up_to(),
         }
 
         const TAG_CONT_U8: u8 = 128;
@@ -188,9 +184,9 @@ impl String {
             };
         }
 
-        // subseqidx is the index of the first byte of the subsequence we're looking at.
-        // It's used to copy a bunch of contiguous good codepoints at once instead of copying
-        // them one by one.
+        // subseqidx is the index of the first byte of the subsequence we're
+        // looking at.  It's used to copy a bunch of contiguous good codepoints
+        // at once instead of copying them one by one.
         let mut subseqidx = i;
 
         while i < total {