Skip to content

Commit 78fa79e

Browse files
Add tests, some of them fail...
1 parent 512cf3a commit 78fa79e

File tree

38 files changed

+1206
-0
lines changed

38 files changed

+1206
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/higher-ranked-auto-trait-1.rs:37:5
3+
|
4+
LL | / async {
5+
LL | | let _y = &();
6+
LL | | let _x = filter(FilterMap {
7+
LL | | f: || async move { *_y },
8+
... |
9+
LL | | drop(_x);
10+
LL | | }
11+
| |_____^ one type is more general than the other
12+
|
13+
= note: expected `async` block `{async block@$DIR/higher-ranked-auto-trait-1.rs:40:19: 40:29}`
14+
found `async` block `{async block@$DIR/higher-ranked-auto-trait-1.rs:40:19: 40:29}`
15+
= note: no two async blocks, even if identical, have the same type
16+
= help: consider pinning your async block and casting it to a trait object
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/higher-ranked-auto-trait-1.rs:37:5
20+
|
21+
LL | / async {
22+
LL | | let _y = &();
23+
LL | | let _x = filter(FilterMap {
24+
LL | | f: || async move { *_y },
25+
... |
26+
LL | | drop(_x);
27+
LL | | }
28+
| |_____^ one type is more general than the other
29+
|
30+
= note: expected `async` block `{async block@$DIR/higher-ranked-auto-trait-1.rs:40:19: 40:29}`
31+
found `async` block `{async block@$DIR/higher-ranked-auto-trait-1.rs:40:19: 40:29}`
32+
= note: no two async blocks, even if identical, have the same type
33+
= help: consider pinning your async block and casting it to a trait object
34+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
35+
36+
error: aborting due to 2 previous errors
37+
38+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Repro for <https://github.com/rust-lang/rust/issues/79648#issuecomment-749127947>.
2+
//@ edition: 2021
3+
//@ revisions: assumptions no_assumptions
4+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
5+
//@[assumptions] check-pass
6+
//@[no_assumptions] known-bug: #110338
7+
8+
use std::future::Future;
9+
use std::marker::PhantomData;
10+
11+
trait Stream {
12+
type Item;
13+
}
14+
15+
struct Filter<St: Stream> {
16+
pending_item: St::Item,
17+
}
18+
19+
fn filter<St: Stream>(_: St) -> Filter<St> {
20+
unimplemented!();
21+
}
22+
23+
struct FilterMap<Fut, F> {
24+
f: F,
25+
pending: PhantomData<Fut>,
26+
}
27+
28+
impl<Fut, F> Stream for FilterMap<Fut, F>
29+
where
30+
F: FnMut() -> Fut,
31+
Fut: Future,
32+
{
33+
type Item = ();
34+
}
35+
36+
pub fn get_foo() -> impl Future + Send {
37+
async {
38+
let _y = &();
39+
let _x = filter(FilterMap {
40+
f: || async move { *_y },
41+
pending: PhantomData,
42+
});
43+
async {}.await;
44+
drop(_x);
45+
}
46+
}
47+
48+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: implementation of `Foo` is not general enough
2+
--> $DIR/higher-ranked-auto-trait-10.rs:32:5
3+
|
4+
LL | Box::new(async move { get_foo(x).await })
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
6+
|
7+
= note: `Foo<'1>` would have to be implemented for the type `&'0 str`, for any two lifetimes `'0` and `'1`...
8+
= note: ...but `Foo<'2>` is actually implemented for the type `&'2 str`, for some specific lifetime `'2`
9+
10+
error: implementation of `Foo` is not general enough
11+
--> $DIR/higher-ranked-auto-trait-10.rs:32:5
12+
|
13+
LL | Box::new(async move { get_foo(x).await })
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
15+
|
16+
= note: `Foo<'1>` would have to be implemented for the type `&'0 str`, for any two lifetimes `'0` and `'1`...
17+
= note: ...but `Foo<'2>` is actually implemented for the type `&'2 str`, for some specific lifetime `'2`
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
20+
error: aborting due to 2 previous errors
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: implementation of `Foo` is not general enough
2+
--> $DIR/higher-ranked-auto-trait-10.rs:32:5
3+
|
4+
LL | Box::new(async move { get_foo(x).await })
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
6+
|
7+
= note: `Foo<'1>` would have to be implemented for the type `&'0 str`, for any two lifetimes `'0` and `'1`...
8+
= note: ...but `Foo<'2>` is actually implemented for the type `&'2 str`, for some specific lifetime `'2`
9+
10+
error: implementation of `Foo` is not general enough
11+
--> $DIR/higher-ranked-auto-trait-10.rs:32:5
12+
|
13+
LL | Box::new(async move { get_foo(x).await })
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
15+
|
16+
= note: `Foo<'1>` would have to be implemented for the type `&'0 str`, for any two lifetimes `'0` and `'1`...
17+
= note: ...but `Foo<'2>` is actually implemented for the type `&'2 str`, for some specific lifetime `'2`
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
20+
error: aborting due to 2 previous errors
21+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Repro for <https://github.com/rust-lang/rust/issues/92415#issue-1090723521>.
2+
//@ edition: 2021
3+
//@ revisions: assumptions no_assumptions
4+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
5+
//@[assumptions] known-bug: unknown
6+
//@[no_assumptions] known-bug: #110338
7+
8+
use std::any::Any;
9+
use std::future::Future;
10+
11+
trait Foo<'a>: Sized {
12+
type Error;
13+
fn foo(x: &'a str) -> Result<Self, Self::Error>;
14+
}
15+
16+
impl<'a> Foo<'a> for &'a str {
17+
type Error = ();
18+
19+
fn foo(x: &'a str) -> Result<Self, Self::Error> {
20+
Ok(x)
21+
}
22+
}
23+
24+
async fn get_foo<'a, T>(x: &'a str) -> Result<T, <T as Foo<'a>>::Error>
25+
where
26+
T: Foo<'a>,
27+
{
28+
Foo::foo(x)
29+
}
30+
31+
fn bar<'a>(x: &'a str) -> Box<dyn Future<Output = Result<&'a str, ()>> + Send + 'a> {
32+
Box::new(async move { get_foo(x).await })
33+
}
34+
35+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/higher-ranked-auto-trait-11.rs:27:9
3+
|
4+
LL | impl<'a, T> Foo<'a> for MyType<T>
5+
| -- lifetime `'a` defined here
6+
...
7+
LL | Box::pin(async move { <T as Foo<'a>>::foo().await })
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'a` must outlive `'static`
9+
10+
error: implementation of `Send` is not general enough
11+
--> $DIR/higher-ranked-auto-trait-11.rs:27:9
12+
|
13+
LL | Box::pin(async move { <T as Foo<'a>>::foo().await })
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Send` is not general enough
15+
|
16+
= note: `Send` would have to be implemented for the type `<T as Foo<'0>>::Future`, for any lifetime `'0`...
17+
= note: ...but `Send` is actually implemented for the type `<T as Foo<'1>>::Future`, for some specific lifetime `'1`
18+
19+
error: aborting due to 2 previous errors
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/higher-ranked-auto-trait-11.rs:27:9
3+
|
4+
LL | impl<'a, T> Foo<'a> for MyType<T>
5+
| -- lifetime `'a` defined here
6+
...
7+
LL | Box::pin(async move { <T as Foo<'a>>::foo().await })
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'a` must outlive `'static`
9+
10+
error: implementation of `Send` is not general enough
11+
--> $DIR/higher-ranked-auto-trait-11.rs:27:9
12+
|
13+
LL | Box::pin(async move { <T as Foo<'a>>::foo().await })
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Send` is not general enough
15+
|
16+
= note: `Send` would have to be implemented for the type `<T as Foo<'0>>::Future`, for any lifetime `'0`...
17+
= note: ...but `Send` is actually implemented for the type `<T as Foo<'1>>::Future`, for some specific lifetime `'1`
18+
19+
error: aborting due to 2 previous errors
20+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Repro for <https://github.com/rust-lang/rust/issues/60658#issuecomment-1509321859>.
2+
//@ edition: 2021
3+
//@ revisions: assumptions no_assumptions
4+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
5+
//@[assumptions] known-bug: unknown
6+
//@[no_assumptions] known-bug: #110338
7+
8+
use core::pin::Pin;
9+
use std::future::Future;
10+
11+
pub trait Foo<'a> {
12+
type Future: Future<Output = ()>;
13+
14+
fn foo() -> Self::Future;
15+
}
16+
17+
struct MyType<T>(T);
18+
19+
impl<'a, T> Foo<'a> for MyType<T>
20+
where
21+
T: Foo<'a>,
22+
T::Future: Send,
23+
{
24+
type Future = Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
25+
26+
fn foo() -> Self::Future {
27+
Box::pin(async move { <T as Foo<'a>>::foo().await })
28+
}
29+
}
30+
31+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: implementation of `Robot` is not general enough
2+
--> $DIR/higher-ranked-auto-trait-12.rs:31:20
3+
|
4+
LL | let _my_task = this_is_send(async move {
5+
| ____________________^
6+
LL | | let _my_iter = IRobot {
7+
LL | | id: 32,
8+
LL | | robot: source,
9+
LL | | };
10+
LL | | yield_now().await;
11+
LL | | });
12+
| |______^ implementation of `Robot` is not general enough
13+
|
14+
= note: `Box<(dyn Robot<Id = u32> + Send + '0)>` must implement `Robot`, for any lifetime `'0`...
15+
= note: ...but `Robot` is actually implemented for the type `Box<(dyn Robot<Id = u32> + Send + 'static)>`
16+
17+
error: aborting due to 1 previous error
18+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Repro for <https://github.com/rust-lang/rust/issues/71671#issuecomment-848994782>.
2+
//@ edition: 2021
3+
//@ revisions: assumptions no_assumptions
4+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
5+
//@[assumptions] check-pass
6+
//@[no_assumptions] known-bug: #110338
7+
8+
pub trait Robot {
9+
type Id;
10+
}
11+
12+
pub type DynRobot = Box<dyn Robot<Id = u32> + Send>;
13+
14+
impl Robot for DynRobot {
15+
type Id = u32;
16+
}
17+
18+
struct IRobot<R: Robot> {
19+
id: R::Id,
20+
robot: R,
21+
}
22+
23+
// stand-in for tokio::spawn
24+
fn this_is_send<T: Send>(value: T) -> T {
25+
value
26+
}
27+
28+
async fn yield_now() {}
29+
30+
fn test(source: DynRobot) {
31+
let _my_task = this_is_send(async move {
32+
let _my_iter = IRobot {
33+
id: 32,
34+
robot: source,
35+
};
36+
yield_now().await;
37+
});
38+
}
39+
40+
fn main() {}

0 commit comments

Comments
 (0)