diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-05 06:40:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-05 06:40:30 +0100 |
| commit | 94bb2d2a974ece985dfea0da0622d4f987505dd3 (patch) | |
| tree | 74bf2532698d90d3089cbca56caf93184690cc45 /tests | |
| parent | 72651306b3e6d7308bb35897501940cd9b97baff (diff) | |
| parent | e0a726ca4bc08d1009803a6c819f701173810761 (diff) | |
Rollup merge of #121664 - compiler-errors:adjust-error-yield-lowering, r=spastorino
Adjust error `yield`/`await` lowering
Adjust the lowering of `yield`/`await` outside of their correct scopes so that we no longer make orpan HIR exprs.
Previously, `yield EXPR` would be lowered directly to `hir::TyKind::Error` (which I'll call `<error>`) which means that `EXPR` was not present in the HIR, but now we lower it to `{ EXPR; <error> }` so that `EXPR` is not orphaned.
Fixes #121096
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/async-await/async-outside-of-await-issue-121096.rs | 9 | ||||
| -rw-r--r-- | tests/ui/async-await/async-outside-of-await-issue-121096.stderr | 12 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/ui/async-await/async-outside-of-await-issue-121096.rs b/tests/ui/async-await/async-outside-of-await-issue-121096.rs new file mode 100644 index 00000000000..e3999035ef9 --- /dev/null +++ b/tests/ui/async-await/async-outside-of-await-issue-121096.rs @@ -0,0 +1,9 @@ +//@ edition:2021 + +fn main() { + async { + use std::ops::Add; + let _ = 1.add(3); + }.await + //~^ ERROR `await` is only allowed inside `async` functions and blocks +} diff --git a/tests/ui/async-await/async-outside-of-await-issue-121096.stderr b/tests/ui/async-await/async-outside-of-await-issue-121096.stderr new file mode 100644 index 00000000000..b0677a83864 --- /dev/null +++ b/tests/ui/async-await/async-outside-of-await-issue-121096.stderr @@ -0,0 +1,12 @@ +error[E0728]: `await` is only allowed inside `async` functions and blocks + --> $DIR/async-outside-of-await-issue-121096.rs:7:7 + | +LL | fn main() { + | ---- this is not `async` +... +LL | }.await + | ^^^^^ only allowed inside `async` functions and blocks + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0728`. |
