Skip to content

Commit 249624b

Browse files
committed
Auto merge of rust-lang#116958 - oli-obk:coro, r=pnkfelix
rename Generator to Coroutine implements rust-lang/compiler-team#682 While I did an automated replacement, I went through all changes manually to avoid renaming things like "id generators", "code generator", ... I renamed files where that was necessary due to the contents referring to the crate name itself (mir opt, codegen or debuginfo tests), or required by tidy (feature gate docs) * [x] rename various remaining abbreviated references to generators. * [x] rename files * [x] rename folders * [x] add renamed feature: `generators`, ... r? `@ghost`
2 parents 96027d9 + 258af95 commit 249624b

File tree

595 files changed

+3935
-3916
lines changed

Some content is hidden

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

595 files changed

+3935
-3916
lines changed

Diff for: compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ pub struct LayoutS<FieldIdx: Idx, VariantIdx: Idx> {
15021502
/// Encodes information about multi-variant layouts.
15031503
/// Even with `Multiple` variants, a layout still has its own fields! Those are then
15041504
/// shared between all variants. One of them will be the discriminant,
1505-
/// but e.g. generators can have more.
1505+
/// but e.g. coroutines can have more.
15061506
///
15071507
/// To access all fields of this layout, both `fields` and the fields of the active variant
15081508
/// must be taken into account.

Diff for: compiler/rustc_ast_lowering/messages.ftl

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ ast_lowering_argument = argument
1111
ast_lowering_assoc_ty_parentheses =
1212
parenthesized generic arguments cannot be used in associated type constraints
1313
14-
ast_lowering_async_generators_not_supported =
15-
`async` generators are not yet supported
14+
ast_lowering_async_coroutines_not_supported =
15+
`async` coroutines are not yet supported
1616
1717
ast_lowering_async_non_move_closure_not_supported =
1818
`async` non-`move` closures with parameters are not currently supported
@@ -42,6 +42,9 @@ ast_lowering_clobber_abi_not_supported =
4242
4343
ast_lowering_closure_cannot_be_static = closures cannot be static
4444
45+
ast_lowering_coroutine_too_many_parameters =
46+
too many parameters for a coroutine (expected 0 or 1 parameters)
47+
4548
ast_lowering_does_not_support_modifiers =
4649
the `{$class_name}` register class does not support template modifiers
4750
@@ -53,9 +56,6 @@ ast_lowering_functional_record_update_destructuring_assignment =
5356
functional record updates are not allowed in destructuring assignments
5457
.suggestion = consider removing the trailing pattern
5558
56-
ast_lowering_generator_too_many_parameters =
57-
too many parameters for a generator (expected 0 or 1 parameters)
58-
5959
ast_lowering_generic_type_with_parentheses =
6060
parenthesized type parameters may only be used with a `Fn` trait
6161
.label = only `Fn` traits may use parentheses

Diff for: compiler/rustc_ast_lowering/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
131131
}
132132

133133
#[derive(Diagnostic, Clone, Copy)]
134-
#[diag(ast_lowering_generator_too_many_parameters, code = "E0628")]
135-
pub struct GeneratorTooManyParameters {
134+
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
135+
pub struct CoroutineTooManyParameters {
136136
#[primary_span]
137137
pub fn_decl_span: Span,
138138
}
@@ -161,8 +161,8 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
161161
}
162162

163163
#[derive(Diagnostic, Clone, Copy)]
164-
#[diag(ast_lowering_async_generators_not_supported, code = "E0727")]
165-
pub struct AsyncGeneratorsNotSupported {
164+
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
165+
pub struct AsyncCoroutinesNotSupported {
166166
#[primary_span]
167167
pub span: Span,
168168
}

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::errors::{
2-
AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
3-
BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignment,
4-
GeneratorTooManyParameters, InclusiveRangeWithNoEnd, NotSupportedForLifetimeBinderAsyncClosure,
5-
UnderscoreExprLhsAssign,
2+
AsyncCoroutinesNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
3+
BaseExpressionDoubleDot, ClosureCannotBeStatic, CoroutineTooManyParameters,
4+
FunctionalRecordUpdateDestructuringAssignment, InclusiveRangeWithNoEnd,
5+
NotSupportedForLifetimeBinderAsyncClosure, UnderscoreExprLhsAssign,
66
};
77
use super::ResolverAstLoweringExt;
88
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@@ -188,7 +188,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
188188
e.id,
189189
None,
190190
e.span,
191-
hir::AsyncGeneratorKind::Block,
191+
hir::AsyncCoroutineKind::Block,
192192
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
193193
),
194194
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
@@ -583,7 +583,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
583583
}
584584
}
585585

586-
/// Lower an `async` construct to a generator that implements `Future`.
586+
/// Lower an `async` construct to a coroutine that implements `Future`.
587587
///
588588
/// This results in:
589589
///
@@ -598,7 +598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
598598
closure_node_id: NodeId,
599599
ret_ty: Option<hir::FnRetTy<'hir>>,
600600
span: Span,
601-
async_gen_kind: hir::AsyncGeneratorKind,
601+
async_gen_kind: hir::AsyncCoroutineKind,
602602
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
603603
) -> hir::ExprKind<'hir> {
604604
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
@@ -613,7 +613,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
613613
span: unstable_span,
614614
};
615615

616-
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
616+
// The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`.
617617
let fn_decl = self.arena.alloc(hir::FnDecl {
618618
inputs: arena_vec![self; input_ty],
619619
output,
@@ -637,7 +637,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
637637
let params = arena_vec![self; param];
638638

639639
let body = self.lower_body(move |this| {
640-
this.generator_kind = Some(hir::GeneratorKind::Async(async_gen_kind));
640+
this.coroutine_kind = Some(hir::CoroutineKind::Async(async_gen_kind));
641641

642642
let old_ctx = this.task_context;
643643
this.task_context = Some(task_context_hid);
@@ -710,9 +710,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
710710
/// ```
711711
fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
712712
let full_span = expr.span.to(await_kw_span);
713-
match self.generator_kind {
714-
Some(hir::GeneratorKind::Async(_)) => {}
715-
Some(hir::GeneratorKind::Gen) | None => {
713+
match self.coroutine_kind {
714+
Some(hir::CoroutineKind::Async(_)) => {}
715+
Some(hir::CoroutineKind::Coroutine) | None => {
716716
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
717717
await_kw_span,
718718
item_span: self.current_item,
@@ -887,19 +887,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
887887
) -> hir::ExprKind<'hir> {
888888
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
889889

890-
let (body_id, generator_option) = self.with_new_scopes(move |this| {
890+
let (body_id, coroutine_option) = self.with_new_scopes(move |this| {
891891
let prev = this.current_item;
892892
this.current_item = Some(fn_decl_span);
893-
let mut generator_kind = None;
893+
let mut coroutine_kind = None;
894894
let body_id = this.lower_fn_body(decl, |this| {
895895
let e = this.lower_expr_mut(body);
896-
generator_kind = this.generator_kind;
896+
coroutine_kind = this.coroutine_kind;
897897
e
898898
});
899-
let generator_option =
900-
this.generator_movability_for_fn(&decl, fn_decl_span, generator_kind, movability);
899+
let coroutine_option =
900+
this.coroutine_movability_for_fn(&decl, fn_decl_span, coroutine_kind, movability);
901901
this.current_item = prev;
902-
(body_id, generator_option)
902+
(body_id, coroutine_option)
903903
});
904904

905905
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
@@ -915,28 +915,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
915915
body: body_id,
916916
fn_decl_span: self.lower_span(fn_decl_span),
917917
fn_arg_span: Some(self.lower_span(fn_arg_span)),
918-
movability: generator_option,
918+
movability: coroutine_option,
919919
constness: self.lower_constness(constness),
920920
});
921921

922922
hir::ExprKind::Closure(c)
923923
}
924924

925-
fn generator_movability_for_fn(
925+
fn coroutine_movability_for_fn(
926926
&mut self,
927927
decl: &FnDecl,
928928
fn_decl_span: Span,
929-
generator_kind: Option<hir::GeneratorKind>,
929+
coroutine_kind: Option<hir::CoroutineKind>,
930930
movability: Movability,
931931
) -> Option<hir::Movability> {
932-
match generator_kind {
933-
Some(hir::GeneratorKind::Gen) => {
932+
match coroutine_kind {
933+
Some(hir::CoroutineKind::Coroutine) => {
934934
if decl.inputs.len() > 1 {
935-
self.tcx.sess.emit_err(GeneratorTooManyParameters { fn_decl_span });
935+
self.tcx.sess.emit_err(CoroutineTooManyParameters { fn_decl_span });
936936
}
937937
Some(movability)
938938
}
939-
Some(hir::GeneratorKind::Async(_)) => {
939+
Some(hir::CoroutineKind::Async(_)) => {
940940
panic!("non-`async` closure body turned `async` during lowering");
941941
}
942942
None => {
@@ -1005,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10051005
inner_closure_id,
10061006
async_ret_ty,
10071007
body.span,
1008-
hir::AsyncGeneratorKind::Closure,
1008+
hir::AsyncCoroutineKind::Closure,
10091009
|this| this.with_new_scopes(|this| this.lower_expr_mut(body)),
10101010
);
10111011
let hir_id = this.lower_node_id(inner_closure_id);
@@ -1444,12 +1444,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
14441444
}
14451445

14461446
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
1447-
match self.generator_kind {
1448-
Some(hir::GeneratorKind::Gen) => {}
1449-
Some(hir::GeneratorKind::Async(_)) => {
1450-
self.tcx.sess.emit_err(AsyncGeneratorsNotSupported { span });
1447+
match self.coroutine_kind {
1448+
Some(hir::CoroutineKind::Coroutine) => {}
1449+
Some(hir::CoroutineKind::Async(_)) => {
1450+
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
14511451
}
1452-
None => self.generator_kind = Some(hir::GeneratorKind::Gen),
1452+
None => self.coroutine_kind = Some(hir::CoroutineKind::Coroutine),
14531453
}
14541454

14551455
let expr =

Diff for: compiler/rustc_ast_lowering/src/item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
8282
is_in_loop_condition: false,
8383
is_in_trait_impl: false,
8484
is_in_dyn_type: false,
85-
generator_kind: None,
85+
coroutine_kind: None,
8686
task_context: None,
8787
current_item: None,
8888
impl_trait_defs: Vec::new(),
@@ -974,7 +974,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
974974
value: hir::Expr<'hir>,
975975
) -> hir::BodyId {
976976
let body = hir::Body {
977-
generator_kind: self.generator_kind,
977+
coroutine_kind: self.coroutine_kind,
978978
params,
979979
value: self.arena.alloc(value),
980980
};
@@ -988,12 +988,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
988988
&mut self,
989989
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
990990
) -> hir::BodyId {
991-
let prev_gen_kind = self.generator_kind.take();
991+
let prev_gen_kind = self.coroutine_kind.take();
992992
let task_context = self.task_context.take();
993993
let (parameters, result) = f(self);
994994
let body_id = self.record_body(parameters, result);
995995
self.task_context = task_context;
996-
self.generator_kind = prev_gen_kind;
996+
self.coroutine_kind = prev_gen_kind;
997997
body_id
998998
}
999999

@@ -1206,7 +1206,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12061206
closure_id,
12071207
None,
12081208
body.span,
1209-
hir::AsyncGeneratorKind::Fn,
1209+
hir::AsyncCoroutineKind::Fn,
12101210
|this| {
12111211
// Create a block from the user's function body:
12121212
let user_body = this.lower_block_expr(body);

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ struct LoweringContext<'a, 'hir> {
111111
/// Collect items that were created by lowering the current owner.
112112
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
113113

114-
generator_kind: Option<hir::GeneratorKind>,
114+
coroutine_kind: Option<hir::CoroutineKind>,
115115

116116
/// When inside an `async` context, this is the `HirId` of the
117-
/// `task_context` local bound to the resume argument of the generator.
117+
/// `task_context` local bound to the resume argument of the coroutine.
118118
task_context: Option<hir::HirId>,
119119

120120
/// Used to get the current `fn`'s def span to point to when using `await`

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
554554
"consider removing `for<...>`"
555555
);
556556
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
557-
gate_all!(generators, "yield syntax is experimental");
557+
gate_all!(coroutines, "yield syntax is experimental");
558558
gate_all!(raw_ref_op, "raw address of syntax is experimental");
559559
gate_all!(const_trait_impl, "const trait impls are experimental");
560560
gate_all!(

0 commit comments

Comments
 (0)