Skip to content

Commit 6095683

Browse files
committed
s/Generator/Coroutine/
1 parent 96027d9 commit 6095683

File tree

310 files changed

+1271
-1271
lines changed

Some content is hidden

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

310 files changed

+1271
-1271
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
132132

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

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

compiler/rustc_ast_lowering/src/expr.rs

+18-18
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),
@@ -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)));
@@ -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.generator_kind = Some(hir::CoroutineKind::Async(async_gen_kind));
641641

642642
let old_ctx = this.task_context;
643643
this.task_context = Some(task_context_hid);
@@ -711,8 +711,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
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);
713713
match self.generator_kind {
714-
Some(hir::GeneratorKind::Async(_)) => {}
715-
Some(hir::GeneratorKind::Gen) | None => {
714+
Some(hir::CoroutineKind::Async(_)) => {}
715+
Some(hir::CoroutineKind::Gen) | None => {
716716
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
717717
await_kw_span,
718718
item_span: self.current_item,
@@ -926,17 +926,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
926926
&mut self,
927927
decl: &FnDecl,
928928
fn_decl_span: Span,
929-
generator_kind: Option<hir::GeneratorKind>,
929+
generator_kind: Option<hir::CoroutineKind>,
930930
movability: Movability,
931931
) -> Option<hir::Movability> {
932932
match generator_kind {
933-
Some(hir::GeneratorKind::Gen) => {
933+
Some(hir::CoroutineKind::Gen) => {
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);
@@ -1445,11 +1445,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
14451445

14461446
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
14471447
match self.generator_kind {
1448-
Some(hir::GeneratorKind::Gen) => {}
1449-
Some(hir::GeneratorKind::Async(_)) => {
1450-
self.tcx.sess.emit_err(AsyncGeneratorsNotSupported { span });
1448+
Some(hir::CoroutineKind::Gen) => {}
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.generator_kind = Some(hir::CoroutineKind::Gen),
14531453
}
14541454

14551455
let expr =

compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -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);

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ 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+
generator_kind: Option<hir::CoroutineKind>,
115115

116116
/// When inside an `async` context, this is the `HirId` of the
117117
/// `task_context` local bound to the resume argument of the generator.

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_errors::{
88
use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
11-
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, LangItem};
11+
use rustc_hir::{AsyncCoroutineKind, CoroutineKind, LangItem};
1212
use rustc_infer::traits::ObligationCause;
1313
use rustc_middle::hir::nested_filter::OnlyBodies;
1414
use rustc_middle::mir::tcx::PlaceTy;
@@ -848,7 +848,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
848848
move_spans.var_subdiag(None, &mut err, None, |kind, var_span| {
849849
use crate::session_diagnostics::CaptureVarCause::*;
850850
match kind {
851-
Some(_) => MoveUseInGenerator { var_span },
851+
Some(_) => MoveUseInCoroutine { var_span },
852852
None => MoveUseInClosure { var_span },
853853
}
854854
});
@@ -894,7 +894,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
894894
let desc_place = self.describe_any_place(place.as_ref());
895895
match kind {
896896
Some(_) => {
897-
BorrowUsePlaceGenerator { place: desc_place, var_span, is_single_var: true }
897+
BorrowUsePlaceCoroutine { place: desc_place, var_span, is_single_var: true }
898898
}
899899
None => BorrowUsePlaceClosure { place: desc_place, var_span, is_single_var: true },
900900
}
@@ -1040,7 +1040,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10401040
|kind, var_span| {
10411041
use crate::session_diagnostics::CaptureVarCause::*;
10421042
match kind {
1043-
Some(_) => BorrowUsePlaceGenerator {
1043+
Some(_) => BorrowUsePlaceCoroutine {
10441044
place: desc_place,
10451045
var_span,
10461046
is_single_var: true,
@@ -1125,7 +1125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11251125
borrow_spans.var_subdiag(None, &mut err, Some(gen_borrow_kind), |kind, var_span| {
11261126
use crate::session_diagnostics::CaptureVarCause::*;
11271127
match kind {
1128-
Some(_) => BorrowUsePlaceGenerator {
1128+
Some(_) => BorrowUsePlaceCoroutine {
11291129
place: desc_place,
11301130
var_span,
11311131
is_single_var: false,
@@ -1146,7 +1146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11461146
let borrow_place_desc = self.describe_any_place(borrow_place.as_ref());
11471147
match kind {
11481148
Some(_) => {
1149-
FirstBorrowUsePlaceGenerator { place: borrow_place_desc, var_span }
1149+
FirstBorrowUsePlaceCoroutine { place: borrow_place_desc, var_span }
11501150
}
11511151
None => FirstBorrowUsePlaceClosure { place: borrow_place_desc, var_span },
11521152
}
@@ -1160,7 +1160,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11601160
|kind, var_span| {
11611161
use crate::session_diagnostics::CaptureVarCause::*;
11621162
match kind {
1163-
Some(_) => SecondBorrowUsePlaceGenerator { place: desc_place, var_span },
1163+
Some(_) => SecondBorrowUsePlaceCoroutine { place: desc_place, var_span },
11641164
None => SecondBorrowUsePlaceClosure { place: desc_place, var_span },
11651165
}
11661166
},
@@ -2077,7 +2077,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20772077
.unwrap_or_else(|| {
20782078
match &self.infcx.tcx.def_kind(self.mir_def_id()) {
20792079
DefKind::Closure => "enclosing closure",
2080-
DefKind::Generator => "enclosing generator",
2080+
DefKind::Coroutine => "enclosing generator",
20812081
kind => bug!("expected closure or generator, found {:?}", kind),
20822082
}
20832083
.to_string()
@@ -2483,12 +2483,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24832483
};
24842484
let kind = match use_span.generator_kind() {
24852485
Some(generator_kind) => match generator_kind {
2486-
GeneratorKind::Async(async_kind) => match async_kind {
2487-
AsyncGeneratorKind::Block => "async block",
2488-
AsyncGeneratorKind::Closure => "async closure",
2486+
CoroutineKind::Async(async_kind) => match async_kind {
2487+
AsyncCoroutineKind::Block => "async block",
2488+
AsyncCoroutineKind::Closure => "async closure",
24892489
_ => bug!("async block/closure expected, but async function found."),
24902490
},
2491-
GeneratorKind::Gen => "generator",
2491+
CoroutineKind::Gen => "generator",
24922492
},
24932493
None => "closure",
24942494
};
@@ -2517,7 +2517,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
25172517
}
25182518
ConstraintCategory::CallArgument(_) => {
25192519
fr_name.highlight_region_name(&mut err);
2520-
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
2520+
if matches!(use_span.generator_kind(), Some(CoroutineKind::Async(_))) {
25212521
err.note(
25222522
"async blocks are not executed immediately and must either take a \
25232523
reference or ownership of outside variables they use",
@@ -2785,7 +2785,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
27852785
loan_spans.var_subdiag(None, &mut err, Some(loan.kind), |kind, var_span| {
27862786
use crate::session_diagnostics::CaptureVarCause::*;
27872787
match kind {
2788-
Some(_) => BorrowUseInGenerator { var_span },
2788+
Some(_) => BorrowUseInCoroutine { var_span },
27892789
None => BorrowUseInClosure { var_span },
27902790
}
27912791
});
@@ -2801,7 +2801,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
28012801
loan_spans.var_subdiag(None, &mut err, Some(loan.kind), |kind, var_span| {
28022802
use crate::session_diagnostics::CaptureVarCause::*;
28032803
match kind {
2804-
Some(_) => BorrowUseInGenerator { var_span },
2804+
Some(_) => BorrowUseInCoroutine { var_span },
28052805
None => BorrowUseInClosure { var_span },
28062806
}
28072807
});

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
182182
// Otherwise, just report the whole type (and use
183183
// the intentionally fuzzy phrase "destructor")
184184
ty::Closure(..) => ("destructor", "closure".to_owned()),
185-
ty::Generator(..) => ("destructor", "generator".to_owned()),
185+
ty::Coroutine(..) => ("destructor", "generator".to_owned()),
186186

187187
_ => ("destructor", format!("type `{}`", local_decl.ty)),
188188
};

compiler/rustc_borrowck/src/diagnostics/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use itertools::Itertools;
88
use rustc_errors::{Applicability, Diagnostic};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, Namespace};
11-
use rustc_hir::GeneratorKind;
11+
use rustc_hir::CoroutineKind;
1212
use rustc_index::IndexSlice;
1313
use rustc_infer::infer::LateBoundRegionConversionTime;
1414
use rustc_middle::mir::tcx::PlaceTy;
@@ -369,7 +369,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
369369
ty::Array(ty, _) | ty::Slice(ty) => {
370370
self.describe_field_from_ty(ty, field, variant_index, including_tuple_field)
371371
}
372-
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
372+
ty::Closure(def_id, _) | ty::Coroutine(def_id, _, _) => {
373373
// We won't be borrowck'ing here if the closure came from another crate,
374374
// so it's safe to call `expect_local`.
375375
//
@@ -502,7 +502,7 @@ pub(super) enum UseSpans<'tcx> {
502502
/// The access is caused by capturing a variable for a closure.
503503
ClosureUse {
504504
/// This is true if the captured variable was from a generator.
505-
generator_kind: Option<GeneratorKind>,
505+
generator_kind: Option<CoroutineKind>,
506506
/// The span of the args of the closure, including the `move` keyword if
507507
/// it's present.
508508
args_span: Span,
@@ -569,7 +569,7 @@ impl UseSpans<'_> {
569569
}
570570
}
571571

572-
pub(super) fn generator_kind(self) -> Option<GeneratorKind> {
572+
pub(super) fn generator_kind(self) -> Option<CoroutineKind> {
573573
match self {
574574
UseSpans::ClosureUse { generator_kind, .. } => generator_kind,
575575
_ => None,
@@ -600,10 +600,10 @@ impl UseSpans<'_> {
600600
match generator_kind {
601601
Some(_) => {
602602
err.subdiagnostic(match action {
603-
Borrow => BorrowInGenerator { path_span },
604-
MatchOn | Use => UseInGenerator { path_span },
605-
Assignment => AssignInGenerator { path_span },
606-
PartialAssignment => AssignPartInGenerator { path_span },
603+
Borrow => BorrowInCoroutine { path_span },
604+
MatchOn | Use => UseInCoroutine { path_span },
605+
Assignment => AssignInCoroutine { path_span },
606+
PartialAssignment => AssignPartInCoroutine { path_span },
607607
});
608608
}
609609
None => {
@@ -624,7 +624,7 @@ impl UseSpans<'_> {
624624
handler: Option<&rustc_errors::Handler>,
625625
err: &mut Diagnostic,
626626
kind: Option<rustc_middle::mir::BorrowKind>,
627-
f: impl FnOnce(Option<GeneratorKind>, Span) -> CaptureVarCause,
627+
f: impl FnOnce(Option<CoroutineKind>, Span) -> CaptureVarCause,
628628
) {
629629
if let UseSpans::ClosureUse { generator_kind, capture_kind_span, path_span, .. } = self {
630630
if capture_kind_span != path_span {
@@ -780,7 +780,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
780780

781781
debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt);
782782
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind
783-
&& let AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) =
783+
&& let AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _, _) =
784784
**kind
785785
{
786786
debug!("move_spans: def_id={:?} places={:?}", def_id, places);
@@ -916,7 +916,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
916916
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind {
917917
let (&def_id, is_generator) = match kind {
918918
box AggregateKind::Closure(def_id, _) => (def_id, false),
919-
box AggregateKind::Generator(def_id, _, _) => (def_id, true),
919+
box AggregateKind::Coroutine(def_id, _, _) => (def_id, true),
920920
_ => continue,
921921
};
922922
let def_id = def_id.expect_local();
@@ -950,7 +950,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
950950
def_id: LocalDefId,
951951
target_place: PlaceRef<'tcx>,
952952
places: &IndexSlice<FieldIdx, Operand<'tcx>>,
953-
) -> Option<(Span, Option<GeneratorKind>, Span, Span)> {
953+
) -> Option<(Span, Option<CoroutineKind>, Span, Span)> {
954954
debug!(
955955
"closure_span: def_id={:?} target_place={:?} places={:?}",
956956
def_id, target_place, places
@@ -1188,7 +1188,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11881188
// another message for the same span
11891189
if !is_loop_message {
11901190
move_spans.var_subdiag(None, err, None, |kind, var_span| match kind {
1191-
Some(_) => CaptureVarCause::PartialMoveUseInGenerator { var_span, is_partial },
1191+
Some(_) => CaptureVarCause::PartialMoveUseInCoroutine { var_span, is_partial },
11921192
None => CaptureVarCause::PartialMoveUseInClosure { var_span, is_partial },
11931193
})
11941194
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
580580
let err = FnMutError {
581581
span: *span,
582582
ty_err: match output_ty.kind() {
583-
ty::Generator(def, ..) if self.infcx.tcx.generator_is_async(*def) => {
583+
ty::Coroutine(def, ..) if self.infcx.tcx.generator_is_async(*def) => {
584584
FnMutReturnTypeErr::ReturnAsyncBlock { span: *span }
585585
}
586586
_ if output_ty.contains_closure() => {
@@ -1036,7 +1036,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10361036
..
10371037
}) => {
10381038
let body = map.body(*body);
1039-
if !matches!(body.generator_kind, Some(hir::GeneratorKind::Async(..))) {
1039+
if !matches!(body.generator_kind, Some(hir::CoroutineKind::Async(..))) {
10401040
closure_span = Some(expr.span.shrink_to_lo());
10411041
}
10421042
}

0 commit comments

Comments
 (0)