Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #122012

Merged
merged 31 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1f2db3d
Add an example to demonstrate how Rc::into_inner works
Takashiidobe Feb 17, 2024
cb8ce9d
time complexity for push
20jasper Feb 16, 2024
bb6dca0
time complexity for push_within_capacity
20jasper Feb 16, 2024
0a5d684
time complexity for pop
20jasper Feb 16, 2024
d2f825f
time complexity for insert
20jasper Feb 18, 2024
ef1a584
intradoc link for vec
20jasper Feb 18, 2024
a9cfeb3
fix typo in push documentation
20jasper Feb 18, 2024
bc52e5d
Fix error in push docs
20jasper Feb 18, 2024
261da5f
Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.
zachs18 Feb 19, 2024
74151cb
Make push docs more vague
20jasper Feb 25, 2024
e0a726c
Adjust error yield/await lowering
compiler-errors Feb 27, 2024
f5f11e1
Add regression test
oli-obk Mar 1, 2024
dd0004a
Don't panic when waiting on poisoned queries
Zoxc Aug 16, 2023
f0c9311
Use root obligation on E0277 for some cases
estebank Feb 29, 2024
89a3c19
Be more lax in `.into_iter()` suggestion when encountering `Iterator`…
estebank Mar 1, 2024
40f9dcc
Use `can_eq` instead of `Ty<'_> == Ty<'_>`
estebank Mar 2, 2024
8364a06
Merge the impl trait in assoc type collector into the opaque type col…
oli-obk Mar 4, 2024
2af01a2
Abort on arity mismatch
Nadrieril Mar 4, 2024
fb91610
Avoid using unnecessary queries when printing the query stack in panics
Zoxc Mar 4, 2024
86e88fc
interpret/cast: make more matches on FloatTy properly exhaustive
RalfJung Mar 4, 2024
681dc38
typo
RalfJung Mar 4, 2024
c2f6c0b
Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-in…
matthiaskrgr Mar 5, 2024
22827fd
Rollup merge of #121262 - 20jasper:add-vector-time-complexity, r=cuviper
matthiaskrgr Mar 5, 2024
7265130
Rollup merge of #121287 - zachs18:rc-into-raw-must-use, r=cuviper
matthiaskrgr Mar 5, 2024
94bb2d2
Rollup merge of #121664 - compiler-errors:adjust-error-yield-lowering…
matthiaskrgr Mar 5, 2024
35f6eee
Rollup merge of #121826 - estebank:e0277-root-obligation-2, r=oli-obk
matthiaskrgr Mar 5, 2024
20dde1e
Rollup merge of #121838 - oli-obk:impl_trait_in_assoc_tys_fix, r=comp…
matthiaskrgr Mar 5, 2024
c483e63
Rollup merge of #121913 - Zoxc:query-fix, r=compiler-errors
matthiaskrgr Mar 5, 2024
44bd2b5
Rollup merge of #121987 - Nadrieril:abort-on-arity-mismatch, r=compil…
matthiaskrgr Mar 5, 2024
87dc3fc
Rollup merge of #121993 - Zoxc:query-stack-panic-queries, r=compiler-…
matthiaskrgr Mar 5, 2024
92ff43d
Rollup merge of #121997 - RalfJung:cast-float-ty, r=compiler-errors
matthiaskrgr Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adjust error yield/await lowering
  • Loading branch information
compiler-errors committed Feb 27, 2024
commit e0a726ca4bc08d1009803a6c819f701173810761
52 changes: 43 additions & 9 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(hir::CoroutineKind::Coroutine(_))
| Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _))
| None => {
return hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
}));
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
// is not accidentally orphaned.
let stmt_id = self.next_id();
let expr_err = self.expr(
expr.span,
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
})),
);
return hir::ExprKind::Block(
self.block_all(
expr.span,
arena_vec![self; hir::Stmt {
hir_id: stmt_id,
kind: hir::StmtKind::Semi(expr),
span: expr.span,
}],
Some(self.arena.alloc(expr_err)),
),
None,
);
}
};

Expand Down Expand Up @@ -1500,12 +1518,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));

let is_async_gen = match self.coroutine_kind {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
return hir::ExprKind::Err(
self.dcx().emit_err(AsyncCoroutinesNotSupported { span }),
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
// is not accidentally orphaned.
let stmt_id = self.next_id();
let expr_err = self.expr(
yielded.span,
hir::ExprKind::Err(self.dcx().emit_err(AsyncCoroutinesNotSupported { span })),
);
return hir::ExprKind::Block(
self.block_all(
yielded.span,
arena_vec![self; hir::Stmt {
hir_id: stmt_id,
kind: hir::StmtKind::Semi(yielded),
span: yielded.span,
}],
Some(self.arena.alloc(expr_err)),
),
None,
);
}
Some(hir::CoroutineKind::Coroutine(_)) => {
Expand Down Expand Up @@ -1535,9 +1572,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
};

let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));

if is_async_gen {
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
// This ensures that we store our resumed `ResumeContext` correctly, and also that
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/async-await/async-outside-of-await-issue-121096.rs
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions tests/ui/async-await/async-outside-of-await-issue-121096.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading