Skip to content

Commit 81910a1

Browse files
authored
Rollup merge of #110965 - compiler-errors:anon-lt-dupe-oops, r=cjgillot
Don't duplicate anonymous lifetimes for async fn in traits `record_lifetime_params_for_async` needs to be called outside of the scope of the function, or else it'll end up collecting anonymous lifetimes twice (those on the function and those within the `AnonymousCreateParameter` rib). This matches how `record_lifetime_params_for_async` is being used for functions with bodies below. This fixes (partially) #110963 when the lifetimes are late-bound, but does not do so when the lifetimes are early-bound (as seen from the known-bug that I added).
2 parents 7721c73 + 4e05cfb commit 81910a1

File tree

6 files changed

+164
-8
lines changed

6 files changed

+164
-8
lines changed

compiler/rustc_resolve/src/late.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -859,13 +859,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
859859
sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
860860
&sig.decl.output,
861861
);
862-
863-
this.record_lifetime_params_for_async(
864-
fn_id,
865-
sig.header.asyncness.opt_return_id(),
866-
);
867862
},
868863
);
864+
self.record_lifetime_params_for_async(fn_id, sig.header.asyncness.opt_return_id());
869865
return;
870866
}
871867
FnKind::Fn(..) => {

tests/ui/async-await/in-trait/nested-rpit.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// edition: 2021
2-
// known-bug: #105197
3-
// failure-status:101
4-
// dont-check-compiler-stderr
2+
// check-pass
53

64
#![feature(async_fn_in_trait)]
75
#![feature(return_position_impl_trait_in_trait)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// edition: 2021
2+
// known-bug: #110963
3+
4+
#![feature(return_type_notation)]
5+
#![feature(async_fn_in_trait)]
6+
7+
trait HealthCheck {
8+
async fn check<'a: 'a>(&'a mut self) -> bool;
9+
}
10+
11+
async fn do_health_check_par<HC>(hc: HC)
12+
where
13+
HC: HealthCheck<check(): Send> + Send + 'static,
14+
{
15+
spawn(async move {
16+
let mut hc = hc;
17+
if !hc.check().await {
18+
log_health_check_failure().await;
19+
}
20+
});
21+
}
22+
23+
async fn log_health_check_failure() {}
24+
25+
fn main() {}
26+
27+
// Fake tokio spawn
28+
29+
use std::future::Future;
30+
use std::pin::Pin;
31+
use std::task::{Context, Poll};
32+
33+
fn spawn<F>(future: F) -> JoinHandle
34+
where
35+
F: Future + Send + 'static,
36+
F::Output: Send + 'static,
37+
{
38+
loop {}
39+
}
40+
41+
struct JoinHandle;
42+
43+
impl Future for JoinHandle {
44+
type Output = ();
45+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
46+
loop {}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-110963-early.rs:4:12
3+
|
4+
LL | #![feature(return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
11+
--> $DIR/issue-110963-early.rs:5:12
12+
|
13+
LL | #![feature(async_fn_in_trait)]
14+
| ^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
17+
18+
error: higher-ranked lifetime error
19+
--> $DIR/issue-110963-early.rs:15:5
20+
|
21+
LL | / spawn(async move {
22+
LL | | let mut hc = hc;
23+
LL | | if !hc.check().await {
24+
LL | | log_health_check_failure().await;
25+
LL | | }
26+
LL | | });
27+
| |______^
28+
|
29+
= note: could not prove `[async block@$DIR/issue-110963-early.rs:15:11: 20:6]: Send`
30+
31+
error: higher-ranked lifetime error
32+
--> $DIR/issue-110963-early.rs:15:5
33+
|
34+
LL | / spawn(async move {
35+
LL | | let mut hc = hc;
36+
LL | | if !hc.check().await {
37+
LL | | log_health_check_failure().await;
38+
LL | | }
39+
LL | | });
40+
| |______^
41+
|
42+
= note: could not prove `[async block@$DIR/issue-110963-early.rs:15:11: 20:6]: Send`
43+
44+
error: aborting due to 2 previous errors; 2 warnings emitted
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// edition: 2021
2+
// check-pass
3+
4+
#![feature(return_type_notation)]
5+
//~^ WARN the feature `return_type_notation` is incomplete
6+
#![feature(async_fn_in_trait)]
7+
//~^ WARN the feature `async_fn_in_trait` is incomplete
8+
9+
trait HealthCheck {
10+
async fn check(&mut self) -> bool;
11+
}
12+
13+
async fn do_health_check_par<HC>(hc: HC)
14+
where
15+
HC: HealthCheck<check(): Send> + Send + 'static,
16+
{
17+
spawn(async move {
18+
let mut hc = hc;
19+
if !hc.check().await {
20+
log_health_check_failure().await;
21+
}
22+
});
23+
}
24+
25+
async fn log_health_check_failure() {}
26+
27+
fn main() {}
28+
29+
// Fake tokio spawn
30+
31+
use std::future::Future;
32+
use std::pin::Pin;
33+
use std::task::{Context, Poll};
34+
35+
fn spawn<F>(future: F) -> JoinHandle
36+
where
37+
F: Future + Send + 'static,
38+
F::Output: Send + 'static,
39+
{
40+
loop {}
41+
}
42+
43+
struct JoinHandle;
44+
45+
impl Future for JoinHandle {
46+
type Output = ();
47+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
48+
loop {}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-110963-late.rs:4:12
3+
|
4+
LL | #![feature(return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
11+
--> $DIR/issue-110963-late.rs:6:12
12+
|
13+
LL | #![feature(async_fn_in_trait)]
14+
| ^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
17+
18+
warning: 2 warnings emitted
19+

0 commit comments

Comments
 (0)