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;
4242pub use vec_deque:: VecDeque ;
4343
4444use crate :: alloc:: { Layout , LayoutErr } ;
45+ use core:: fmt:: Display ;
4546
4647/// The error type for `try_reserve` methods.
4748#[ derive( Clone , PartialEq , Eq , Debug ) ]
@@ -77,6 +78,22 @@ impl From<LayoutErr> for TryReserveError {
7778 }
7879}
7980
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+
8097/// An intermediate trait for specialization of `Extend`.
8198#[ doc( hidden) ]
8299trait SpecExtend < I : IntoIterator > {
Original file line number Diff line number Diff line change @@ -552,6 +552,13 @@ impl Error for char::ParseCharError {
552552 }
553553}
554554
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+
555562// Copied from `any.rs`.
556563impl dyn Error + ' static {
557564 /// Returns `true` if the boxed type is the same as `T`
You can’t perform that action at this time.
0 commit comments