Skip to content

Commit fafb016

Browse files
committed
Auto merge of #120030 - matthiaskrgr:rollup-38h12rs, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #119062 (Deny braced macro invocations in let-else) - #119922 (Rework how diagnostic lints are stored.) - #119978 (Move async closure parameters into the resultant closure's future eagerly) - #119984 (Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.) - #120020 (Gracefully handle missing typeck information if typeck errored) - #120021 (don't store const var origins for known vars) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 92f2e0a + 1a329e4 commit fafb016

File tree

78 files changed

+697
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+697
-712
lines changed

compiler/rustc_ast/src/util/classify.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
// Predicates on exprs and stmts that the pretty-printer and parser use
44

5-
use crate::ast;
5+
use crate::{ast, token::Delimiter};
66

77
/// Does this expression require a semicolon to be treated
88
/// as a statement? The negation of this: 'can this expression
@@ -59,8 +59,12 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
5959
| While(..)
6060
| ConstBlock(_) => break Some(expr),
6161

62-
// FIXME: These can end in `}`, but changing these would break stable code.
63-
InlineAsm(_) | OffsetOf(_, _) | MacCall(_) | IncludedBytes(_) | FormatArgs(_) => {
62+
MacCall(mac) => {
63+
break (mac.args.delim == Delimiter::Brace).then_some(expr);
64+
}
65+
66+
InlineAsm(_) | OffsetOf(_, _) | IncludedBytes(_) | FormatArgs(_) => {
67+
// These should have been denied pre-expansion.
6468
break None;
6569
}
6670

compiler/rustc_ast_lowering/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ ast_lowering_assoc_ty_parentheses =
1414
ast_lowering_async_coroutines_not_supported =
1515
`async` coroutines are not yet supported
1616
17-
ast_lowering_async_non_move_closure_not_supported =
18-
`async` non-`move` closures with parameters are not currently supported
19-
.help = consider using `let` statements to manually capture variables by reference before entering an `async move` closure
20-
2117
ast_lowering_att_syntax_only_x86 =
2218
the `att_syntax` option is only supported on x86
2319

compiler/rustc_ast_lowering/src/errors.rs

-8
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,6 @@ pub struct ClosureCannotBeStatic {
145145
pub fn_decl_span: Span,
146146
}
147147

148-
#[derive(Diagnostic, Clone, Copy)]
149-
#[help]
150-
#[diag(ast_lowering_async_non_move_closure_not_supported, code = "E0708")]
151-
pub struct AsyncNonMoveClosureNotSupported {
152-
#[primary_span]
153-
pub fn_decl_span: Span,
154-
}
155-
156148
#[derive(Diagnostic, Clone, Copy)]
157149
#[diag(ast_lowering_functional_record_update_destructuring_assignment)]
158150
pub struct FunctionalRecordUpdateDestructuringAssignment {

compiler/rustc_ast_lowering/src/expr.rs

+15-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::errors::{
2-
AsyncCoroutinesNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
3-
BaseExpressionDoubleDot, ClosureCannotBeStatic, CoroutineTooManyParameters,
2+
AsyncCoroutinesNotSupported, AwaitOnlyInAsyncFnAndBlocks, BaseExpressionDoubleDot,
3+
ClosureCannotBeStatic, CoroutineTooManyParameters,
44
FunctionalRecordUpdateDestructuringAssignment, InclusiveRangeWithNoEnd, MatchArmWithNoBody,
55
NeverPatternWithBody, NeverPatternWithGuard, NotSupportedForLifetimeBinderAsyncClosure,
66
UnderscoreExprLhsAssign,
@@ -13,7 +13,6 @@ use rustc_ast::*;
1313
use rustc_data_structures::stack::ensure_sufficient_stack;
1414
use rustc_hir as hir;
1515
use rustc_hir::def::{DefKind, Res};
16-
use rustc_middle::span_bug;
1716
use rustc_session::errors::report_lit_error;
1817
use rustc_span::source_map::{respan, Spanned};
1918
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -1028,51 +1027,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
10281027
fn_decl_span: Span,
10291028
fn_arg_span: Span,
10301029
) -> hir::ExprKind<'hir> {
1031-
let CoroutineKind::Async { closure_id: inner_closure_id, .. } = coroutine_kind else {
1032-
span_bug!(fn_decl_span, "`async gen` and `gen` closures are not supported, yet");
1033-
};
1034-
10351030
if let &ClosureBinder::For { span, .. } = binder {
10361031
self.dcx().emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
10371032
}
10381033

10391034
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10401035

1041-
let outer_decl =
1042-
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
1043-
10441036
let body = self.with_new_scopes(fn_decl_span, |this| {
1045-
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
1046-
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
1047-
this.dcx().emit_err(AsyncNonMoveClosureNotSupported { fn_decl_span });
1048-
}
1049-
10501037
// Transform `async |x: u8| -> X { ... }` into
10511038
// `|x: u8| || -> X { ... }`.
1052-
let body_id = this.lower_fn_body(&outer_decl, |this| {
1039+
let body_id = this.lower_body(|this| {
10531040
let async_ret_ty = if let FnRetTy::Ty(ty) = &decl.output {
10541041
let itctx = ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock);
10551042
Some(hir::FnRetTy::Return(this.lower_ty(ty, &itctx)))
10561043
} else {
10571044
None
10581045
};
10591046

1060-
let async_body = this.make_desugared_coroutine_expr(
1061-
capture_clause,
1062-
inner_closure_id,
1063-
async_ret_ty,
1047+
let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments(
1048+
decl,
1049+
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
10641050
body.span,
1065-
hir::CoroutineDesugaring::Async,
1051+
coroutine_kind,
10661052
hir::CoroutineSource::Closure,
1067-
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
1053+
async_ret_ty,
10681054
);
1069-
let hir_id = this.lower_node_id(inner_closure_id);
1055+
1056+
let hir_id = this.lower_node_id(coroutine_kind.closure_id());
10701057
this.maybe_forward_track_caller(body.span, closure_hir_id, hir_id);
1071-
hir::Expr { hir_id, kind: async_body, span: this.lower_span(body.span) }
1058+
1059+
(parameters, expr)
10721060
});
10731061
body_id
10741062
});
10751063

1064+
let outer_decl =
1065+
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
1066+
10761067
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
10771068
// We need to lower the declaration outside the new scope, because we
10781069
// have to conserve the state of being inside a loop condition for the

0 commit comments

Comments
 (0)