File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ pub use linked_list::LinkedList;
42
42
pub use vec_deque:: VecDeque ;
43
43
44
44
use crate :: alloc:: { Layout , LayoutErr } ;
45
+ use core:: fmt:: Display ;
45
46
46
47
/// The error type for `try_reserve` methods.
47
48
#[ derive( Clone , PartialEq , Eq , Debug ) ]
@@ -77,6 +78,22 @@ impl From<LayoutErr> for TryReserveError {
77
78
}
78
79
}
79
80
81
+ #[ unstable( feature = "try_reserve" , reason = "new API" , issue = "48043" ) ]
82
+ impl Display for TryReserveError {
83
+ fn fmt (
84
+ & self ,
85
+ fmt : & mut core:: fmt:: Formatter < ' _ > ,
86
+ ) -> core:: result:: Result < ( ) , core:: fmt:: Error > {
87
+ fmt. write_str ( "memory allocation failed" ) ?;
88
+ fmt. write_str ( match & self {
89
+ TryReserveError :: CapacityOverflow => {
90
+ " because the computed capacity exceeded the collection's maximum"
91
+ }
92
+ TryReserveError :: AllocError { .. } => " because the memory allocator returned a error" ,
93
+ } )
94
+ }
95
+ }
96
+
80
97
/// An intermediate trait for specialization of `Extend`.
81
98
#[ doc( hidden) ]
82
99
trait SpecExtend < I : IntoIterator > {
Original file line number Diff line number Diff line change @@ -552,6 +552,13 @@ impl Error for char::ParseCharError {
552
552
}
553
553
}
554
554
555
+ #[ unstable( feature = "try_reserve" , reason = "new API" , issue = "48043" ) ]
556
+ impl Error for alloc:: collections:: TryReserveError {
557
+ fn description ( & self ) -> & str {
558
+ "memory allocation failed"
559
+ }
560
+ }
561
+
555
562
// Copied from `any.rs`.
556
563
impl dyn Error + ' static {
557
564
/// Returns `true` if the boxed type is the same as `T`
You can’t perform that action at this time.
0 commit comments