Skip to content

Commit 4346943

Browse files
committed
Rust bug: error when: higher ranked lifetime, assert Send;
```rust error: implementation of `MapApiRO` is not general enough --> src/data/impl_static_levels.rs:138:22 | 138 | let fu = assert_sync(fu); | ^^^^^^^^^^^^^^^ implementation of `MapApiRO` is not general enough | = note: `MapApiRO<String>` would have to be implemented for the type `&'0 Level`, for any lifetime `'0`... = note: ...but `MapApiRO<String>` is actually implemented for the type `&'1 Level`, for some specific lifetime `'1` ``` rust-lang/rust#100013 rust-lang/rust#114046 rust-lang/rust#110338
1 parent b229c49 commit 4346943

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

src/data/impl_level.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl<'me> MapApi<'me, String> for &'me mut Level {
9898
mod tests {
9999
use crate::map_api::MapApi;
100100
use crate::map_api::MapApiRO;
101+
use crate::util::assert_send;
101102
use crate::Level;
102103
use crate::Val;
103104

@@ -119,5 +120,11 @@ mod tests {
119120

120121
let got = d.get(&k()).await;
121122
assert_eq!(got, Val(2));
123+
124+
/////////////
125+
126+
let x = k();
127+
let fu = d.get(x.as_str());
128+
let fu = assert_send(fu);
122129
}
123130
}

src/data/impl_level_map.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ mod tests {
152152
// let x = k();
153153
// let fu = lm.get(x.as_str());
154154
//
155-
// let fu = foo(fu);
156-
//
157-
// fn foo<T: Send>(v: T) -> T {
158-
// v
159-
// }
155+
// let fu = assert_send(fu);
160156
}
161157
}
162158
}

src/data/impl_ref.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ mod tests {
9292
use futures_util::StreamExt;
9393

9494
use crate::map_api::MapApiRO;
95+
use crate::util::assert_send;
96+
use crate::util::assert_sync;
9597
use crate::Level;
9698
use crate::Ref;
9799
use crate::StaticLevels;
@@ -140,5 +142,14 @@ mod tests {
140142
let got = { r }.range(k()..).await.collect::<Vec<_>>().await;
141143
assert_eq!(got, vec![(k(), Val(3)), (k(), Val(2))]);
142144
}
145+
146+
// TODO: Error:
147+
// {
148+
// let r = Ref::new(&d, &static_levels);
149+
//
150+
// let x = k();
151+
// let fu = r.get(x.as_str());
152+
// let fu = assert_sync(fu);
153+
// }
143154
}
144155
}

src/data/impl_static_levels.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ where
8585

8686
#[cfg(test)]
8787
mod tests {
88+
use std::os::macos::raw::stat;
8889
use std::sync::Arc;
8990

9091
use futures_util::StreamExt;
9192

9293
use crate::map_api::MapApiRO;
94+
use crate::util::assert_sync;
9395
use crate::Level;
9496
use crate::StaticLevels;
9597
use crate::Val;
@@ -129,5 +131,11 @@ mod tests {
129131
let got = static_levels.get(&k()).await;
130132
assert_eq!(got, Val(2));
131133
}
134+
135+
{
136+
let x = k();
137+
let fu = static_levels.get(x.as_str());
138+
let fu = assert_sync(fu);
139+
}
132140
}
133141
}

src/util.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ pub fn by_key_seq<K, V>((k1, _v1): &(K, V), (k2, _v2): &(K, V)) -> bool
44
where K: MapKey {
55
k1 <= k2
66
}
7+
8+
pub fn assert_send<T: Send>(v: T) -> T {
9+
v
10+
}
11+
12+
pub fn assert_sync<T: Sync>(v: T) -> T {
13+
v
14+
}

0 commit comments

Comments
 (0)