Skip to content

Commit a928f64

Browse files
authored
Rollup merge of #70640 - jonas-schievink:async-ice, r=cramertj
Hide `task_context` when lowering body Fixes #70594
2 parents 1ea8653 + c7d9d89 commit a928f64

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/librustc_ast_lowering/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
972972
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
973973
) -> hir::BodyId {
974974
let prev_gen_kind = self.generator_kind.take();
975+
let task_context = self.task_context.take();
975976
let (parameters, result) = f(self);
976977
let body_id = self.record_body(parameters, result);
978+
self.task_context = task_context;
977979
self.generator_kind = prev_gen_kind;
978980
body_id
979981
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2018
2+
3+
async fn fun() {
4+
[1; ().await];
5+
//~^ error: `await` is only allowed inside `async` functions and blocks
6+
//~| error: `.await` is not allowed in a `const`
7+
//~| error: `loop` is not allowed in a `const`
8+
//~| error: `.await` is not allowed in a `const`
9+
//~| error: the trait bound `(): std::future::Future` is not satisfied
10+
}
11+
12+
fn main() {}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0728]: `await` is only allowed inside `async` functions and blocks
2+
--> $DIR/issue-70594.rs:4:9
3+
|
4+
LL | async fn fun() {
5+
| --- this is not `async`
6+
LL | [1; ().await];
7+
| ^^^^^^^^ only allowed inside `async` functions and blocks
8+
9+
error[E0744]: `.await` is not allowed in a `const`
10+
--> $DIR/issue-70594.rs:4:9
11+
|
12+
LL | [1; ().await];
13+
| ^^^^^^^^
14+
15+
error[E0658]: `loop` is not allowed in a `const`
16+
--> $DIR/issue-70594.rs:4:9
17+
|
18+
LL | [1; ().await];
19+
| ^^^^^^^^
20+
|
21+
= note: see issue #52000 <https://github.com/rust-lang/rust/issues/52000> for more information
22+
= help: add `#![feature(const_loop)]` to the crate attributes to enable
23+
24+
error[E0744]: `.await` is not allowed in a `const`
25+
--> $DIR/issue-70594.rs:4:9
26+
|
27+
LL | [1; ().await];
28+
| ^^^^^^^^
29+
30+
error[E0277]: the trait bound `(): std::future::Future` is not satisfied
31+
--> $DIR/issue-70594.rs:4:9
32+
|
33+
LL | [1; ().await];
34+
| ^^^^^^^^ the trait `std::future::Future` is not implemented for `()`
35+
|
36+
::: $SRC_DIR/libcore/future/mod.rs:LL:COL
37+
|
38+
LL | F: Future,
39+
| ------ required by this bound in `std::future::poll_with_context`
40+
41+
error: aborting due to 5 previous errors
42+
43+
Some errors have detailed explanations: E0277, E0658, E0728, E0744.
44+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)