Skip to content

Commit e45e8ab

Browse files
committed
Implement Error trait for TryFromSliceError
1 parent a6e70b5 commit e45e8ab

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/libcore/array.rs

+15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
6363
#[derive(Debug, Copy, Clone)]
6464
pub struct TryFromSliceError(());
6565

66+
impl fmt::Display for TryFromSliceError {
67+
#[inline]
68+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69+
fmt::Display::fmt(self.__description())
70+
}
71+
}
72+
73+
impl TryFromSliceError {
74+
#[inline]
75+
#[doc(hidden)]
76+
pub fn __description(&self) -> &str {
77+
"could not convert slice to array"
78+
}
79+
}
80+
6681
macro_rules! __impl_slice_eq1 {
6782
($Lhs: ty, $Rhs: ty) => {
6883
__impl_slice_eq1! { $Lhs, $Rhs, Sized }

src/libstd/error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use any::TypeId;
5656
use borrow::Cow;
5757
use cell;
5858
use char;
59+
use core::array;
5960
use fmt::{self, Debug, Display};
6061
use mem::transmute;
6162
use num;
@@ -281,6 +282,13 @@ impl Error for num::TryFromIntError {
281282
}
282283
}
283284

285+
#[unstable(feature = "try_from", issue = "33417")]
286+
impl Error for array::TryFromSliceError {
287+
fn description(&self) -> &str {
288+
self.__description()
289+
}
290+
}
291+
284292
#[stable(feature = "rust1", since = "1.0.0")]
285293
impl Error for num::ParseFloatError {
286294
fn description(&self) -> &str {

0 commit comments

Comments
 (0)