Skip to content

Commit 3478d7c

Browse files
committed
Auto merge of #76257 - JulianKnodt:i75777, r=Dylan-DPC
Add regression test This adds a regression test for #75777, effectively closing it since it is solved on nightly and beta. Closes #75777
2 parents 0d033de + a7e8208 commit 3478d7c

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/issue-75777.rs:13:5
3+
|
4+
LL | fn inject<'a, Env: 'a, A: 'a + Send>(v: A) -> Box<dyn FnOnce(&'a Env) -> BoxFuture<'a, A>> {
5+
| -- lifetime `'a` defined here
6+
LL | let fut: BoxFuture<'a, A> = Box::pin(future::ready(v));
7+
LL | Box::new(move |_| fut)
8+
| ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
9+
|
10+
= help: consider replacing `'a` with `'static`
11+
12+
error: aborting due to previous error
13+

src/test/ui/issues/issue-75777.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Regression test for #75777.
2+
// Checks that a boxed future can be properly constructed.
3+
4+
#![feature(future_readiness_fns)]
5+
6+
use std::future::{self, Future};
7+
use std::pin::Pin;
8+
9+
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
10+
11+
fn inject<'a, Env: 'a, A: 'a + Send>(v: A) -> Box<dyn FnOnce(&'a Env) -> BoxFuture<'a, A>> {
12+
let fut: BoxFuture<'a, A> = Box::pin(future::ready(v));
13+
Box::new(move |_| fut)
14+
//~^ ERROR: cannot infer an appropriate lifetime
15+
}
16+
17+
fn main() {}

src/test/ui/issues/issue-75777.stderr

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
2+
--> $DIR/issue-75777.rs:13:14
3+
|
4+
LL | Box::new(move |_| fut)
5+
| ^^^^^^^^^^^^
6+
|
7+
note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 11:11...
8+
--> $DIR/issue-75777.rs:11:11
9+
|
10+
LL | fn inject<'a, Env: 'a, A: 'a + Send>(v: A) -> Box<dyn FnOnce(&'a Env) -> BoxFuture<'a, A>> {
11+
| ^^
12+
note: ...so that the types are compatible
13+
--> $DIR/issue-75777.rs:13:14
14+
|
15+
LL | Box::new(move |_| fut)
16+
| ^^^^^^^^^^^^
17+
= note: expected `(Pin<Box<dyn Future<Output = A> + Send>>,)`
18+
found `(Pin<Box<(dyn Future<Output = A> + Send + 'a)>>,)`
19+
= note: but, the lifetime must be valid for the static lifetime...
20+
note: ...so that the expression is assignable
21+
--> $DIR/issue-75777.rs:13:5
22+
|
23+
LL | Box::new(move |_| fut)
24+
| ^^^^^^^^^^^^^^^^^^^^^^
25+
= note: expected `Box<(dyn FnOnce(&'a Env) -> Pin<Box<(dyn Future<Output = A> + Send + 'a)>> + 'static)>`
26+
found `Box<dyn FnOnce(&'a Env) -> Pin<Box<(dyn Future<Output = A> + Send + 'a)>>>`
27+
28+
error: aborting due to previous error
29+
30+
For more information about this error, try `rustc --explain E0495`.

0 commit comments

Comments
 (0)