Skip to content

Commit

Permalink
Minimal example of bug(?) with higher-ranked trait bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeef committed Apr 11, 2022
0 parents commit ac63bb6
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
158 changes: 158 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "hrtb_test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3.21"
35 changes: 35 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use futures::Future;
trait TestFn<'a>: Send + Sync {
type Fut: Future<Output = ()>;
fn call(self, v: &'a i64) -> Self::Fut;
}

impl<'a, F, Fut> TestFn<'a> for F
where
F: FnOnce(&'a i64) -> Fut + Send + Sync,
Fut: Future<Output = ()>,
{
type Fut = Fut;

fn call(self, v: &'a i64) -> Self::Fut {
self(v)
}
}

async fn test<F>(func: F)
where
F: for<'a> TestFn<'a>,
{
func.call(&3).await
}

async fn main_async() {
test(|v| async move {
println!("works! {} ", v);
})
.await;
}

fn main() {
futures::executor::block_on(main_async());
}

0 comments on commit ac63bb6

Please sign in to comment.