Skip to content

Commit d705510

Browse files
authored
Unrolled build for rust-lang#118762
Rollup merge of rust-lang#118762 - compiler-errors:gen-nits, r=eholk Some more minor `async gen`-related nits Tiny tweaks found after `async gen` pr landed r? eholk
2 parents c416699 + 384a49e commit d705510

File tree

8 files changed

+35
-34
lines changed

8 files changed

+35
-34
lines changed

compiler/rustc_ast/src/ast.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,14 @@ impl CoroutineKind {
24502450
matches!(self, CoroutineKind::Gen { .. })
24512451
}
24522452

2453+
pub fn closure_id(self) -> NodeId {
2454+
match self {
2455+
CoroutineKind::Async { closure_id, .. }
2456+
| CoroutineKind::Gen { closure_id, .. }
2457+
| CoroutineKind::AsyncGen { closure_id, .. } => closure_id,
2458+
}
2459+
}
2460+
24532461
/// In this case this is an `async` or `gen` return, the `NodeId` for the generated `impl Trait`
24542462
/// item.
24552463
pub fn return_id(self) -> (NodeId, Span) {

compiler/rustc_ast_lowering/src/item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10351035
let (Some(coroutine_kind), Some(body)) = (coroutine_kind, body) else {
10361036
return self.lower_fn_body_block(span, decl, body);
10371037
};
1038-
// FIXME(gen_blocks): Introduce `closure_id` method and remove ALL destructuring.
1039-
let (CoroutineKind::Async { closure_id, .. }
1040-
| CoroutineKind::Gen { closure_id, .. }
1041-
| CoroutineKind::AsyncGen { closure_id, .. }) = coroutine_kind;
1038+
let closure_id = coroutine_kind.closure_id();
10421039

10431040
self.lower_body(|this| {
10441041
let mut parameters: Vec<hir::Param<'_>> = Vec::new();

compiler/rustc_ast_lowering/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
177177
} else {
178178
[sym::gen_future].into()
179179
},
180-
// FIXME(gen_blocks): how does `closure_track_caller`
180+
// FIXME(gen_blocks): how does `closure_track_caller`/`async_fn_track_caller`
181+
// interact with `gen`/`async gen` blocks
181182
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
182183
generics_def_id_map: Default::default(),
183184
host_param_id: None,

compiler/rustc_ast_passes/src/ast_validation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12711271
// Functions cannot both be `const async` or `const gen`
12721272
if let Some(&FnHeader {
12731273
constness: Const::Yes(cspan),
1274-
coroutine_kind: Some(coro_kind),
1274+
coroutine_kind: Some(coroutine_kind),
12751275
..
12761276
}) = fk.header()
12771277
{
1278-
let aspan = match coro_kind {
1278+
let aspan = match coroutine_kind {
12791279
CoroutineKind::Async { span: aspan, .. }
12801280
| CoroutineKind::Gen { span: aspan, .. }
12811281
| CoroutineKind::AsyncGen { span: aspan, .. } => aspan,

compiler/rustc_builtin_macros/src/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ fn check_test_signature(
541541
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
542542
}
543543

544-
if let Some(coro_kind) = f.sig.header.coroutine_kind {
545-
match coro_kind {
544+
if let Some(coroutine_kind) = f.sig.header.coroutine_kind {
545+
match coroutine_kind {
546546
ast::CoroutineKind::Async { span, .. } => {
547547
return Err(sd.emit_err(errors::TestBadFn {
548548
span: i.span,

compiler/rustc_lint/src/early.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,8 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
162162
// Explicitly check for lints associated with 'closure_id', since
163163
// it does not have a corresponding AST node
164164
if let ast_visit::FnKind::Fn(_, _, sig, _, _, _) = fk {
165-
if let Some(coro_kind) = sig.header.coroutine_kind {
166-
let (ast::CoroutineKind::Async { closure_id, .. }
167-
| ast::CoroutineKind::Gen { closure_id, .. }
168-
| ast::CoroutineKind::AsyncGen { closure_id, .. }) = coro_kind;
169-
self.check_id(closure_id);
165+
if let Some(coroutine_kind) = sig.header.coroutine_kind {
166+
self.check_id(coroutine_kind.closure_id());
170167
}
171168
}
172169
}
@@ -226,12 +223,10 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
226223
// it does not have a corresponding AST node
227224
match e.kind {
228225
ast::ExprKind::Closure(box ast::Closure {
229-
coroutine_kind: Some(coro_kind), ..
226+
coroutine_kind: Some(coroutine_kind),
227+
..
230228
}) => {
231-
let (ast::CoroutineKind::Async { closure_id, .. }
232-
| ast::CoroutineKind::Gen { closure_id, .. }
233-
| ast::CoroutineKind::AsyncGen { closure_id, .. }) = coro_kind;
234-
self.check_id(closure_id);
229+
self.check_id(coroutine_kind.closure_id());
235230
}
236231
_ => {}
237232
}

compiler/rustc_resolve/src/def_collector.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
157157
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
158158
if let FnKind::Fn(_, _, sig, _, generics, body) = fn_kind {
159159
match sig.header.coroutine_kind {
160-
Some(
161-
CoroutineKind::Async { closure_id, .. }
162-
| CoroutineKind::Gen { closure_id, .. }
163-
| CoroutineKind::AsyncGen { closure_id, .. },
164-
) => {
160+
Some(coroutine_kind) => {
165161
self.visit_generics(generics);
166162

167163
// For async functions, we need to create their inner defs inside of a
@@ -176,8 +172,12 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
176172
// then the closure_def will never be used, and we should avoid generating a
177173
// def-id for it.
178174
if let Some(body) = body {
179-
let closure_def =
180-
self.create_def(closure_id, kw::Empty, DefKind::Closure, span);
175+
let closure_def = self.create_def(
176+
coroutine_kind.closure_id(),
177+
kw::Empty,
178+
DefKind::Closure,
179+
span,
180+
);
181181
self.with_parent(closure_def, |this| this.visit_block(body));
182182
}
183183
return;
@@ -289,11 +289,12 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
289289
// we must create two defs.
290290
let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span);
291291
match closure.coroutine_kind {
292-
Some(
293-
CoroutineKind::Async { closure_id, .. }
294-
| CoroutineKind::Gen { closure_id, .. }
295-
| CoroutineKind::AsyncGen { closure_id, .. },
296-
) => self.create_def(closure_id, kw::Empty, DefKind::Closure, expr.span),
292+
Some(coroutine_kind) => self.create_def(
293+
coroutine_kind.closure_id(),
294+
kw::Empty,
295+
DefKind::Closure,
296+
expr.span,
297+
),
297298
None => closure_def,
298299
}
299300
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3144,10 +3144,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31443144
let what = match self.tcx.coroutine_kind(coroutine_def_id) {
31453145
None
31463146
| Some(hir::CoroutineKind::Coroutine)
3147-
| Some(hir::CoroutineKind::Gen(_))
3148-
// FIXME(gen_blocks): This could be yield or await...
3149-
| Some(hir::CoroutineKind::AsyncGen(_)) => "yield",
3147+
| Some(hir::CoroutineKind::Gen(_)) => "yield",
31503148
Some(hir::CoroutineKind::Async(..)) => "await",
3149+
Some(hir::CoroutineKind::AsyncGen(_)) => "yield`/`await",
31513150
};
31523151
err.note(format!(
31533152
"all values live across `{what}` must have a statically known size"

0 commit comments

Comments
 (0)