Skip to content

Commit

Permalink
Rust bug: error when: higher ranked lifetime, assert Send;
Browse files Browse the repository at this point in the history
```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
  • Loading branch information
drmingdrmer committed Sep 27, 2023
1 parent b229c49 commit 4346943
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/data/impl_level.rs
Expand Up @@ -98,6 +98,7 @@ impl<'me> MapApi<'me, String> for &'me mut Level {
mod tests {
use crate::map_api::MapApi;
use crate::map_api::MapApiRO;
use crate::util::assert_send;
use crate::Level;
use crate::Val;

Expand All @@ -119,5 +120,11 @@ mod tests {

let got = d.get(&k()).await;
assert_eq!(got, Val(2));

/////////////

let x = k();
let fu = d.get(x.as_str());
let fu = assert_send(fu);
}
}
6 changes: 1 addition & 5 deletions src/data/impl_level_map.rs
Expand Up @@ -152,11 +152,7 @@ mod tests {
// let x = k();
// let fu = lm.get(x.as_str());
//
// let fu = foo(fu);
//
// fn foo<T: Send>(v: T) -> T {
// v
// }
// let fu = assert_send(fu);
}
}
}
11 changes: 11 additions & 0 deletions src/data/impl_ref.rs
Expand Up @@ -92,6 +92,8 @@ mod tests {
use futures_util::StreamExt;

use crate::map_api::MapApiRO;
use crate::util::assert_send;
use crate::util::assert_sync;
use crate::Level;
use crate::Ref;
use crate::StaticLevels;
Expand Down Expand Up @@ -140,5 +142,14 @@ mod tests {
let got = { r }.range(k()..).await.collect::<Vec<_>>().await;
assert_eq!(got, vec![(k(), Val(3)), (k(), Val(2))]);
}

// TODO: Error:
// {
// let r = Ref::new(&d, &static_levels);
//
// let x = k();
// let fu = r.get(x.as_str());
// let fu = assert_sync(fu);
// }
}
}
8 changes: 8 additions & 0 deletions src/data/impl_static_levels.rs
Expand Up @@ -85,11 +85,13 @@ where

#[cfg(test)]
mod tests {
use std::os::macos::raw::stat;
use std::sync::Arc;

use futures_util::StreamExt;

use crate::map_api::MapApiRO;
use crate::util::assert_sync;
use crate::Level;
use crate::StaticLevels;
use crate::Val;
Expand Down Expand Up @@ -129,5 +131,11 @@ mod tests {
let got = static_levels.get(&k()).await;
assert_eq!(got, Val(2));
}

{
let x = k();
let fu = static_levels.get(x.as_str());
let fu = assert_sync(fu);
}
}
}
8 changes: 8 additions & 0 deletions src/util.rs
Expand Up @@ -4,3 +4,11 @@ pub fn by_key_seq<K, V>((k1, _v1): &(K, V), (k2, _v2): &(K, V)) -> bool
where K: MapKey {
k1 <= k2
}

pub fn assert_send<T: Send>(v: T) -> T {
v
}

pub fn assert_sync<T: Sync>(v: T) -> T {
v
}

0 comments on commit 4346943

Please sign in to comment.