Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
binder,
*capture_clause,
e.id,
*movability,
expr_hir_id,
*coroutine_kind,
fn_decl,
Expand Down Expand Up @@ -1152,13 +1153,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
binder: &ClosureBinder,
capture_clause: CaptureBy,
closure_id: NodeId,
movability: Movability,
closure_hir_id: HirId,
coroutine_kind: CoroutineKind,
decl: &FnDecl,
body: &Expr,
fn_decl_span: Span,
fn_arg_span: Span,
) -> hir::ExprKind<'hir> {
if movability == Movability::Static {
self.dcx().emit_err(ClosureCannotBeStatic { fn_decl_span });
}
let closure_def_id = self.local_def_id(closure_id);
let (binder_clause, generic_params) = self.lower_closure_binder(binder);

Expand Down
14 changes: 13 additions & 1 deletion tests/ui/unpretty/exhaustive.hir.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ error[E0697]: closures cannot be static
LL | static move || value;
| ^^^^^^^^^^^^^^

error[E0697]: closures cannot be static
--> $DIR/exhaustive.rs:211:10
|
LL | (static async || value);
| ^^^^^^^^^^^^^^^

error[E0697]: closures cannot be static
--> $DIR/exhaustive.rs:212:10
|
LL | (static async move || value);
| ^^^^^^^^^^^^^^^^^^^^

error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/exhaustive.rs:239:13
|
Expand Down Expand Up @@ -166,7 +178,7 @@ LL | let _: impl for<'a> Send;
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 20 previous errors
error: aborting due to 22 previous errors

Some errors have detailed explanations: E0214, E0562, E0697, E0703, E0728.
For more information about an error, try `rustc --explain E0214`.
12 changes: 10 additions & 2 deletions tests/ui/unpretty/exhaustive.hir.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,16 @@ mod expressions {
move || |mut _task_context: ResumeTy| { { let _t = value; _t } };
|| value;
move || value;
|| |mut _task_context: ResumeTy| { { let _t = value; _t } };
move || |mut _task_context: ResumeTy| { { let _t = value; _t } };
||
|mut _task_context: ResumeTy|
{
{ let _t = value; _t }
};
move ||
|mut _task_context: ResumeTy|
{
{ let _t = value; _t }
};
|| -> u8 { value };
1 + (|| { });
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/unpretty/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ mod expressions {
move || value;
async || value;
async move || value;
static || value; //[hir]~ ERROR closures cannot be static
static move || value; //[hir]~ ERROR closures cannot be static
(static async || value);
(static async move || value);
static || value; //[hir]~ ERROR closures cannot be static
static move || value; //[hir]~ ERROR closures cannot be static
(static async || value); //[hir]~ ERROR closures cannot be static
(static async move || value); //[hir]~ ERROR closures cannot be static
|| -> u8 { value };
1 + || {};
}
Expand Down
Loading