Skip to content

Commit 8c2ae80

Browse files
committedJan 24, 2024
Don't manually resolve async closures in rustc_resolve
1 parent cd6d8f2 commit 8c2ae80

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed
 

‎compiler/rustc_resolve/src/late.rs

-29
Original file line numberDiff line numberDiff line change
@@ -4424,35 +4424,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44244424
ExprKind::Type(ref _type_expr, ref _ty) => {
44254425
visit::walk_expr(self, expr);
44264426
}
4427-
// `async |x| ...` gets desugared to `|x| async {...}`, so we need to
4428-
// resolve the arguments within the proper scopes so that usages of them inside the
4429-
// closure are detected as upvars rather than normal closure arg usages.
4430-
//
4431-
// Similarly, `gen |x| ...` gets desugared to `|x| gen {...}`, so we handle that too.
4432-
ExprKind::Closure(box ast::Closure {
4433-
coroutine_kind: Some(_),
4434-
ref fn_decl,
4435-
ref body,
4436-
..
4437-
}) => {
4438-
self.with_rib(ValueNS, RibKind::Normal, |this| {
4439-
this.with_label_rib(RibKind::FnOrCoroutine, |this| {
4440-
// Resolve arguments:
4441-
this.resolve_params(&fn_decl.inputs);
4442-
// No need to resolve return type --
4443-
// the outer closure return type is `FnRetTy::Default`.
4444-
4445-
// Now resolve the inner closure
4446-
{
4447-
// No need to resolve arguments: the inner closure has none.
4448-
// Resolve the return type:
4449-
visit::walk_fn_ret_ty(this, &fn_decl.output);
4450-
// Resolve the body
4451-
this.visit_expr(body);
4452-
}
4453-
})
4454-
});
4455-
}
44564427
// For closures, RibKind::FnOrCoroutine is added in visit_fn
44574428
ExprKind::Closure(box ast::Closure {
44584429
binder: ClosureBinder::For { ref generic_params, span },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2021
2+
3+
#![feature(async_closure)]
4+
5+
fn main() {
6+
let x = async move |x: &str| {
7+
//~^ ERROR lifetime may not live long enough
8+
// This error is proof that the `&str` type is higher-ranked.
9+
// This won't work until async closures are fully impl'd.
10+
println!("{x}");
11+
};
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/higher-ranked.rs:6:34
3+
|
4+
LL | let x = async move |x: &str| {
5+
| ____________________________-___-_^
6+
| | | |
7+
| | | return type of closure `{async closure body@$DIR/higher-ranked.rs:6:34: 11:6}` contains a lifetime `'2`
8+
| | let's call the lifetime of this reference `'1`
9+
LL | |
10+
LL | | // This error is proof that the `&str` type is higher-ranked.
11+
LL | | // This won't work until async closures are fully impl'd.
12+
LL | | println!("{x}");
13+
LL | | };
14+
| |_____^ returning this value requires that `'1` must outlive `'2`
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)
Please sign in to comment.