about summary refs log tree commit diff
path: root/tests/ui/async-await/higher-ranked-auto-trait-9.rs
blob: 66edbf23f2b2164cf18529c430f0dc6bc58fd6eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Repro for <https://github.com/rust-lang/rust/issues/87425#issue-952059416>.
//@ edition: 2021
//@ revisions: assumptions no_assumptions
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
//@[assumptions] check-pass
//@[no_assumptions] known-bug: #110338

use std::any::Any;
use std::fmt;
use std::future::Future;

pub trait Foo {
    type Item;
}

impl<F, I> Foo for F
where
    Self: FnOnce() -> I,
    I: fmt::Debug,
{
    type Item = I;
}

async fn foo_item<F: Foo>(_: F) -> F::Item {
    unimplemented!()
}

fn main() {
    let fut = async {
        let callback = || -> Box<dyn Any> { unimplemented!() };

        // Using plain fn instead of a closure fixes the error,
        // though you obviously can't capture any state...
        // fn callback() -> Box<dyn Any> {
        //     todo!()
        // }

        foo_item(callback).await;
    };

    // Removing `+ Send` bound also fixes the error,
    // though at the cost of loosing `Send`ability...
    let fut: &(dyn Future<Output = ()> + Send) = &fut as _;
}