Skip to content

Commit 17fa344

Browse files
authored
Rollup merge of rust-lang#70739 - Centril:fix-70736, r=petrochenkov
def_collector, visit_fn: account for no body Fixes rust-lang#70736 r? @petrochenkov
2 parents 4911d16 + 5a7ad49 commit 17fa344

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

src/librustc_resolve/def_collector.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use log::debug;
22
use rustc_ast::ast::*;
33
use rustc_ast::token::{self, Token};
44
use rustc_ast::visit::{self, FnKind};
5+
use rustc_ast::walk_list;
56
use rustc_expand::expand::AstFragment;
67
use rustc_hir::def_id::LocalDefId;
78
use rustc_hir::definitions::*;
@@ -117,10 +118,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
117118
// we must mirror everything that `visit::walk_fn` below does.
118119
self.visit_fn_header(&sig.header);
119120
visit::walk_fn_decl(self, &sig.decl);
120-
if let Some(body) = body {
121-
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
122-
self.with_parent(closure_def, |this| this.visit_block(body));
123-
}
121+
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
122+
self.with_parent(closure_def, |this| walk_list!(this, visit_block, body));
124123
return;
125124
}
126125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// edition:2018
2+
3+
async fn free(); //~ ERROR without a body
4+
5+
struct A;
6+
impl A {
7+
async fn inherent(); //~ ERROR without body
8+
}
9+
10+
trait B {
11+
async fn associated();
12+
//~^ ERROR cannot be declared `async`
13+
}
14+
impl B for A {
15+
async fn associated(); //~ ERROR without body
16+
//~^ ERROR cannot be declared `async`
17+
//~| ERROR incompatible type for trait
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
error: free function without a body
2+
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:3:1
3+
|
4+
LL | async fn free();
5+
| ^^^^^^^^^^^^^^^-
6+
| |
7+
| help: provide a definition for the function: `{ <body> }`
8+
9+
error: associated function in `impl` without body
10+
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:7:5
11+
|
12+
LL | async fn inherent();
13+
| ^^^^^^^^^^^^^^^^^^^-
14+
| |
15+
| help: provide a definition for the function: `{ <body> }`
16+
17+
error[E0706]: functions in traits cannot be declared `async`
18+
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:11:5
19+
|
20+
LL | async fn associated();
21+
| -----^^^^^^^^^^^^^^^^^
22+
| |
23+
| `async` because of this
24+
|
25+
= note: `async` trait functions are not currently supported
26+
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
27+
28+
error: associated function in `impl` without body
29+
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:5
30+
|
31+
LL | async fn associated();
32+
| ^^^^^^^^^^^^^^^^^^^^^-
33+
| |
34+
| help: provide a definition for the function: `{ <body> }`
35+
36+
error[E0706]: functions in traits cannot be declared `async`
37+
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:5
38+
|
39+
LL | async fn associated();
40+
| -----^^^^^^^^^^^^^^^^^
41+
| |
42+
| `async` because of this
43+
|
44+
= note: `async` trait functions are not currently supported
45+
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
46+
47+
error[E0053]: method `associated` has an incompatible type for trait
48+
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:26
49+
|
50+
LL | async fn associated();
51+
| - type in trait
52+
...
53+
LL | async fn associated();
54+
| ^
55+
| |
56+
| the `Output` of this `async fn`'s found opaque type
57+
| expected `()`, found opaque type
58+
|
59+
= note: expected fn pointer `fn()`
60+
found fn pointer `fn() -> impl std::future::Future`
61+
62+
error: aborting due to 6 previous errors
63+
64+
Some errors have detailed explanations: E0053, E0706.
65+
For more information about an error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)