@@ -60,15 +60,25 @@ pub use crate::alloc::{AllocError, Global, GlobalAlloc, Layout, LayoutError};
60
60
/// [*currently allocated*]: #currently-allocated-memory
61
61
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
62
62
pub unsafe trait Allocator : crate :: alloc:: Allocator {
63
+ #[ cfg( not( no_global_oom_handling) ) ]
63
64
#[ must_use] // Doesn't actually work
64
- type Result < T , E >
65
+ type Result < T , E : Error >
65
66
where
66
- E : Error + IntoLayout ;
67
+ E : IntoLayout ;
67
68
69
+ #[ cfg( not( no_global_oom_handling) ) ]
68
70
#[ must_use]
69
- fn map_result < T , E > ( result : Result < T , E > ) -> Self :: Result < T , E >
71
+ fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E >
70
72
where
71
- E : Error + IntoLayout ;
73
+ E : IntoLayout ;
74
+
75
+ #[ cfg( no_global_oom_handling) ]
76
+ #[ must_use] // Doesn't actually work
77
+ type Result < T , E : Error > ;
78
+
79
+ #[ cfg( no_global_oom_handling) ]
80
+ #[ must_use]
81
+ fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E > ;
72
82
}
73
83
74
84
#[ cfg( not( no_global_oom_handling) ) ]
@@ -84,15 +94,15 @@ pub(crate) fn capacity_overflow() -> ! {
84
94
panic ! ( "capacity overflow" ) ;
85
95
}
86
96
97
+ #[ cfg( not( no_global_oom_handling) ) ]
87
98
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
88
99
pub trait IntoLayout {
89
- #[ cfg( not( no_global_oom_handling) ) ]
90
100
fn into_layout ( self ) -> Layout ;
91
101
}
92
102
103
+ #[ cfg( not( no_global_oom_handling) ) ]
93
104
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
94
105
impl IntoLayout for TryReserveError {
95
- #[ cfg( not( no_global_oom_handling) ) ]
96
106
fn into_layout ( self ) -> Layout {
97
107
match self . kind ( ) {
98
108
TryReserveErrorKind :: CapacityOverflow => capacity_overflow ( ) ,
@@ -104,14 +114,24 @@ impl IntoLayout for TryReserveError {
104
114
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
105
115
#[ cfg( not( no_global_oom_handling) ) ]
106
116
unsafe impl < X : crate :: alloc:: Allocator > Allocator for X {
107
- type Result < T , E > = T
117
+ type Result < T , E : Error > = T
108
118
where
109
- E : Error + IntoLayout ;
119
+ E : IntoLayout ;
110
120
111
- fn map_result < T , E > ( result : Result < T , E > ) -> Self :: Result < T , E >
121
+ fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E >
112
122
where
113
- E : Error + IntoLayout ,
123
+ E : IntoLayout ,
114
124
{
115
125
result. unwrap_or_else ( |error| handle_alloc_error ( error. into_layout ( ) ) )
116
126
}
117
127
}
128
+
129
+ #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
130
+ #[ cfg( no_global_oom_handling) ]
131
+ unsafe impl < X : crate :: alloc:: Allocator > Allocator for X {
132
+ type Result < T , E : Error > = Result < T , E > ;
133
+
134
+ fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E > {
135
+ result
136
+ }
137
+ }
0 commit comments