Skip to content

Commit 0b50319

Browse files
Rollup merge of #68738 - kennytm:derive-clone-eq-for-fromutf8error, r=sfackler
Derive Clone + Eq for std::string::FromUtf8Error Implement `Clone` and `Eq` for `std::string::FromUtf8Error`. Both the inner `Vec<u8>` and `std::str::Utf8Error` are also `Clone + Eq`, so I don't see why we shouldn't derive them on `FromUtf8Error` as well. (impl are insta-stable, requiring FCP from T-libs.)
2 parents 6dff769 + 847d5b4 commit 0b50319

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub struct String {
319319
/// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
320320
/// ```
321321
#[stable(feature = "rust1", since = "1.0.0")]
322-
#[derive(Debug)]
322+
#[derive(Debug, Clone, PartialEq, Eq)]
323323
pub struct FromUtf8Error {
324324
bytes: Vec<u8>,
325325
error: Utf8Error,

src/liballoc/tests/string.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ fn test_from_utf8() {
5050

5151
let xs = b"hello\xFF".to_vec();
5252
let err = String::from_utf8(xs).unwrap_err();
53+
assert_eq!(err.as_bytes(), b"hello\xff");
54+
let err_clone = err.clone();
55+
assert_eq!(err, err_clone);
5356
assert_eq!(err.into_bytes(), b"hello\xff".to_vec());
57+
assert_eq!(err_clone.utf8_error().valid_up_to(), 5);
5458
}
5559

5660
#[test]

0 commit comments

Comments
 (0)