Skip to content

Commit cdc4205

Browse files
committed
remove lifetime param, encountered the bug: Higher ranked lifetime error when tryng to see that a future is send. #114046
rust-lang/rust#114046
1 parent 14e6472 commit cdc4205

File tree

4 files changed

+33
-53
lines changed

4 files changed

+33
-53
lines changed

src/meta/raft-store/src/sm_v002/leveled_store/level_data.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,34 @@ impl LevelData {
8282
}
8383
}
8484

85-
impl<'d> MapApiRO<'d, String> for &'d LevelData {
85+
impl<'d> MapApiRO<String> for &'d LevelData {
8686
type GetFut<'f, Q> = impl Future<Output = Marked<<String as MapKey>::V>> + 'f
8787
where
8888
Self: 'f,
89-
'd: 'f,
9089
String: Borrow<Q>,
9190
Q: Ord + Send + Sync + ?Sized,
9291
Q: 'f;
9392

9493
fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
9594
where
96-
// 'd: 'f,
9795
String: Borrow<Q>,
9896
Q: Ord + Send + Sync + ?Sized,
9997
Q: 'f,
10098
{
10199
async move { self.kv.get(key).cloned().unwrap_or(Marked::empty()) }
102100
}
103101

104-
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (String, Marked<<String as MapKey>::V>)>>
102+
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (String, Marked<<String as MapKey>::V>)>> + 'f
105103
where
106104
Self: 'f,
107-
'd: 'f,
108105
String: Borrow<Q>,
109106
R: RangeBounds<Q> + Send + Sync + Clone,
110-
R: 'f,
107+
R: 'f,
111108
Q: Ord + Send + Sync + ?Sized,
112109
Q: 'f;
113110

114111
fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
115112
where
116-
'd: 'f,
117113
String: Borrow<Q>,
118114
Q: Ord + Send + Sync + ?Sized,
119115
R: RangeBounds<Q> + Clone + Send + Sync,
@@ -126,7 +122,7 @@ impl<'d> MapApiRO<'d, String> for &'d LevelData {
126122
}
127123
}
128124

129-
impl<'me> MapApi<'me, String> for &'me mut LevelData {
125+
impl<'me> MapApi<String> for &'me mut LevelData {
130126
type RO<'o> = &'o LevelData where Self: 'o;
131127

132128
fn to_ro<'o>(&'o self) -> Self::RO<'o> {
@@ -143,7 +139,7 @@ impl<'me> MapApi<'me, String> for &'me mut LevelData {
143139
value: Option<(<String as MapKey>::V, Option<KVMeta>)>,
144140
) -> Self::SetFut<'f>
145141
where
146-
'me: 'f,
142+
Self: 'f,
147143
{
148144
// The chance it is the bottom level is very low in a loaded system.
149145
// Thus we always tombstone the key if it is None.
@@ -167,11 +163,10 @@ impl<'me> MapApi<'me, String> for &'me mut LevelData {
167163
}
168164
}
169165

170-
impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
166+
impl<'d> MapApiRO<ExpireKey> for &'d LevelData {
171167
type GetFut<'f, Q> = impl Future<Output = Marked<<ExpireKey as MapKey>::V>> + 'f
172168
where
173169
Self: 'f,
174-
'd: 'f,
175170
ExpireKey: Borrow<Q>,
176171
Q: Ord + Send + Sync + ?Sized,
177172
Q: 'f;
@@ -189,7 +184,6 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
189184
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (ExpireKey, Marked<<ExpireKey as MapKey>::V>)>> + 'f
190185
where
191186
Self: 'f,
192-
'd: 'f,
193187
ExpireKey: Borrow<Q>,
194188
R: RangeBounds<Q> + Send + Sync + Clone,
195189
R: 'f,
@@ -198,7 +192,6 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
198192

199193
fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
200194
where
201-
'd: 'f,
202195
ExpireKey: Borrow<Q>,
203196
Q: Ord + Send + Sync + ?Sized,
204197
R: RangeBounds<Q> + Clone + Send + Sync,
@@ -215,7 +208,7 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
215208
}
216209
}
217210

218-
impl<'me> MapApi<'me, ExpireKey> for &'me mut LevelData {
211+
impl<'me> MapApi<ExpireKey> for &'me mut LevelData {
219212
type RO<'o> = &'o LevelData
220213
where Self: 'o;
221214

src/meta/raft-store/src/sm_v002/leveled_store/leveled_map.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,22 @@ impl<'d> LeveledRef<'d> {
5858
}
5959
}
6060

61-
impl<'d, K> MapApiRO<'d, K> for LeveledRef<'d>
61+
impl<'d, K> MapApiRO<K> for LeveledRef<'d>
6262
where
6363
K: MapKey + fmt::Debug,
64-
// &'d LevelData: MapApiRO<'d, K>,
65-
for<'him> &'him LevelData: MapApiRO<'him, K>,
64+
// &'d LevelData: MapApiRO<K>,
65+
for<'him> &'him LevelData: MapApiRO<K>,
66+
// &'him LevelData: MapApiRO<K>,
6667
{
6768
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
6869
where
6970
Self: 'f,
70-
'd: 'f,
7171
K: Borrow<Q>,
7272
Q: Ord + Send + Sync + ?Sized,
7373
Q: 'f;
7474

7575
fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
7676
where
77-
'd: 'f,
7877
K: Borrow<Q>,
7978
Q: Ord + Send + Sync + ?Sized,
8079
Q: 'f,
@@ -90,10 +89,9 @@ where
9089
}
9190
}
9291

93-
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (K, Marked<K::V>)>>
92+
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (K, Marked<K::V>)>> + 'f
9493
where
9594
Self: 'f,
96-
'd: 'f,
9795
K: Borrow<Q>,
9896
R: RangeBounds<Q> + Send + Sync + Clone,
9997
R:'f,
@@ -102,7 +100,6 @@ where
102100

103101
fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
104102
where
105-
'd: 'f,
106103
K: Borrow<Q>,
107104
R: RangeBounds<Q> + Clone + Send + Sync,
108105
R: 'f,
@@ -176,15 +173,14 @@ impl<'d> LeveledRefMut<'d> {
176173

177174
// Because `LeveledRefMut` has a mut ref of lifetime 'd,
178175
// `self` must outlive 'd otherwise there will be two mut ref.
179-
impl<'d, K> MapApiRO<'d, K> for LeveledRefMut<'d>
176+
impl<'d, K> MapApiRO<K> for LeveledRefMut<'d>
180177
where
181178
K: MapKey,
182-
for<'him> &'him LevelData: MapApiRO<'him, K>,
179+
for<'him> &'him LevelData: MapApiRO<K>,
183180
{
184181
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
185182
where
186183
Self: 'f,
187-
'd: 'f,
188184
K: Borrow<Q>,
189185
Q: Ord + Send + Sync + ?Sized,
190186
Q: 'f;
@@ -209,7 +205,6 @@ where
209205
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (K, Marked<K::V>)>> +'f
210206
where
211207
Self: 'f,
212-
'd: 'f,
213208
K: Borrow<Q>,
214209
R: RangeBounds<Q> + Send + Sync + Clone,
215210
R: 'f,
@@ -227,11 +222,11 @@ where
227222
}
228223
}
229224

230-
impl<'d, K> MapApi<'d, K> for LeveledRefMut<'d>
225+
impl<'d, K> MapApi<K> for LeveledRefMut<'d>
231226
where
232227
K: MapKey,
233-
for<'him> &'him LevelData: MapApiRO<'him, K>,
234-
for<'him> &'him mut LevelData: MapApi<'him, K>,
228+
for<'him> &'him LevelData: MapApiRO<K>,
229+
for<'him> &'him mut LevelData: MapApi<K>,
235230
{
236231
type RO<'o> = LeveledRef<'o>
237232
where Self: 'o;
@@ -342,10 +337,10 @@ impl LeveledMap {
342337
}
343338
}
344339

345-
impl<'d, K> MapApiRO<'d, K> for &'d LeveledMap
340+
impl<'d, K> MapApiRO<K> for &'d LeveledMap
346341
where
347342
K: MapKey + fmt::Debug,
348-
for<'him> &'him LevelData: MapApiRO<'him, K>,
343+
for<'him> &'him LevelData: MapApiRO<K>,
349344
{
350345
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
351346
where
@@ -386,11 +381,11 @@ where
386381
}
387382
}
388383

389-
impl<'me, K> MapApi<'me, K> for &'me mut LeveledMap
384+
impl<'me, K> MapApi<K> for &'me mut LeveledMap
390385
where
391386
K: MapKey,
392-
for<'e> &'e LevelData: MapApiRO<'e, K>,
393-
for<'him> &'him mut LevelData: MapApi<'him, K>,
387+
for<'e> &'e LevelData: MapApiRO<K>,
388+
for<'him> &'him mut LevelData: MapApi<K>,
394389
{
395390
type RO<'o> = LeveledRef<'o>
396391
where Self: 'o;

src/meta/raft-store/src/sm_v002/leveled_store/map_api.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ impl<V> MapValue for V where V: Clone + Send + Sync + Unpin + 'static {}
5757
///
5858
/// There is no lifetime constraint on the trait,
5959
/// and it's the implementation's duty to specify a valid lifetime constraint.
60-
pub(in crate::sm_v002) trait MapApiRO<'d, K>: Send + Sync
60+
pub(in crate::sm_v002) trait MapApiRO<K>: Send + Sync
6161
where K: MapKey
6262
{
6363
type GetFut<'f, Q>: Future<Output = Marked<K::V>>
6464
where
6565
Self: 'f,
66-
'd: 'f,
6766
K: Borrow<Q>,
6867
Q: Ord + Send + Sync + ?Sized,
6968
Q: 'f;
@@ -78,7 +77,6 @@ where K: MapKey
7877
type RangeFut<'f, Q, R>: Future<Output = BoxStream<'f, (K, Marked<K::V>)>>
7978
where
8079
Self: 'f,
81-
'd: 'f,
8280
K: Borrow<Q>,
8381
R: RangeBounds<Q> + Send + Sync + Clone,
8482
R: 'f,
@@ -97,10 +95,10 @@ where K: MapKey
9795
}
9896

9997
/// Provide a read-write key-value map API set, used to access state machine data.
100-
pub(in crate::sm_v002) trait MapApi<'d, K>: MapApiRO<'d, K>
98+
pub(in crate::sm_v002) trait MapApi<K>: MapApiRO<K>
10199
where K: MapKey
102100
{
103-
type RO<'o>: MapApiRO<'o, K>
101+
type RO<'o>: MapApiRO<K>
104102
where Self: 'o;
105103

106104
fn to_ro<'o>(&'o self) -> Self::RO<'o>;
@@ -124,7 +122,7 @@ impl MapApiExt {
124122
) -> (Marked<K::V>, Marked<K::V>)
125123
where
126124
K: MapKey,
127-
&'d mut T: MapApi<'d, K>,
125+
&'d mut T: MapApi<K>,
128126
{
129127
//
130128
let got = s.to_ro().get(&key).await;
@@ -147,7 +145,7 @@ impl MapApiExt {
147145
) -> (Marked<K::V>, Marked<K::V>)
148146
where
149147
K: MapKey,
150-
&'d mut T: MapApi<'d, K>,
148+
&'d mut T: MapApi<K>,
151149
{
152150
let got = s.to_ro().get(&key).await;
153151

@@ -161,37 +159,34 @@ impl MapApiExt {
161159
}
162160
}
163161

164-
impl<'ro_me, 'ro_d, K, T> MapApiRO<'ro_d, K> for &'ro_me mut T
162+
impl<'ro_me, K, T> MapApiRO<K> for &'ro_me mut T
165163
where
166164
K: MapKey,
167-
&'ro_me T: MapApiRO<'ro_d, K>,
165+
&'ro_me T: MapApiRO<K>,
168166
K: Ord + Send + Sync + 'static,
169167
T: Send + Sync,
170168
{
171-
type GetFut<'f, Q> = <&'ro_me T as MapApiRO<'ro_d, K>>::GetFut<'f, Q>
169+
type GetFut<'f, Q> = <&'ro_me T as MapApiRO<K>>::GetFut<'f, Q>
172170
where
173171
Self: 'f,
174172
'ro_me: 'f,
175-
'ro_d: 'f,
176173
K: Borrow<Q>,
177174
Q: Ord + Send + Sync + ?Sized,
178175
Q: 'f;
179176

180177
fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
181178
where
182179
'ro_me: 'f,
183-
'ro_d: 'f,
184180
K: Borrow<Q>,
185181
Q: Ord + Send + Sync + ?Sized,
186182
{
187183
(&*self).get(key)
188184
}
189185

190-
type RangeFut<'f, Q, R> = <&'ro_me T as MapApiRO<'ro_d, K>>::RangeFut<'f, Q, R>
186+
type RangeFut<'f, Q, R> = <&'ro_me T as MapApiRO<K>>::RangeFut<'f, Q, R>
191187
where
192188
Self: 'f,
193189
'ro_me: 'f,
194-
'ro_d: 'f,
195190
K: Borrow<Q>,
196191
R: RangeBounds<Q> + Send + Sync + Clone,
197192
R: 'f,
@@ -201,7 +196,6 @@ where
201196
fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
202197
where
203198
'ro_me: 'f,
204-
'ro_d: 'f,
205199
K: Borrow<Q>,
206200
Q: Ord + Send + Sync + ?Sized,
207201
R: RangeBounds<Q> + Clone + Send + Sync,

src/meta/raft-store/src/sm_v002/leveled_store/static_leveled_map.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,20 @@ impl StaticLeveledMap {
6262
}
6363
}
6464

65-
impl<'d, K> MapApiRO<'d, K> for &'d StaticLeveledMap
65+
impl<'d, K> MapApiRO<K> for &'d StaticLeveledMap
6666
where
6767
K: MapKey,
68-
for<'him> &'him LevelData: MapApiRO<'him, K>,
68+
for<'him> &'him LevelData: MapApiRO<K>,
6969
{
7070
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
7171
where
7272
Self: 'f,
73-
'd: 'f,
7473
K: Borrow<Q>,
7574
Q: Ord + Send + Sync + ?Sized,
7675
Q: 'f;
7776

7877
fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
7978
where
80-
'd: 'f,
8179
K: Borrow<Q>,
8280
Q: Ord + Send + Sync + ?Sized,
8381
Q: 'f,

0 commit comments

Comments
 (0)