diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 3722a0774ba2c..8e7aa59ee341e 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1502,7 +1502,7 @@ pub struct LayoutS { /// Encodes information about multi-variant layouts. /// Even with `Multiple` variants, a layout still has its own fields! Those are then /// shared between all variants. One of them will be the discriminant, - /// but e.g. generators can have more. + /// but e.g. coroutines can have more. /// /// To access all fields of this layout, both `fields` and the fields of the active variant /// must be taken into account. diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index b9fe99ac72fa4..91591a71611b4 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -11,8 +11,8 @@ ast_lowering_argument = argument ast_lowering_assoc_ty_parentheses = parenthesized generic arguments cannot be used in associated type constraints -ast_lowering_async_generators_not_supported = - `async` generators are not yet supported +ast_lowering_async_coroutines_not_supported = + `async` coroutines are not yet supported ast_lowering_async_non_move_closure_not_supported = `async` non-`move` closures with parameters are not currently supported @@ -42,6 +42,9 @@ ast_lowering_clobber_abi_not_supported = ast_lowering_closure_cannot_be_static = closures cannot be static +ast_lowering_coroutine_too_many_parameters = + too many parameters for a coroutine (expected 0 or 1 parameters) + ast_lowering_does_not_support_modifiers = the `{$class_name}` register class does not support template modifiers @@ -53,9 +56,6 @@ ast_lowering_functional_record_update_destructuring_assignment = functional record updates are not allowed in destructuring assignments .suggestion = consider removing the trailing pattern -ast_lowering_generator_too_many_parameters = - too many parameters for a generator (expected 0 or 1 parameters) - ast_lowering_generic_type_with_parentheses = parenthesized type parameters may only be used with a `Fn` trait .label = only `Fn` traits may use parentheses diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index fe0c7d101c19c..6e1a9eff5008d 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -131,8 +131,8 @@ pub struct AwaitOnlyInAsyncFnAndBlocks { } #[derive(Diagnostic, Clone, Copy)] -#[diag(ast_lowering_generator_too_many_parameters, code = "E0628")] -pub struct GeneratorTooManyParameters { +#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")] +pub struct CoroutineTooManyParameters { #[primary_span] pub fn_decl_span: Span, } @@ -161,8 +161,8 @@ pub struct FunctionalRecordUpdateDestructuringAssignment { } #[derive(Diagnostic, Clone, Copy)] -#[diag(ast_lowering_async_generators_not_supported, code = "E0727")] -pub struct AsyncGeneratorsNotSupported { +#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")] +pub struct AsyncCoroutinesNotSupported { #[primary_span] pub span: Span, } diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index dda230282221f..4f1b13870fd46 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1,8 +1,8 @@ use super::errors::{ - AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks, - BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignment, - GeneratorTooManyParameters, InclusiveRangeWithNoEnd, NotSupportedForLifetimeBinderAsyncClosure, - UnderscoreExprLhsAssign, + AsyncCoroutinesNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks, + BaseExpressionDoubleDot, ClosureCannotBeStatic, CoroutineTooManyParameters, + FunctionalRecordUpdateDestructuringAssignment, InclusiveRangeWithNoEnd, + NotSupportedForLifetimeBinderAsyncClosure, UnderscoreExprLhsAssign, }; use super::ResolverAstLoweringExt; use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs}; @@ -188,7 +188,7 @@ impl<'hir> LoweringContext<'_, 'hir> { e.id, None, e.span, - hir::AsyncGeneratorKind::Block, + hir::AsyncCoroutineKind::Block, |this| this.with_new_scopes(|this| this.lower_block_expr(block)), ), ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr), @@ -583,7 +583,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - /// Lower an `async` construct to a generator that implements `Future`. + /// Lower an `async` construct to a coroutine that implements `Future`. /// /// This results in: /// @@ -598,7 +598,7 @@ impl<'hir> LoweringContext<'_, 'hir> { closure_node_id: NodeId, ret_ty: Option>, span: Span, - async_gen_kind: hir::AsyncGeneratorKind, + async_gen_kind: hir::AsyncCoroutineKind, body: impl FnOnce(&mut Self) -> hir::Expr<'hir>, ) -> hir::ExprKind<'hir> { let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span))); @@ -613,7 +613,7 @@ impl<'hir> LoweringContext<'_, 'hir> { span: unstable_span, }; - // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`. + // The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`. let fn_decl = self.arena.alloc(hir::FnDecl { inputs: arena_vec![self; input_ty], output, @@ -637,7 +637,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let params = arena_vec![self; param]; let body = self.lower_body(move |this| { - this.generator_kind = Some(hir::GeneratorKind::Async(async_gen_kind)); + this.coroutine_kind = Some(hir::CoroutineKind::Async(async_gen_kind)); let old_ctx = this.task_context; this.task_context = Some(task_context_hid); @@ -710,9 +710,9 @@ impl<'hir> LoweringContext<'_, 'hir> { /// ``` fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> { let full_span = expr.span.to(await_kw_span); - match self.generator_kind { - Some(hir::GeneratorKind::Async(_)) => {} - Some(hir::GeneratorKind::Gen) | None => { + match self.coroutine_kind { + Some(hir::CoroutineKind::Async(_)) => {} + Some(hir::CoroutineKind::Coroutine) | None => { self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks { await_kw_span, item_span: self.current_item, @@ -887,19 +887,19 @@ impl<'hir> LoweringContext<'_, 'hir> { ) -> hir::ExprKind<'hir> { let (binder_clause, generic_params) = self.lower_closure_binder(binder); - let (body_id, generator_option) = self.with_new_scopes(move |this| { + let (body_id, coroutine_option) = self.with_new_scopes(move |this| { let prev = this.current_item; this.current_item = Some(fn_decl_span); - let mut generator_kind = None; + let mut coroutine_kind = None; let body_id = this.lower_fn_body(decl, |this| { let e = this.lower_expr_mut(body); - generator_kind = this.generator_kind; + coroutine_kind = this.coroutine_kind; e }); - let generator_option = - this.generator_movability_for_fn(&decl, fn_decl_span, generator_kind, movability); + let coroutine_option = + this.coroutine_movability_for_fn(&decl, fn_decl_span, coroutine_kind, movability); this.current_item = prev; - (body_id, generator_option) + (body_id, coroutine_option) }); let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params); @@ -915,28 +915,28 @@ impl<'hir> LoweringContext<'_, 'hir> { body: body_id, fn_decl_span: self.lower_span(fn_decl_span), fn_arg_span: Some(self.lower_span(fn_arg_span)), - movability: generator_option, + movability: coroutine_option, constness: self.lower_constness(constness), }); hir::ExprKind::Closure(c) } - fn generator_movability_for_fn( + fn coroutine_movability_for_fn( &mut self, decl: &FnDecl, fn_decl_span: Span, - generator_kind: Option, + coroutine_kind: Option, movability: Movability, ) -> Option { - match generator_kind { - Some(hir::GeneratorKind::Gen) => { + match coroutine_kind { + Some(hir::CoroutineKind::Coroutine) => { if decl.inputs.len() > 1 { - self.tcx.sess.emit_err(GeneratorTooManyParameters { fn_decl_span }); + self.tcx.sess.emit_err(CoroutineTooManyParameters { fn_decl_span }); } Some(movability) } - Some(hir::GeneratorKind::Async(_)) => { + Some(hir::CoroutineKind::Async(_)) => { panic!("non-`async` closure body turned `async` during lowering"); } None => { @@ -1005,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> { inner_closure_id, async_ret_ty, body.span, - hir::AsyncGeneratorKind::Closure, + hir::AsyncCoroutineKind::Closure, |this| this.with_new_scopes(|this| this.lower_expr_mut(body)), ); let hir_id = this.lower_node_id(inner_closure_id); @@ -1444,12 +1444,12 @@ impl<'hir> LoweringContext<'_, 'hir> { } fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> { - match self.generator_kind { - Some(hir::GeneratorKind::Gen) => {} - Some(hir::GeneratorKind::Async(_)) => { - self.tcx.sess.emit_err(AsyncGeneratorsNotSupported { span }); + match self.coroutine_kind { + Some(hir::CoroutineKind::Coroutine) => {} + Some(hir::CoroutineKind::Async(_)) => { + self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }); } - None => self.generator_kind = Some(hir::GeneratorKind::Gen), + None => self.coroutine_kind = Some(hir::CoroutineKind::Coroutine), } let expr = diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index b73f21433e1f7..3c165f87dbf3d 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -82,7 +82,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { is_in_loop_condition: false, is_in_trait_impl: false, is_in_dyn_type: false, - generator_kind: None, + coroutine_kind: None, task_context: None, current_item: None, impl_trait_defs: Vec::new(), @@ -974,7 +974,7 @@ impl<'hir> LoweringContext<'_, 'hir> { value: hir::Expr<'hir>, ) -> hir::BodyId { let body = hir::Body { - generator_kind: self.generator_kind, + coroutine_kind: self.coroutine_kind, params, value: self.arena.alloc(value), }; @@ -988,12 +988,12 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>), ) -> hir::BodyId { - let prev_gen_kind = self.generator_kind.take(); + let prev_gen_kind = self.coroutine_kind.take(); let task_context = self.task_context.take(); let (parameters, result) = f(self); let body_id = self.record_body(parameters, result); self.task_context = task_context; - self.generator_kind = prev_gen_kind; + self.coroutine_kind = prev_gen_kind; body_id } @@ -1206,7 +1206,7 @@ impl<'hir> LoweringContext<'_, 'hir> { closure_id, None, body.span, - hir::AsyncGeneratorKind::Fn, + hir::AsyncCoroutineKind::Fn, |this| { // Create a block from the user's function body: let user_body = this.lower_block_expr(body); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 68567f97eabce..1e51449e70cc6 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -111,10 +111,10 @@ struct LoweringContext<'a, 'hir> { /// Collect items that were created by lowering the current owner. children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>, - generator_kind: Option, + coroutine_kind: Option, /// When inside an `async` context, this is the `HirId` of the - /// `task_context` local bound to the resume argument of the generator. + /// `task_context` local bound to the resume argument of the coroutine. task_context: Option, /// Used to get the current `fn`'s def span to point to when using `await` diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 9328b83e8f3b0..34532967d9e24 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -554,7 +554,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { "consider removing `for<...>`" ); gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental"); - gate_all!(generators, "yield syntax is experimental"); + gate_all!(coroutines, "yield syntax is experimental"); gate_all!(raw_ref_op, "raw address of syntax is experimental"); gate_all!(const_trait_impl, "const trait impls are experimental"); gate_all!( diff --git a/compiler/rustc_borrowck/messages.ftl b/compiler/rustc_borrowck/messages.ftl index 2c7b97afa8011..8c5a1d8970922 100644 --- a/compiler/rustc_borrowck/messages.ftl +++ b/compiler/rustc_borrowck/messages.ftl @@ -1,20 +1,20 @@ borrowck_assign_due_to_use_closure = assignment occurs due to use in closure -borrowck_assign_due_to_use_generator = - assign occurs due to use in generator +borrowck_assign_due_to_use_coroutine = + assign occurs due to use in coroutine borrowck_assign_part_due_to_use_closure = assignment to part occurs due to use in closure -borrowck_assign_part_due_to_use_generator = - assign to part occurs due to use in generator +borrowck_assign_part_due_to_use_coroutine = + assign to part occurs due to use in coroutine borrowck_borrow_due_to_use_closure = borrow occurs due to use in closure -borrowck_borrow_due_to_use_generator = - borrow occurs due to use in generator +borrowck_borrow_due_to_use_coroutine = + borrow occurs due to use in coroutine borrowck_calling_operator_moves_lhs = calling this operator moves the left-hand side @@ -142,11 +142,11 @@ borrowck_partial_var_move_by_use_in_closure = *[false] moved } due to use in closure -borrowck_partial_var_move_by_use_in_generator = +borrowck_partial_var_move_by_use_in_coroutine = variable {$is_partial -> [true] partially moved *[false] moved - } due to use in generator + } due to use in coroutine borrowck_returned_async_block_escaped = returns an `async` block that contains a reference to a captured variable, which then escapes the closure body @@ -180,15 +180,15 @@ borrowck_ty_no_impl_copy = borrowck_use_due_to_use_closure = use occurs due to use in closure -borrowck_use_due_to_use_generator = - use occurs due to use in generator +borrowck_use_due_to_use_coroutine = + use occurs due to use in coroutine borrowck_used_impl_require_static = the used `impl` has a `'static` requirement borrowck_value_capture_here = value captured {$is_within -> - [true] here by generator + [true] here by coroutine *[false] here } @@ -207,8 +207,8 @@ borrowck_value_moved_here = borrowck_var_borrow_by_use_in_closure = borrow occurs due to use in closure -borrowck_var_borrow_by_use_in_generator = - borrow occurs due to use in generator +borrowck_var_borrow_by_use_in_coroutine = + borrow occurs due to use in coroutine borrowck_var_borrow_by_use_place_in_closure = {$is_single_var -> @@ -216,11 +216,11 @@ borrowck_var_borrow_by_use_place_in_closure = [false] borrows occur } due to use of {$place} in closure -borrowck_var_borrow_by_use_place_in_generator = +borrowck_var_borrow_by_use_place_in_coroutine = {$is_single_var -> *[true] borrow occurs [false] borrows occur - } due to use of {$place} in generator + } due to use of {$place} in coroutine borrowck_var_cannot_escape_closure = captured variable cannot escape `FnMut` closure body @@ -234,8 +234,8 @@ borrowck_var_does_not_need_mut = borrowck_var_first_borrow_by_use_place_in_closure = first borrow occurs due to use of {$place} in closure -borrowck_var_first_borrow_by_use_place_in_generator = - first borrow occurs due to use of {$place} in generator +borrowck_var_first_borrow_by_use_place_in_coroutine = + first borrow occurs due to use of {$place} in coroutine borrowck_var_here_captured = variable captured here @@ -244,8 +244,8 @@ borrowck_var_here_defined = variable defined here borrowck_var_move_by_use_in_closure = move occurs due to use in closure -borrowck_var_move_by_use_in_generator = - move occurs due to use in generator +borrowck_var_move_by_use_in_coroutine = + move occurs due to use in coroutine borrowck_var_mutable_borrow_by_use_place_in_closure = mutable borrow occurs due to use of {$place} in closure @@ -253,5 +253,5 @@ borrowck_var_mutable_borrow_by_use_place_in_closure = borrowck_var_second_borrow_by_use_place_in_closure = second borrow occurs due to use of {$place} in closure -borrowck_var_second_borrow_by_use_place_in_generator = - second borrow occurs due to use of {$place} in generator +borrowck_var_second_borrow_by_use_place_in_coroutine = + second borrow occurs due to use of {$place} in coroutine diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index a2c7e767b4cc2..2ceec1b5658de 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -368,7 +368,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { err } - pub(crate) fn cannot_borrow_across_generator_yield( + pub(crate) fn cannot_borrow_across_coroutine_yield( &self, span: Span, yield_span: Span, @@ -377,7 +377,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { self, span, E0626, - "borrow may still be in use when generator yields", + "borrow may still be in use when coroutine yields", ); err.span_label(yield_span, "possible yield occurs here"); err diff --git a/compiler/rustc_borrowck/src/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs index b719a610e07c7..201f0df123879 100644 --- a/compiler/rustc_borrowck/src/def_use.rs +++ b/compiler/rustc_borrowck/src/def_use.rs @@ -44,7 +44,7 @@ pub fn categorize(context: PlaceContext) -> Option { PlaceContext::MutatingUse(MutatingUseContext::Projection) | // Borrows only consider their local used at the point of the borrow. - // This won't affect the results since we use this analysis for generators + // This won't affect the results since we use this analysis for coroutines // and we only care about the result at suspension points. Borrows cannot // cross suspension points so this behavior is unproblematic. PlaceContext::MutatingUse(MutatingUseContext::Borrow) | diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 20a4402f6f699..00816c0f2539c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -8,7 +8,7 @@ use rustc_errors::{ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; -use rustc_hir::{AsyncGeneratorKind, GeneratorKind, LangItem}; +use rustc_hir::{AsyncCoroutineKind, CoroutineKind, LangItem}; use rustc_infer::traits::ObligationCause; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::mir::tcx::PlaceTy; @@ -848,7 +848,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { move_spans.var_subdiag(None, &mut err, None, |kind, var_span| { use crate::session_diagnostics::CaptureVarCause::*; match kind { - Some(_) => MoveUseInGenerator { var_span }, + Some(_) => MoveUseInCoroutine { var_span }, None => MoveUseInClosure { var_span }, } }); @@ -894,7 +894,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let desc_place = self.describe_any_place(place.as_ref()); match kind { Some(_) => { - BorrowUsePlaceGenerator { place: desc_place, var_span, is_single_var: true } + BorrowUsePlaceCoroutine { place: desc_place, var_span, is_single_var: true } } None => BorrowUsePlaceClosure { place: desc_place, var_span, is_single_var: true }, } @@ -926,8 +926,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let borrow_spans = self.borrow_spans(span, location); let span = borrow_spans.args_or_use(); - let container_name = if issued_spans.for_generator() || borrow_spans.for_generator() { - "generator" + let container_name = if issued_spans.for_coroutine() || borrow_spans.for_coroutine() { + "coroutine" } else { "closure" }; @@ -1040,7 +1040,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { |kind, var_span| { use crate::session_diagnostics::CaptureVarCause::*; match kind { - Some(_) => BorrowUsePlaceGenerator { + Some(_) => BorrowUsePlaceCoroutine { place: desc_place, var_span, is_single_var: true, @@ -1125,7 +1125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { borrow_spans.var_subdiag(None, &mut err, Some(gen_borrow_kind), |kind, var_span| { use crate::session_diagnostics::CaptureVarCause::*; match kind { - Some(_) => BorrowUsePlaceGenerator { + Some(_) => BorrowUsePlaceCoroutine { place: desc_place, var_span, is_single_var: false, @@ -1146,7 +1146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let borrow_place_desc = self.describe_any_place(borrow_place.as_ref()); match kind { Some(_) => { - FirstBorrowUsePlaceGenerator { place: borrow_place_desc, var_span } + FirstBorrowUsePlaceCoroutine { place: borrow_place_desc, var_span } } None => FirstBorrowUsePlaceClosure { place: borrow_place_desc, var_span }, } @@ -1160,7 +1160,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { |kind, var_span| { use crate::session_diagnostics::CaptureVarCause::*; match kind { - Some(_) => SecondBorrowUsePlaceGenerator { place: desc_place, var_span }, + Some(_) => SecondBorrowUsePlaceCoroutine { place: desc_place, var_span }, None => SecondBorrowUsePlaceClosure { place: desc_place, var_span }, } }, @@ -1575,7 +1575,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // Get closure's arguments let ty::Closure(_, args) = typeck_results.expr_ty(closure_expr).kind() else { - /* hir::Closure can be a generator too */ + /* hir::Closure can be a coroutine too */ return; }; let sig = args.as_closure().sig(); @@ -1949,7 +1949,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ( Some(name), BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _), - ) if borrow_spans.for_generator() || borrow_spans.for_closure() => self + ) if borrow_spans.for_coroutine() || borrow_spans.for_closure() => self .report_escaping_closure_capture( borrow_spans, borrow_span, @@ -1974,7 +1974,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { span, .. }, - ) if borrow_spans.for_generator() || borrow_spans.for_closure() => self + ) if borrow_spans.for_coroutine() || borrow_spans.for_closure() => self .report_escaping_closure_capture( borrow_spans, borrow_span, @@ -2077,8 +2077,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .unwrap_or_else(|| { match &self.infcx.tcx.def_kind(self.mir_def_id()) { DefKind::Closure => "enclosing closure", - DefKind::Generator => "enclosing generator", - kind => bug!("expected closure or generator, found {:?}", kind), + DefKind::Coroutine => "enclosing coroutine", + kind => bug!("expected closure or coroutine, found {:?}", kind), } .to_string() }) @@ -2112,7 +2112,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { borrow_spans.args_subdiag(&mut err, |args_span| { crate::session_diagnostics::CaptureArgLabel::Capture { - is_within: borrow_spans.for_generator(), + is_within: borrow_spans.for_coroutine(), args_span, } }); @@ -2353,7 +2353,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { borrow_spans.args_subdiag(&mut err, |args_span| { crate::session_diagnostics::CaptureArgLabel::Capture { - is_within: borrow_spans.for_generator(), + is_within: borrow_spans.for_coroutine(), args_span, } }); @@ -2481,14 +2481,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } Err(_) => (args_span, "move || "), }; - let kind = match use_span.generator_kind() { - Some(generator_kind) => match generator_kind { - GeneratorKind::Async(async_kind) => match async_kind { - AsyncGeneratorKind::Block => "async block", - AsyncGeneratorKind::Closure => "async closure", + let kind = match use_span.coroutine_kind() { + Some(coroutine_kind) => match coroutine_kind { + CoroutineKind::Async(async_kind) => match async_kind { + AsyncCoroutineKind::Block => "async block", + AsyncCoroutineKind::Closure => "async closure", _ => bug!("async block/closure expected, but async function found."), }, - GeneratorKind::Gen => "generator", + CoroutineKind::Coroutine => "coroutine", }, None => "closure", }; @@ -2517,7 +2517,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } ConstraintCategory::CallArgument(_) => { fr_name.highlight_region_name(&mut err); - if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) { + if matches!(use_span.coroutine_kind(), Some(CoroutineKind::Async(_))) { err.note( "async blocks are not executed immediately and must either take a \ reference or ownership of outside variables they use", @@ -2785,7 +2785,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { loan_spans.var_subdiag(None, &mut err, Some(loan.kind), |kind, var_span| { use crate::session_diagnostics::CaptureVarCause::*; match kind { - Some(_) => BorrowUseInGenerator { var_span }, + Some(_) => BorrowUseInCoroutine { var_span }, None => BorrowUseInClosure { var_span }, } }); @@ -2801,7 +2801,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { loan_spans.var_subdiag(None, &mut err, Some(loan.kind), |kind, var_span| { use crate::session_diagnostics::CaptureVarCause::*; match kind { - Some(_) => BorrowUseInGenerator { var_span }, + Some(_) => BorrowUseInCoroutine { var_span }, None => BorrowUseInClosure { var_span }, } }); diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index c9514f5604c08..8a930ca59a334 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -182,7 +182,7 @@ impl<'tcx> BorrowExplanation<'tcx> { // Otherwise, just report the whole type (and use // the intentionally fuzzy phrase "destructor") ty::Closure(..) => ("destructor", "closure".to_owned()), - ty::Generator(..) => ("destructor", "generator".to_owned()), + ty::Coroutine(..) => ("destructor", "coroutine".to_owned()), _ => ("destructor", format!("type `{}`", local_decl.ty)), }; diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 8f5d5e67a7a9d..47a387e25e3a4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -8,7 +8,7 @@ use itertools::Itertools; use rustc_errors::{Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, Namespace}; -use rustc_hir::GeneratorKind; +use rustc_hir::CoroutineKind; use rustc_index::IndexSlice; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_middle::mir::tcx::PlaceTy; @@ -369,7 +369,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ty::Array(ty, _) | ty::Slice(ty) => { self.describe_field_from_ty(ty, field, variant_index, including_tuple_field) } - ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => { + ty::Closure(def_id, _) | ty::Coroutine(def_id, _, _) => { // We won't be borrowck'ing here if the closure came from another crate, // so it's safe to call `expect_local`. // @@ -501,8 +501,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { pub(super) enum UseSpans<'tcx> { /// The access is caused by capturing a variable for a closure. ClosureUse { - /// This is true if the captured variable was from a generator. - generator_kind: Option, + /// This is true if the captured variable was from a coroutine. + coroutine_kind: Option, /// The span of the args of the closure, including the `move` keyword if /// it's present. args_span: Span, @@ -569,9 +569,9 @@ impl UseSpans<'_> { } } - pub(super) fn generator_kind(self) -> Option { + pub(super) fn coroutine_kind(self) -> Option { match self { - UseSpans::ClosureUse { generator_kind, .. } => generator_kind, + UseSpans::ClosureUse { coroutine_kind, .. } => coroutine_kind, _ => None, } } @@ -596,14 +596,14 @@ impl UseSpans<'_> { ) { use crate::InitializationRequiringAction::*; use CaptureVarPathUseCause::*; - if let UseSpans::ClosureUse { generator_kind, path_span, .. } = self { - match generator_kind { + if let UseSpans::ClosureUse { coroutine_kind, path_span, .. } = self { + match coroutine_kind { Some(_) => { err.subdiagnostic(match action { - Borrow => BorrowInGenerator { path_span }, - MatchOn | Use => UseInGenerator { path_span }, - Assignment => AssignInGenerator { path_span }, - PartialAssignment => AssignPartInGenerator { path_span }, + Borrow => BorrowInCoroutine { path_span }, + MatchOn | Use => UseInCoroutine { path_span }, + Assignment => AssignInCoroutine { path_span }, + PartialAssignment => AssignPartInCoroutine { path_span }, }); } None => { @@ -624,9 +624,9 @@ impl UseSpans<'_> { handler: Option<&rustc_errors::Handler>, err: &mut Diagnostic, kind: Option, - f: impl FnOnce(Option, Span) -> CaptureVarCause, + f: impl FnOnce(Option, Span) -> CaptureVarCause, ) { - if let UseSpans::ClosureUse { generator_kind, capture_kind_span, path_span, .. } = self { + if let UseSpans::ClosureUse { coroutine_kind, capture_kind_span, path_span, .. } = self { if capture_kind_span != path_span { err.subdiagnostic(match kind { Some(kd) => match kd { @@ -642,7 +642,7 @@ impl UseSpans<'_> { None => CaptureVarKind::Move { kind_span: capture_kind_span }, }); }; - let diag = f(generator_kind, path_span); + let diag = f(coroutine_kind, path_span); match handler { Some(hd) => err.eager_subdiagnostic(hd, diag), None => err.subdiagnostic(diag), @@ -653,15 +653,15 @@ impl UseSpans<'_> { /// Returns `false` if this place is not used in a closure. pub(super) fn for_closure(&self) -> bool { match *self { - UseSpans::ClosureUse { generator_kind, .. } => generator_kind.is_none(), + UseSpans::ClosureUse { coroutine_kind, .. } => coroutine_kind.is_none(), _ => false, } } - /// Returns `false` if this place is not used in a generator. - pub(super) fn for_generator(&self) -> bool { + /// Returns `false` if this place is not used in a coroutine. + pub(super) fn for_coroutine(&self) -> bool { match *self { - UseSpans::ClosureUse { generator_kind, .. } => generator_kind.is_some(), + UseSpans::ClosureUse { coroutine_kind, .. } => coroutine_kind.is_some(), _ => false, } } @@ -780,15 +780,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt); if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind - && let AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) = + && let AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _, _) = **kind { debug!("move_spans: def_id={:?} places={:?}", def_id, places); let def_id = def_id.expect_local(); - if let Some((args_span, generator_kind, capture_kind_span, path_span)) = + if let Some((args_span, coroutine_kind, capture_kind_span, path_span)) = self.closure_span(def_id, moved_place, places) { - return ClosureUse { generator_kind, args_span, capture_kind_span, path_span }; + return ClosureUse { coroutine_kind, args_span, capture_kind_span, path_span }; } } @@ -800,11 +800,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { | FakeReadCause::ForLet(Some(closure_def_id)) => { debug!("move_spans: def_id={:?} place={:?}", closure_def_id, place); let places = &[Operand::Move(place)]; - if let Some((args_span, generator_kind, capture_kind_span, path_span)) = + if let Some((args_span, coroutine_kind, capture_kind_span, path_span)) = self.closure_span(closure_def_id, moved_place, IndexSlice::from_raw(places)) { return ClosureUse { - generator_kind, + coroutine_kind, args_span, capture_kind_span, path_span, @@ -914,21 +914,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { for stmt in statements.chain(maybe_additional_statement) { if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind { - let (&def_id, is_generator) = match kind { + let (&def_id, is_coroutine) = match kind { box AggregateKind::Closure(def_id, _) => (def_id, false), - box AggregateKind::Generator(def_id, _, _) => (def_id, true), + box AggregateKind::Coroutine(def_id, _, _) => (def_id, true), _ => continue, }; let def_id = def_id.expect_local(); debug!( - "borrow_spans: def_id={:?} is_generator={:?} places={:?}", - def_id, is_generator, places + "borrow_spans: def_id={:?} is_coroutine={:?} places={:?}", + def_id, is_coroutine, places ); - if let Some((args_span, generator_kind, capture_kind_span, path_span)) = + if let Some((args_span, coroutine_kind, capture_kind_span, path_span)) = self.closure_span(def_id, Place::from(target).as_ref(), places) { - return ClosureUse { generator_kind, args_span, capture_kind_span, path_span }; + return ClosureUse { coroutine_kind, args_span, capture_kind_span, path_span }; } else { return OtherUse(use_span); } @@ -942,7 +942,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { OtherUse(use_span) } - /// Finds the spans of a captured place within a closure or generator. + /// Finds the spans of a captured place within a closure or coroutine. /// The first span is the location of the use resulting in the capture kind of the capture /// The second span is the location the use resulting in the captured path of the capture fn closure_span( @@ -950,7 +950,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { def_id: LocalDefId, target_place: PlaceRef<'tcx>, places: &IndexSlice>, - ) -> Option<(Span, Option, Span, Span)> { + ) -> Option<(Span, Option, Span, Span)> { debug!( "closure_span: def_id={:?} target_place={:?} places={:?}", def_id, target_place, places @@ -968,11 +968,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { { debug!("closure_span: found captured local {:?}", place); let body = self.infcx.tcx.hir().body(body); - let generator_kind = body.generator_kind(); + let coroutine_kind = body.coroutine_kind(); return Some(( fn_decl_span, - generator_kind, + coroutine_kind, captured_place.get_capture_kind_span(self.infcx.tcx), captured_place.get_path_span(self.infcx.tcx), )); @@ -1188,7 +1188,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // another message for the same span if !is_loop_message { move_spans.var_subdiag(None, err, None, |kind, var_span| match kind { - Some(_) => CaptureVarCause::PartialMoveUseInGenerator { var_span, is_partial }, + Some(_) => CaptureVarCause::PartialMoveUseInCoroutine { var_span, is_partial }, None => CaptureVarCause::PartialMoveUseInClosure { var_span, is_partial }, }) } diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index e5ffc8a11142b..003254b8da1ec 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -62,7 +62,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { local, projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)], } => { - debug_assert!(is_closure_or_generator( + debug_assert!(is_closure_or_coroutine( Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty )); @@ -122,7 +122,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { { item_msg = access_place_desc; debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref()); - debug_assert!(is_closure_or_generator( + debug_assert!(is_closure_or_coroutine( the_place_err.ty(self.body, self.infcx.tcx).ty )); @@ -385,7 +385,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { local, projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)], } => { - debug_assert!(is_closure_or_generator( + debug_assert!(is_closure_or_coroutine( Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty )); @@ -1377,8 +1377,8 @@ fn suggest_ampmut<'tcx>( } } -fn is_closure_or_generator(ty: Ty<'_>) -> bool { - ty.is_closure() || ty.is_generator() +fn is_closure_or_coroutine(ty: Ty<'_>) -> bool { + ty.is_closure() || ty.is_coroutine() } /// Given a field that needs to be mutable, returns a span where the " mut " could go. diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 27072a60f65f0..a0a809123c0f9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -580,7 +580,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let err = FnMutError { span: *span, ty_err: match output_ty.kind() { - ty::Generator(def, ..) if self.infcx.tcx.generator_is_async(*def) => { + ty::Coroutine(def, ..) if self.infcx.tcx.coroutine_is_async(*def) => { FnMutReturnTypeErr::ReturnAsyncBlock { span: *span } } _ if output_ty.contains_closure() => { @@ -1036,7 +1036,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { .. }) => { let body = map.body(*body); - if !matches!(body.generator_kind, Some(hir::GeneratorKind::Async(..))) { + if !matches!(body.coroutine_kind, Some(hir::CoroutineKind::Async(..))) { closure_span = Some(expr.span.shrink_to_lo()); } } diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index f8883c53d5713..de9ece3faba4d 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -41,7 +41,7 @@ pub(crate) enum RegionNameSource { AnonRegionFromUpvar(Span, Symbol), /// The region corresponding to the return type of a closure. AnonRegionFromOutput(RegionNameHighlight, &'static str), - /// The region from a type yielded by a generator. + /// The region from a type yielded by a coroutine. AnonRegionFromYieldTy(Span, String), /// An anonymous region from an async fn. AnonRegionFromAsyncFn(Span), @@ -322,7 +322,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { let def_ty = self.regioncx.universal_regions().defining_ty; let DefiningTy::Closure(_, args) = def_ty else { - // Can't have BrEnv in functions, constants or generators. + // Can't have BrEnv in functions, constants or coroutines. bug!("BrEnv outside of closure."); }; let hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }) = @@ -680,16 +680,16 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { } hir::FnRetTy::Return(hir_ty) => (fn_decl.output.span(), Some(hir_ty)), }; - let mir_description = match hir.body(body).generator_kind { - Some(hir::GeneratorKind::Async(gen)) => match gen { - hir::AsyncGeneratorKind::Block => " of async block", - hir::AsyncGeneratorKind::Closure => " of async closure", - hir::AsyncGeneratorKind::Fn => { + let mir_description = match hir.body(body).coroutine_kind { + Some(hir::CoroutineKind::Async(gen)) => match gen { + hir::AsyncCoroutineKind::Block => " of async block", + hir::AsyncCoroutineKind::Closure => " of async closure", + hir::AsyncCoroutineKind::Fn => { let parent_item = hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id); let output = &parent_item .fn_decl() - .expect("generator lowered from async fn should be in fn") + .expect("coroutine lowered from async fn should be in fn") .output; span = output.span(); if let hir::FnRetTy::Return(ret) = output { @@ -698,7 +698,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { " of async function" } }, - Some(hir::GeneratorKind::Gen) => " of generator", + Some(hir::CoroutineKind::Coroutine) => " of coroutine", None => " of closure", }; (span, mir_description, hir_ty) @@ -793,7 +793,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { &self, fr: RegionVid, ) -> Option { - // Note: generators from `async fn` yield `()`, so we don't have to + // Note: coroutines from `async fn` yield `()`, so we don't have to // worry about them here. let yield_ty = self.regioncx.universal_regions().yield_ty?; debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty); diff --git a/compiler/rustc_borrowck/src/invalidation.rs b/compiler/rustc_borrowck/src/invalidation.rs index 84be50a641694..7b5b52e39b121 100644 --- a/compiler/rustc_borrowck/src/invalidation.rs +++ b/compiler/rustc_borrowck/src/invalidation.rs @@ -161,7 +161,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { } TerminatorKind::UnwindResume | TerminatorKind::Return - | TerminatorKind::GeneratorDrop => { + | TerminatorKind::CoroutineDrop => { // Invalidate all borrows of local places let borrow_set = self.borrow_set; let start = self.location_table.start_index(location); diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index d274a3eea6ca9..ee34be847cc09 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -302,11 +302,11 @@ fn do_mir_borrowck<'tcx>( .pass_name("borrowck") .iterate_to_fixpoint(); - let movable_generator = - // The first argument is the generator type passed by value + let movable_coroutine = + // The first argument is the coroutine type passed by value if let Some(local) = body.local_decls.raw.get(1) // Get the interior types and args which typeck computed - && let ty::Generator(_, _, hir::Movability::Static) = local.ty.kind() + && let ty::Coroutine(_, _, hir::Movability::Static) = local.ty.kind() { false } else { @@ -323,7 +323,7 @@ fn do_mir_borrowck<'tcx>( body: promoted_body, move_data: &move_data, location_table, // no need to create a real one for the promoted, it is not used - movable_generator, + movable_coroutine, fn_self_span_reported: Default::default(), locals_are_invalidated_at_exit, access_place_error_reported: Default::default(), @@ -351,7 +351,7 @@ fn do_mir_borrowck<'tcx>( body, move_data: &mdpe.move_data, location_table, - movable_generator, + movable_coroutine, locals_are_invalidated_at_exit, fn_self_span_reported: Default::default(), access_place_error_reported: Default::default(), @@ -536,7 +536,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> { /// when MIR borrowck begins. location_table: &'cx LocationTable, - movable_generator: bool, + movable_coroutine: bool, /// This keeps track of whether local variables are free-ed when the function /// exits even without a `StorageDead`, which appears to be the case for /// constants. @@ -778,7 +778,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro | TerminatorKind::Unreachable | TerminatorKind::UnwindResume | TerminatorKind::Return - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { real_target: _, imaginary_target: _ } | TerminatorKind::FalseUnwind { real_target: _, unwind: _ } => { // no data used, thus irrelevant to borrowck @@ -797,7 +797,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro match term.kind { TerminatorKind::Yield { value: _, resume: _, resume_arg: _, drop: _ } => { - if self.movable_generator { + if self.movable_coroutine { // Look for any active borrows to locals let borrow_set = self.borrow_set.clone(); for i in flow_state.borrows.iter() { @@ -809,7 +809,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro TerminatorKind::UnwindResume | TerminatorKind::Return - | TerminatorKind::GeneratorDrop => { + | TerminatorKind::CoroutineDrop => { // Returning from the function implicitly kills storage for all locals and statics. // Often, the storage will already have been killed by an explicit // StorageDead, but we don't always emit those (notably on unwind paths), @@ -1326,7 +1326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // moved into the closure and subsequently used by the closure, // in order to populate our used_mut set. match **aggregate_kind { - AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => { + AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _, _) => { let def_id = def_id.expect_local(); let BorrowCheckResult { used_mut_upvars, .. } = self.infcx.tcx.mir_borrowck(def_id); @@ -1549,12 +1549,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } /// Reports an error if this is a borrow of local data. - /// This is called for all Yield expressions on movable generators + /// This is called for all Yield expressions on movable coroutines fn check_for_local_borrow(&mut self, borrow: &BorrowData<'tcx>, yield_span: Span) { debug!("check_for_local_borrow({:?})", borrow); if borrow_of_local_data(borrow.borrowed_place) { - let err = self.cannot_borrow_across_generator_yield( + let err = self.cannot_borrow_across_coroutine_yield( self.retrieve_borrow_spans(borrow).var_or_use(), yield_span, ); diff --git a/compiler/rustc_borrowck/src/path_utils.rs b/compiler/rustc_borrowck/src/path_utils.rs index ed93a560981e4..51e318f085438 100644 --- a/compiler/rustc_borrowck/src/path_utils.rs +++ b/compiler/rustc_borrowck/src/path_utils.rs @@ -137,7 +137,7 @@ pub(super) fn is_active<'tcx>( } /// Determines if a given borrow is borrowing local data -/// This is called for all Yield expressions on movable generators +/// This is called for all Yield expressions on movable coroutines pub(super) fn borrow_of_local_data(place: Place<'_>) -> bool { // Reborrow of already borrowed data is ignored // Any errors will be caught on the initial borrow @@ -165,7 +165,7 @@ pub(crate) fn is_upvar_field_projection<'tcx>( match place_ref.last_projection() { Some((place_base, ProjectionElem::Field(field, _ty))) => { let base_ty = place_base.ty(body, tcx).ty; - if (base_ty.is_closure() || base_ty.is_generator()) + if (base_ty.is_closure() || base_ty.is_coroutine()) && (!by_ref || upvars[field.index()].by_ref) { Some(field) diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index ca3ccf439f280..e321b92603d38 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -139,23 +139,23 @@ pub(crate) enum RequireStaticErr { #[derive(Subdiagnostic)] pub(crate) enum CaptureVarPathUseCause { - #[label(borrowck_borrow_due_to_use_generator)] - BorrowInGenerator { + #[label(borrowck_borrow_due_to_use_coroutine)] + BorrowInCoroutine { #[primary_span] path_span: Span, }, - #[label(borrowck_use_due_to_use_generator)] - UseInGenerator { + #[label(borrowck_use_due_to_use_coroutine)] + UseInCoroutine { #[primary_span] path_span: Span, }, - #[label(borrowck_assign_due_to_use_generator)] - AssignInGenerator { + #[label(borrowck_assign_due_to_use_coroutine)] + AssignInCoroutine { #[primary_span] path_span: Span, }, - #[label(borrowck_assign_part_due_to_use_generator)] - AssignPartInGenerator { + #[label(borrowck_assign_part_due_to_use_coroutine)] + AssignPartInCoroutine { #[primary_span] path_span: Span, }, @@ -202,8 +202,8 @@ pub(crate) enum CaptureVarKind { #[derive(Subdiagnostic)] pub(crate) enum CaptureVarCause { - #[label(borrowck_var_borrow_by_use_place_in_generator)] - BorrowUsePlaceGenerator { + #[label(borrowck_var_borrow_by_use_place_in_coroutine)] + BorrowUsePlaceCoroutine { is_single_var: bool, place: String, #[primary_span] @@ -216,8 +216,8 @@ pub(crate) enum CaptureVarCause { #[primary_span] var_span: Span, }, - #[label(borrowck_var_borrow_by_use_in_generator)] - BorrowUseInGenerator { + #[label(borrowck_var_borrow_by_use_in_coroutine)] + BorrowUseInCoroutine { #[primary_span] var_span: Span, }, @@ -226,8 +226,8 @@ pub(crate) enum CaptureVarCause { #[primary_span] var_span: Span, }, - #[label(borrowck_var_move_by_use_in_generator)] - MoveUseInGenerator { + #[label(borrowck_var_move_by_use_in_coroutine)] + MoveUseInCoroutine { #[primary_span] var_span: Span, }, @@ -236,8 +236,8 @@ pub(crate) enum CaptureVarCause { #[primary_span] var_span: Span, }, - #[label(borrowck_var_first_borrow_by_use_place_in_generator)] - FirstBorrowUsePlaceGenerator { + #[label(borrowck_var_first_borrow_by_use_place_in_coroutine)] + FirstBorrowUsePlaceCoroutine { place: String, #[primary_span] var_span: Span, @@ -248,8 +248,8 @@ pub(crate) enum CaptureVarCause { #[primary_span] var_span: Span, }, - #[label(borrowck_var_second_borrow_by_use_place_in_generator)] - SecondBorrowUsePlaceGenerator { + #[label(borrowck_var_second_borrow_by_use_place_in_coroutine)] + SecondBorrowUsePlaceCoroutine { place: String, #[primary_span] var_span: Span, @@ -266,8 +266,8 @@ pub(crate) enum CaptureVarCause { #[primary_span] var_span: Span, }, - #[label(borrowck_partial_var_move_by_use_in_generator)] - PartialMoveUseInGenerator { + #[label(borrowck_partial_var_move_by_use_in_coroutine)] + PartialMoveUseInCoroutine { #[primary_span] var_span: Span, is_partial: bool, diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index eec886b7be48f..d053d0a4b3bad 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); // We will not have a universal_regions.yield_ty if we yield (by accident) - // outside of a generator and return an `impl Trait`, so emit a delay_span_bug + // outside of a coroutine and return an `impl Trait`, so emit a delay_span_bug // because we don't want to panic in an assert here if we've already got errors. if body.yield_ty().is_some() != universal_regions.yield_ty.is_some() { self.tcx().sess.delay_span_bug( diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index 21da05c32dd86..80e6c6c1dfb77 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -101,7 +101,7 @@ pub(super) fn trace<'mir, 'tcx>( results.dropck_boring_locals(boring_locals); } -/// Contextual state for the type-liveness generator. +/// Contextual state for the type-liveness coroutine. struct LivenessContext<'me, 'typeck, 'flow, 'tcx> { /// Current type-checker, giving us our inference context etc. typeck: &'me mut TypeChecker<'typeck, 'tcx>, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 1ec0e62d16a3b..9eb02be2f155b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -671,8 +671,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { PlaceTy { ty: base_ty, variant_index: Some(index) } } } - // We do not need to handle generators here, because this runs - // before the generator transform stage. + // We do not need to handle coroutines here, because this runs + // before the coroutine transform stage. _ => { let ty = if let Some(name) = maybe_name { span_mirbug_and_err!( @@ -774,13 +774,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { let (variant, args) = match base_ty { PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() { ty::Adt(adt_def, args) => (adt_def.variant(variant_index), args), - ty::Generator(def_id, args, _) => { - let mut variants = args.as_generator().state_tys(def_id, tcx); + ty::Coroutine(def_id, args, _) => { + let mut variants = args.as_coroutine().state_tys(def_id, tcx); let Some(mut variant) = variants.nth(variant_index.into()) else { bug!( - "variant_index of generator out of range: {:?}/{:?}", + "variant_index of coroutine out of range: {:?}/{:?}", variant_index, - args.as_generator().state_tys(def_id, tcx).count() + args.as_coroutine().state_tys(def_id, tcx).count() ); }; return match variant.nth(field.index()) { @@ -788,7 +788,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { None => Err(FieldAccessError::OutOfRange { field_count: variant.count() }), }; } - _ => bug!("can't have downcast of non-adt non-generator type"), + _ => bug!("can't have downcast of non-adt non-coroutine type"), }, PlaceTy { ty, variant_index: None } => match *ty.kind() { ty::Adt(adt_def, args) if !adt_def.is_enum() => { @@ -802,13 +802,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { }), }; } - ty::Generator(_, args, _) => { + ty::Coroutine(_, args, _) => { // Only prefix fields (upvars and current state) are // accessible without a variant index. - return match args.as_generator().prefix_tys().get(field.index()) { + return match args.as_coroutine().prefix_tys().get(field.index()) { Some(ty) => Ok(*ty), None => Err(FieldAccessError::OutOfRange { - field_count: args.as_generator().prefix_tys().len(), + field_count: args.as_coroutine().prefix_tys().len(), }), }; } @@ -1351,7 +1351,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { | TerminatorKind::UnwindResume | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } | TerminatorKind::FalseEdge { .. } @@ -1468,7 +1468,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let value_ty = value.ty(body, tcx); match body.yield_ty() { - None => span_mirbug!(self, term, "yield in non-generator"), + None => span_mirbug!(self, term, "yield in non-coroutine"), Some(ty) => { if let Err(terr) = self.sub_types( value_ty, @@ -1648,9 +1648,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, block_data, "return on cleanup block") } } - TerminatorKind::GeneratorDrop { .. } => { + TerminatorKind::CoroutineDrop { .. } => { if is_cleanup { - span_mirbug!(self, block_data, "generator_drop in cleanup block") + span_mirbug!(self, block_data, "coroutine_drop in cleanup block") } } TerminatorKind::Yield { resume, drop, .. } => { @@ -1797,14 +1797,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { }), } } - AggregateKind::Generator(_, args, _) => { + AggregateKind::Coroutine(_, args, _) => { // It doesn't make sense to look at a field beyond the prefix; // these require a variant index, and are not initialized in // aggregate rvalues. - match args.as_generator().prefix_tys().get(field_index.as_usize()) { + match args.as_coroutine().prefix_tys().get(field_index.as_usize()) { Some(ty) => Ok(*ty), None => Err(FieldAccessError::OutOfRange { - field_count: args.as_generator().prefix_tys().len(), + field_count: args.as_coroutine().prefix_tys().len(), }), } } @@ -2397,7 +2397,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { AggregateKind::Array(_) => None, AggregateKind::Tuple => None, AggregateKind::Closure(_, _) => None, - AggregateKind::Generator(_, _, _) => None, + AggregateKind::Coroutine(_, _, _) => None, }, } } @@ -2625,7 +2625,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // desugaring. A closure gets desugared to a struct, and // these extra requirements are basically like where // clauses on the struct. - AggregateKind::Closure(def_id, args) | AggregateKind::Generator(def_id, args, _) => { + AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args, _) => { (def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location)) } @@ -2673,7 +2673,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let parent_args = match tcx.def_kind(def_id) { DefKind::Closure => args.as_closure().parent_args(), - DefKind::Generator => args.as_generator().parent_args(), + DefKind::Coroutine => args.as_coroutine().parent_args(), DefKind::InlineConst => args.as_inline_const().parent_args(), other => bug!("unexpected item {:?}", other), }; diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index c73192f440451..7897a5a63ba8f 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -58,7 +58,7 @@ pub struct UniversalRegions<'tcx> { num_universals: usize, /// The "defining" type for this function, with all universal - /// regions instantiated. For a closure or generator, this is the + /// regions instantiated. For a closure or coroutine, this is the /// closure type, but for a top-level function it's the `FnDef`. pub defining_ty: DefiningTy<'tcx>, @@ -91,10 +91,10 @@ pub enum DefiningTy<'tcx> { /// `ClosureArgs::closure_sig_ty`. Closure(DefId, GenericArgsRef<'tcx>), - /// The MIR is a generator. The signature is that generators take + /// The MIR is a coroutine. The signature is that coroutines take /// no parameters and return the result of - /// `ClosureArgs::generator_return_ty`. - Generator(DefId, GenericArgsRef<'tcx>, hir::Movability), + /// `ClosureArgs::coroutine_return_ty`. + Coroutine(DefId, GenericArgsRef<'tcx>, hir::Movability), /// The MIR is a fn item with the given `DefId` and args. The signature /// of the function can be bound then with the `fn_sig` query. @@ -112,13 +112,13 @@ pub enum DefiningTy<'tcx> { impl<'tcx> DefiningTy<'tcx> { /// Returns a list of all the upvar types for this MIR. If this is - /// not a closure or generator, there are no upvars, and hence it + /// not a closure or coroutine, there are no upvars, and hence it /// will be an empty list. The order of types in this list will /// match up with the upvar order in the HIR, typesystem, and MIR. pub fn upvar_tys(self) -> &'tcx ty::List> { match self { DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(), - DefiningTy::Generator(_, args, _) => args.as_generator().upvar_tys(), + DefiningTy::Coroutine(_, args, _) => args.as_coroutine().upvar_tys(), DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => { ty::List::empty() } @@ -130,7 +130,7 @@ impl<'tcx> DefiningTy<'tcx> { /// user's code. pub fn implicit_inputs(self) -> usize { match self { - DefiningTy::Closure(..) | DefiningTy::Generator(..) => 1, + DefiningTy::Closure(..) | DefiningTy::Coroutine(..) => 1, DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => 0, } } @@ -146,7 +146,7 @@ impl<'tcx> DefiningTy<'tcx> { pub fn def_id(&self) -> DefId { match *self { DefiningTy::Closure(def_id, ..) - | DefiningTy::Generator(def_id, ..) + | DefiningTy::Coroutine(def_id, ..) | DefiningTy::FnDef(def_id, ..) | DefiningTy::Const(def_id, ..) | DefiningTy::InlineConst(def_id, ..) => def_id, @@ -178,7 +178,7 @@ pub enum RegionClassification { Global, /// An **external** region is only relevant for - /// closures, generators, and inline consts. In that + /// closures, coroutines, and inline consts. In that /// case, it refers to regions that are free in the type /// -- basically, something bound in the surrounding context. /// @@ -196,7 +196,7 @@ pub enum RegionClassification { /// Here, the lifetimes `'a` and `'b` would be **external** to the /// closure. /// - /// If we are not analyzing a closure/generator/inline-const, + /// If we are not analyzing a closure/coroutine/inline-const, /// there are no external lifetimes. External, @@ -354,7 +354,7 @@ impl<'tcx> UniversalRegions<'tcx> { err.note(format!("late-bound region is {:?}", self.to_region_vid(r))); }); } - DefiningTy::Generator(def_id, args, _) => { + DefiningTy::Coroutine(def_id, args, _) => { let v = with_no_trimmed_paths!( args[tcx.generics_of(def_id).parent_count..] .iter() @@ -362,7 +362,7 @@ impl<'tcx> UniversalRegions<'tcx> { .collect::>() ); err.note(format!( - "defining type: {} with generator args [\n {},\n]", + "defining type: {} with coroutine args [\n {},\n]", tcx.def_path_str_with_args(def_id, args), v.join(",\n "), )); @@ -426,13 +426,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let typeck_root_def_id = self.infcx.tcx.typeck_root_def_id(self.mir_def.to_def_id()); - // If this is a 'root' body (not a closure/generator/inline const), then + // If this is a 'root' body (not a closure/coroutine/inline const), then // there are no extern regions, so the local regions start at the same // position as the (empty) sub-list of extern regions let first_local_index = if self.mir_def.to_def_id() == typeck_root_def_id { first_extern_index } else { - // If this is a closure, generator, or inline-const, then the late-bound regions from the enclosing + // If this is a closure, coroutine, or inline-const, then the late-bound regions from the enclosing // function/closures are actually external regions to us. For example, here, 'a is not local // to the closure c (although it is local to the fn foo): // fn foo<'a>() { @@ -528,7 +528,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { debug!("build: local regions = {}..{}", first_local_index, num_universals); let yield_ty = match defining_ty { - DefiningTy::Generator(_, args, _) => Some(args.as_generator().yield_ty()), + DefiningTy::Coroutine(_, args, _) => Some(args.as_coroutine().yield_ty()), _ => None, }; @@ -563,8 +563,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { match *defining_ty.kind() { ty::Closure(def_id, args) => DefiningTy::Closure(def_id, args), - ty::Generator(def_id, args, movability) => { - DefiningTy::Generator(def_id, args, movability) + ty::Coroutine(def_id, args, movability) => { + DefiningTy::Coroutine(def_id, args, movability) } ty::FnDef(def_id, args) => DefiningTy::FnDef(def_id, args), _ => span_bug!( @@ -621,7 +621,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id); let fr_args = match defining_ty { DefiningTy::Closure(_, args) - | DefiningTy::Generator(_, args, _) + | DefiningTy::Coroutine(_, args, _) | DefiningTy::InlineConst(_, args) => { // In the case of closures, we rely on the fact that // the first N elements in the ClosureArgs are @@ -686,13 +686,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { ) } - DefiningTy::Generator(def_id, args, movability) => { + DefiningTy::Coroutine(def_id, args, movability) => { assert_eq!(self.mir_def.to_def_id(), def_id); - let resume_ty = args.as_generator().resume_ty(); - let output = args.as_generator().return_ty(); - let generator_ty = Ty::new_generator(tcx, def_id, args, movability); + let resume_ty = args.as_coroutine().resume_ty(); + let output = args.as_coroutine().return_ty(); + let coroutine_ty = Ty::new_coroutine(tcx, def_id, args, movability); let inputs_and_output = - self.infcx.tcx.mk_type_list(&[generator_ty, resume_ty, output]); + self.infcx.tcx.mk_type_list(&[coroutine_ty, resume_ty, output]); ty::Binder::dummy(inputs_and_output) } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 9c57f68f0b81e..c7999a226c7d9 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -179,7 +179,7 @@ fn entry_point_type(item: &ast::Item, at_root: bool) -> EntryPointType { } /// A folder used to remove any entry points (like fn main) because the harness -/// generator will provide its own +/// coroutine will provide its own struct EntryPointCleaner<'a> { // Current depth in the ast sess: &'a Session, diff --git a/compiler/rustc_codegen_cranelift/example/std_example.rs b/compiler/rustc_codegen_cranelift/example/std_example.rs index 490cc2404f626..9bd2ab5c638c1 100644 --- a/compiler/rustc_codegen_cranelift/example/std_example.rs +++ b/compiler/rustc_codegen_cranelift/example/std_example.rs @@ -1,7 +1,7 @@ #![feature( core_intrinsics, - generators, - generator_trait, + coroutines, + coroutine_trait, is_sorted, repr_simd, tuple_trait, @@ -12,7 +12,7 @@ use std::arch::x86_64::*; use std::hint::black_box; use std::io::Write; -use std::ops::Generator; +use std::ops::Coroutine; fn main() { println!("{:?}", std::env::args().collect::>()); diff --git a/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh b/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh index 3b2a12ec0280a..c83efa51e9ea1 100755 --- a/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh +++ b/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh @@ -157,7 +157,7 @@ rm -r tests/run-make/compressed-debuginfo rm -r tests/run-make/extern-fn-explicit-align # argument alignment not yet supported -rm tests/ui/codegen/subtyping-enforces-type-equality.rs # assert_assignable bug with Generator's +rm tests/ui/codegen/subtyping-enforces-type-equality.rs # assert_assignable bug with Coroutine's # bugs in the test suite # ====================== diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index ac7389792c80c..80e7c5bd9edbc 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -478,7 +478,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { TerminatorKind::Yield { .. } | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } - | TerminatorKind::GeneratorDrop => { + | TerminatorKind::CoroutineDrop => { bug!("shouldn't exist at codegen {:?}", bb_data.terminator()); } TerminatorKind::Drop { place, target, unwind: _, replace: _ } => { diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 1cb6fa0772314..b0853d30e03b8 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -510,7 +510,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( | TerminatorKind::Drop { .. } | TerminatorKind::Assert { .. } => {} TerminatorKind::Yield { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => unreachable!(), TerminatorKind::InlineAsm { .. } => return None, diff --git a/compiler/rustc_codegen_gcc/example/std_example.rs b/compiler/rustc_codegen_gcc/example/std_example.rs index 18f2ddcde126b..dc0aad04a78f3 100644 --- a/compiler/rustc_codegen_gcc/example/std_example.rs +++ b/compiler/rustc_codegen_gcc/example/std_example.rs @@ -1,9 +1,9 @@ -#![feature(core_intrinsics, generators, generator_trait, is_sorted)] +#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted)] #[cfg(feature="master")] use std::arch::x86_64::*; use std::io::Write; -use std::ops::Generator; +use std::ops::Coroutine; extern { pub fn printf(format: *const i8, ...) -> i32; diff --git a/compiler/rustc_codegen_gcc/src/type_of.rs b/compiler/rustc_codegen_gcc/src/type_of.rs index c2eab295acd29..357ce6226592e 100644 --- a/compiler/rustc_codegen_gcc/src/type_of.rs +++ b/compiler/rustc_codegen_gcc/src/type_of.rs @@ -87,7 +87,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout // FIXME(eddyb) producing readable type names for trait objects can result // in problematically distinct types due to HRTB and subtyping (see #47638). // ty::Dynamic(..) | - ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str + ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str if !cx.sess().fewer_names() => { let mut name = with_no_trimmed_paths!(layout.ty.to_string()); @@ -98,10 +98,10 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout write!(&mut name, "::{}", def.variant(index).name).unwrap(); } } - if let (&ty::Generator(_, _, _), &Variants::Single { index }) = + if let (&ty::Coroutine(_, _, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { - write!(&mut name, "::{}", ty::GeneratorArgs::variant_name(index)).unwrap(); + write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); } Some(name) } diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 411620c9e493c..f75add90aa2cf 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -313,7 +313,7 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) { // generic functions from consideration as well. if !matches!( kind, - DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator + DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine ) { return None; } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 4f8ae2ddb8f9e..865bf01c8c1e0 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -460,7 +460,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D } ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id), ty::Closure(..) => build_closure_env_di_node(cx, unique_type_id), - ty::Generator(..) => enums::build_generator_di_node(cx, unique_type_id), + ty::Coroutine(..) => enums::build_coroutine_di_node(cx, unique_type_id), ty::Adt(def, ..) => match def.adt_kind() { AdtKind::Struct => build_struct_type_di_node(cx, unique_type_id), AdtKind::Union => build_union_type_di_node(cx, unique_type_id), @@ -1026,20 +1026,20 @@ fn build_struct_type_di_node<'ll, 'tcx>( // Tuples //=----------------------------------------------------------------------------- -/// Builds the DW_TAG_member debuginfo nodes for the upvars of a closure or generator. -/// For a generator, this will handle upvars shared by all states. +/// Builds the DW_TAG_member debuginfo nodes for the upvars of a closure or coroutine. +/// For a coroutine, this will handle upvars shared by all states. fn build_upvar_field_di_nodes<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - closure_or_generator_ty: Ty<'tcx>, - closure_or_generator_di_node: &'ll DIType, + closure_or_coroutine_ty: Ty<'tcx>, + closure_or_coroutine_di_node: &'ll DIType, ) -> SmallVec<&'ll DIType> { - let (&def_id, up_var_tys) = match closure_or_generator_ty.kind() { - ty::Generator(def_id, args, _) => (def_id, args.as_generator().prefix_tys()), + let (&def_id, up_var_tys) = match closure_or_coroutine_ty.kind() { + ty::Coroutine(def_id, args, _) => (def_id, args.as_coroutine().prefix_tys()), ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()), _ => { bug!( - "build_upvar_field_di_nodes() called with non-closure-or-generator-type: {:?}", - closure_or_generator_ty + "build_upvar_field_di_nodes() called with non-closure-or-coroutine-type: {:?}", + closure_or_coroutine_ty ) } }; @@ -1049,7 +1049,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>( ); let capture_names = cx.tcx.closure_saved_names_of_captured_variables(def_id); - let layout = cx.layout_of(closure_or_generator_ty); + let layout = cx.layout_of(closure_or_coroutine_ty); up_var_tys .into_iter() @@ -1058,7 +1058,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>( .map(|(index, (up_var_ty, capture_name))| { build_field_di_node( cx, - closure_or_generator_di_node, + closure_or_coroutine_di_node, capture_name.as_str(), cx.size_and_align_of(up_var_ty), layout.fields.offset(index), diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 88040557a9b33..ca7bfbeac25ce 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -12,7 +12,7 @@ use rustc_middle::{ ty::{ self, layout::{LayoutOf, TyAndLayout}, - AdtDef, GeneratorArgs, Ty, + AdtDef, CoroutineArgs, Ty, }, }; use rustc_target::abi::{Align, Endian, Size, TagEncoding, VariantIdx, Variants}; @@ -268,18 +268,18 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( ) } -/// A generator debuginfo node looks the same as a that of an enum type. +/// A coroutine debuginfo node looks the same as a that of an enum type. /// /// See [build_enum_type_di_node] for more information. -pub(super) fn build_generator_di_node<'ll, 'tcx>( +pub(super) fn build_coroutine_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { - let generator_type = unique_type_id.expect_ty(); - let generator_type_and_layout = cx.layout_of(generator_type); - let generator_type_name = compute_debuginfo_type_name(cx.tcx, generator_type, false); + let coroutine_type = unique_type_id.expect_ty(); + let coroutine_type_and_layout = cx.layout_of(coroutine_type); + let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); - debug_assert!(!wants_c_like_enum_debuginfo(generator_type_and_layout)); + debug_assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout)); type_map::build_type_with_children( cx, @@ -287,24 +287,24 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>( cx, type_map::Stub::Union, unique_type_id, - &generator_type_name, - size_and_align_of(generator_type_and_layout), + &coroutine_type_name, + size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, ), - |cx, generator_type_di_node| match generator_type_and_layout.variants { + |cx, coroutine_type_di_node| match coroutine_type_and_layout.variants { Variants::Multiple { tag_encoding: TagEncoding::Direct, .. } => { - build_union_fields_for_direct_tag_generator( + build_union_fields_for_direct_tag_coroutine( cx, - generator_type_and_layout, - generator_type_di_node, + coroutine_type_and_layout, + coroutine_type_di_node, ) } Variants::Single { .. } | Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, .. } => { bug!( - "Encountered generator with non-direct-tag layout: {:?}", - generator_type_and_layout + "Encountered coroutine with non-direct-tag layout: {:?}", + coroutine_type_and_layout ) } }, @@ -428,7 +428,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>( }) .collect(); - build_union_fields_for_direct_tag_enum_or_generator( + build_union_fields_for_direct_tag_enum_or_coroutine( cx, enum_type_and_layout, enum_type_di_node, @@ -469,8 +469,8 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - enum_or_generator_type_and_layout: TyAndLayout<'tcx>, - enum_or_generator_type_di_node: &'ll DIType, + enum_or_coroutine_type_and_layout: TyAndLayout<'tcx>, + enum_or_coroutine_type_di_node: &'ll DIType, variant_index: VariantIdx, untagged_variant_index: Option, variant_struct_type_di_node: &'ll DIType, @@ -486,13 +486,13 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( Stub::Struct, UniqueTypeId::for_enum_variant_struct_type_wrapper( cx.tcx, - enum_or_generator_type_and_layout.ty, + enum_or_coroutine_type_and_layout.ty, variant_index, ), &variant_struct_wrapper_type_name(variant_index), // NOTE: We use size and align of enum_type, not from variant_layout: - size_and_align_of(enum_or_generator_type_and_layout), - Some(enum_or_generator_type_di_node), + size_and_align_of(enum_or_coroutine_type_and_layout), + Some(enum_or_coroutine_type_di_node), DIFlags::FlagZero, ), |cx, wrapper_struct_type_di_node| { @@ -535,7 +535,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( cx, wrapper_struct_type_di_node, "value", - size_and_align_of(enum_or_generator_type_and_layout), + size_and_align_of(enum_or_coroutine_type_and_layout), Size::ZERO, DIFlags::FlagZero, variant_struct_type_di_node, @@ -662,40 +662,40 @@ fn split_128(value: u128) -> Split128 { Split128 { hi: (value >> 64) as u64, lo: value as u64 } } -fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>( +fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - generator_type_and_layout: TyAndLayout<'tcx>, - generator_type_di_node: &'ll DIType, + coroutine_type_and_layout: TyAndLayout<'tcx>, + coroutine_type_di_node: &'ll DIType, ) -> SmallVec<&'ll DIType> { let Variants::Multiple { tag_encoding: TagEncoding::Direct, tag_field, .. } = - generator_type_and_layout.variants + coroutine_type_and_layout.variants else { bug!("This function only supports layouts with directly encoded tags.") }; - let (generator_def_id, generator_args) = match generator_type_and_layout.ty.kind() { - &ty::Generator(def_id, args, _) => (def_id, args.as_generator()), + let (coroutine_def_id, coroutine_args) = match coroutine_type_and_layout.ty.kind() { + &ty::Coroutine(def_id, args, _) => (def_id, args.as_coroutine()), _ => unreachable!(), }; - let generator_layout = cx.tcx.optimized_mir(generator_def_id).generator_layout().unwrap(); + let coroutine_layout = cx.tcx.optimized_mir(coroutine_def_id).coroutine_layout().unwrap(); - let common_upvar_names = cx.tcx.closure_saved_names_of_captured_variables(generator_def_id); - let variant_range = generator_args.variant_range(generator_def_id, cx.tcx); + let common_upvar_names = cx.tcx.closure_saved_names_of_captured_variables(coroutine_def_id); + let variant_range = coroutine_args.variant_range(coroutine_def_id, cx.tcx); let variant_count = (variant_range.start.as_u32()..variant_range.end.as_u32()).len(); - let tag_base_type = tag_base_type(cx, generator_type_and_layout); + let tag_base_type = tag_base_type(cx, coroutine_type_and_layout); let variant_names_type_di_node = build_variant_names_type_di_node( cx, - generator_type_di_node, + coroutine_type_di_node, variant_range .clone() - .map(|variant_index| (variant_index, GeneratorArgs::variant_name(variant_index))), + .map(|variant_index| (variant_index, CoroutineArgs::variant_name(variant_index))), ); let discriminants: IndexVec = { - let discriminants_iter = generator_args.discriminants(generator_def_id, cx.tcx); + let discriminants_iter = coroutine_args.discriminants(coroutine_def_id, cx.tcx); let mut discriminants: IndexVec = IndexVec::with_capacity(variant_count); for (variant_index, discr) in discriminants_iter { @@ -709,16 +709,16 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>( // Build the type node for each field. let variant_field_infos: SmallVec> = variant_range .map(|variant_index| { - let variant_struct_type_di_node = super::build_generator_variant_struct_type_di_node( + let variant_struct_type_di_node = super::build_coroutine_variant_struct_type_di_node( cx, variant_index, - generator_type_and_layout, - generator_type_di_node, - generator_layout, + coroutine_type_and_layout, + coroutine_type_di_node, + coroutine_layout, &common_upvar_names, ); - let span = generator_layout.variant_source_info[variant_index].span; + let span = coroutine_layout.variant_source_info[variant_index].span; let source_info = if !span.is_dummy() { let loc = cx.lookup_debug_loc(span.lo()); Some((file_metadata(cx, &loc.file), loc.line as c_uint)) @@ -735,10 +735,10 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>( }) .collect(); - build_union_fields_for_direct_tag_enum_or_generator( + build_union_fields_for_direct_tag_enum_or_coroutine( cx, - generator_type_and_layout, - generator_type_di_node, + coroutine_type_and_layout, + coroutine_type_di_node, &variant_field_infos[..], variant_names_type_di_node, tag_base_type, @@ -747,9 +747,9 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>( ) } -/// This is a helper function shared between enums and generators that makes sure fields have the +/// This is a helper function shared between enums and coroutines that makes sure fields have the /// expect names. -fn build_union_fields_for_direct_tag_enum_or_generator<'ll, 'tcx>( +fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, enum_type_and_layout: TyAndLayout<'tcx>, enum_type_di_node: &'ll DIType, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index d3239d5c358f5..df1df6d197e23 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -6,11 +6,11 @@ use rustc_hir::def::CtorKind; use rustc_index::IndexSlice; use rustc_middle::{ bug, - mir::GeneratorLayout, + mir::CoroutineLayout, ty::{ self, layout::{IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout}, - AdtDef, GeneratorArgs, Ty, VariantDef, + AdtDef, CoroutineArgs, Ty, VariantDef, }, }; use rustc_span::Symbol; @@ -66,14 +66,14 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( } } -pub(super) fn build_generator_di_node<'ll, 'tcx>( +pub(super) fn build_coroutine_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { if cpp_like_debuginfo(cx.tcx) { - cpp_like::build_generator_di_node(cx, unique_type_id) + cpp_like::build_coroutine_di_node(cx, unique_type_id) } else { - native::build_generator_di_node(cx, unique_type_id) + native::build_coroutine_di_node(cx, unique_type_id) } } @@ -101,13 +101,13 @@ fn build_c_style_enum_di_node<'ll, 'tcx>( } } -/// Extract the type with which we want to describe the tag of the given enum or generator. +/// Extract the type with which we want to describe the tag of the given enum or coroutine. fn tag_base_type<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, enum_type_and_layout: TyAndLayout<'tcx>, ) -> Ty<'tcx> { debug_assert!(match enum_type_and_layout.ty.kind() { - ty::Generator(..) => true, + ty::Coroutine(..) => true, ty::Adt(adt_def, _) => adt_def.is_enum(), _ => false, }); @@ -300,8 +300,8 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( .di_node } -/// Build the struct type for describing a single generator state. -/// See [build_generator_variant_struct_type_di_node]. +/// Build the struct type for describing a single coroutine state. +/// See [build_coroutine_variant_struct_type_di_node]. /// /// ```txt /// @@ -317,25 +317,25 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( /// ---> DW_TAG_structure_type (type of variant 3) /// /// ``` -pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>( +pub fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, variant_index: VariantIdx, - generator_type_and_layout: TyAndLayout<'tcx>, - generator_type_di_node: &'ll DIType, - generator_layout: &GeneratorLayout<'tcx>, + coroutine_type_and_layout: TyAndLayout<'tcx>, + coroutine_type_di_node: &'ll DIType, + coroutine_layout: &CoroutineLayout<'tcx>, common_upvar_names: &IndexSlice, ) -> &'ll DIType { - let variant_name = GeneratorArgs::variant_name(variant_index); + let variant_name = CoroutineArgs::variant_name(variant_index); let unique_type_id = UniqueTypeId::for_enum_variant_struct_type( cx.tcx, - generator_type_and_layout.ty, + coroutine_type_and_layout.ty, variant_index, ); - let variant_layout = generator_type_and_layout.for_variant(cx, variant_index); + let variant_layout = coroutine_type_and_layout.for_variant(cx, variant_index); - let generator_args = match generator_type_and_layout.ty.kind() { - ty::Generator(_, args, _) => args.as_generator(), + let coroutine_args = match coroutine_type_and_layout.ty.kind() { + ty::Coroutine(_, args, _) => args.as_coroutine(), _ => unreachable!(), }; @@ -346,17 +346,17 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &variant_name, - size_and_align_of(generator_type_and_layout), - Some(generator_type_di_node), + size_and_align_of(coroutine_type_and_layout), + Some(coroutine_type_di_node), DIFlags::FlagZero, ), |cx, variant_struct_type_di_node| { // Fields that just belong to this variant/state let state_specific_fields: SmallVec<_> = (0..variant_layout.fields.count()) .map(|field_index| { - let generator_saved_local = generator_layout.variant_fields[variant_index] + let coroutine_saved_local = coroutine_layout.variant_fields[variant_index] [FieldIdx::from_usize(field_index)]; - let field_name_maybe = generator_layout.field_names[generator_saved_local]; + let field_name_maybe = coroutine_layout.field_names[coroutine_saved_local]; let field_name = field_name_maybe .as_ref() .map(|s| Cow::from(s.as_str())) @@ -377,7 +377,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>( .collect(); // Fields that are common to all states - let common_fields: SmallVec<_> = generator_args + let common_fields: SmallVec<_> = coroutine_args .prefix_tys() .iter() .zip(common_upvar_names) @@ -388,7 +388,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>( variant_struct_type_di_node, upvar_name.as_str(), cx.size_and_align_of(upvar_ty), - generator_type_and_layout.fields.offset(index), + coroutine_type_and_layout.fields.offset(index), DIFlags::FlagZero, type_di_node(cx, upvar_ty), ) @@ -397,7 +397,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>( state_specific_fields.into_iter().chain(common_fields.into_iter()).collect() }, - |cx| build_generic_type_param_di_nodes(cx, generator_type_and_layout.ty), + |cx| build_generic_type_param_di_nodes(cx, coroutine_type_and_layout.ty), ) .di_node } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs index feac40d8c306c..7eff52b857f8e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -110,12 +110,12 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( ) } -/// Build the debuginfo node for a generator environment. It looks the same as the debuginfo for +/// Build the debuginfo node for a coroutine environment. It looks the same as the debuginfo for /// an enum. See [build_enum_type_di_node] for more information. /// /// ```txt /// -/// ---> DW_TAG_structure_type (top-level type for the generator) +/// ---> DW_TAG_structure_type (top-level type for the coroutine) /// DW_TAG_variant_part (variant part) /// DW_AT_discr (reference to discriminant DW_TAG_member) /// DW_TAG_member (discriminant member) @@ -127,21 +127,21 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( /// DW_TAG_structure_type (type of variant 3) /// /// ``` -pub(super) fn build_generator_di_node<'ll, 'tcx>( +pub(super) fn build_coroutine_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { - let generator_type = unique_type_id.expect_ty(); - let &ty::Generator(generator_def_id, _, _) = generator_type.kind() else { - bug!("build_generator_di_node() called with non-generator type: `{:?}`", generator_type) + let coroutine_type = unique_type_id.expect_ty(); + let &ty::Coroutine(coroutine_def_id, _, _) = coroutine_type.kind() else { + bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) }; - let containing_scope = get_namespace_for_item(cx, generator_def_id); - let generator_type_and_layout = cx.layout_of(generator_type); + let containing_scope = get_namespace_for_item(cx, coroutine_def_id); + let coroutine_type_and_layout = cx.layout_of(coroutine_type); - debug_assert!(!wants_c_like_enum_debuginfo(generator_type_and_layout)); + debug_assert!(!wants_c_like_enum_debuginfo(coroutine_type_and_layout)); - let generator_type_name = compute_debuginfo_type_name(cx.tcx, generator_type, false); + let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); type_map::build_type_with_children( cx, @@ -149,37 +149,37 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>( cx, Stub::Struct, unique_type_id, - &generator_type_name, - size_and_align_of(generator_type_and_layout), + &coroutine_type_name, + size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, ), - |cx, generator_type_di_node| { - let generator_layout = - cx.tcx.optimized_mir(generator_def_id).generator_layout().unwrap(); + |cx, coroutine_type_di_node| { + let coroutine_layout = + cx.tcx.optimized_mir(coroutine_def_id).coroutine_layout().unwrap(); let Variants::Multiple { tag_encoding: TagEncoding::Direct, ref variants, .. } = - generator_type_and_layout.variants + coroutine_type_and_layout.variants else { bug!( - "Encountered generator with non-direct-tag layout: {:?}", - generator_type_and_layout + "Encountered coroutine with non-direct-tag layout: {:?}", + coroutine_type_and_layout ) }; let common_upvar_names = - cx.tcx.closure_saved_names_of_captured_variables(generator_def_id); + cx.tcx.closure_saved_names_of_captured_variables(coroutine_def_id); // Build variant struct types let variant_struct_type_di_nodes: SmallVec<_> = variants .indices() .map(|variant_index| { // FIXME: This is problematic because just a number is not a valid identifier. - // GeneratorArgs::variant_name(variant_index), would be consistent + // CoroutineArgs::variant_name(variant_index), would be consistent // with enums? let variant_name = format!("{}", variant_index.as_usize()).into(); - let span = generator_layout.variant_source_info[variant_index].span; + let span = coroutine_layout.variant_source_info[variant_index].span; let source_info = if !span.is_dummy() { let loc = cx.lookup_debug_loc(span.lo()); Some((file_metadata(cx, &loc.file), loc.line)) @@ -191,12 +191,12 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>( variant_index, variant_name, variant_struct_type_di_node: - super::build_generator_variant_struct_type_di_node( + super::build_coroutine_variant_struct_type_di_node( cx, variant_index, - generator_type_and_layout, - generator_type_di_node, - generator_layout, + coroutine_type_and_layout, + coroutine_type_di_node, + coroutine_layout, &common_upvar_names, ), source_info, @@ -206,18 +206,18 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>( smallvec![build_enum_variant_part_di_node( cx, - generator_type_and_layout, - generator_type_di_node, + coroutine_type_and_layout, + coroutine_type_di_node, &variant_struct_type_di_nodes[..], )] }, - // We don't seem to be emitting generic args on the generator type, it seems. Rather + // We don't seem to be emitting generic args on the coroutine type, it seems. Rather // they get attached to the struct type of each variant. NO_GENERICS, ) } -/// Builds the DW_TAG_variant_part of an enum or generator debuginfo node: +/// Builds the DW_TAG_variant_part of an enum or coroutine debuginfo node: /// /// ```txt /// DW_TAG_structure_type (top-level type for enum) @@ -306,11 +306,11 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( /// ``` fn build_discr_member_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - enum_or_generator_type_and_layout: TyAndLayout<'tcx>, - enum_or_generator_type_di_node: &'ll DIType, + enum_or_coroutine_type_and_layout: TyAndLayout<'tcx>, + enum_or_coroutine_type_di_node: &'ll DIType, ) -> Option<&'ll DIType> { - let tag_name = match enum_or_generator_type_and_layout.ty.kind() { - ty::Generator(..) => "__state", + let tag_name = match enum_or_coroutine_type_and_layout.ty.kind() { + ty::Coroutine(..) => "__state", _ => "", }; @@ -320,14 +320,14 @@ fn build_discr_member_di_node<'ll, 'tcx>( // In LLVM IR the wrong scope will be listed but when DWARF is // generated from it, the DW_TAG_member will be a child the // DW_TAG_variant_part. - let containing_scope = enum_or_generator_type_di_node; + let containing_scope = enum_or_coroutine_type_di_node; - match enum_or_generator_type_and_layout.layout.variants() { + match enum_or_coroutine_type_and_layout.layout.variants() { // A single-variant enum has no discriminant. &Variants::Single { .. } => None, &Variants::Multiple { tag_field, .. } => { - let tag_base_type = tag_base_type(cx, enum_or_generator_type_and_layout); + let tag_base_type = tag_base_type(cx, enum_or_coroutine_type_and_layout); let (size, align) = cx.size_and_align_of(tag_base_type); unsafe { @@ -340,7 +340,7 @@ fn build_discr_member_di_node<'ll, 'tcx>( UNKNOWN_LINE_NUMBER, size.bits(), align.bits() as u32, - enum_or_generator_type_and_layout.fields.offset(tag_field).bits(), + enum_or_coroutine_type_and_layout.fields.offset(tag_field).bits(), DIFlags::FlagArtificial, type_di_node(cx, tag_base_type), )) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index e30622cbdced6..1aec65cf94900 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -43,7 +43,7 @@ pub(super) enum UniqueTypeId<'tcx> { /// The ID of a regular type as it shows up at the language level. Ty(Ty<'tcx>, private::HiddenZst), /// The ID for the single DW_TAG_variant_part nested inside the top-level - /// DW_TAG_structure_type that describes enums and generators. + /// DW_TAG_structure_type that describes enums and coroutines. VariantPart(Ty<'tcx>, private::HiddenZst), /// The ID for the artificial struct type describing a single enum variant. VariantStructType(Ty<'tcx>, VariantIdx, private::HiddenZst), diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index d874b3ab99daa..c8bf7286edffe 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -342,7 +342,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { // We look up the generics of the enclosing function and truncate the args // to their length in order to cut off extra stuff that might be in there for - // closures or generators. + // closures or coroutines. let generics = tcx.generics_of(enclosing_fn_def_id); let args = instance.args.truncate_to(tcx, generics); diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index fd4c9572af2fe..712b6ed533303 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -42,7 +42,7 @@ fn uncached_llvm_type<'a, 'tcx>( // FIXME(eddyb) producing readable type names for trait objects can result // in problematically distinct types due to HRTB and subtyping (see #47638). // ty::Dynamic(..) | - ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str + ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str // For performance reasons we use names only when emitting LLVM IR. if !cx.sess().fewer_names() => { @@ -54,10 +54,10 @@ fn uncached_llvm_type<'a, 'tcx>( write!(&mut name, "::{}", def.variant(index).name).unwrap(); } } - if let (&ty::Generator(_, _, _), &Variants::Single { index }) = + if let (&ty::Coroutine(_, _, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { - write!(&mut name, "::{}", ty::GeneratorArgs::variant_name(index)).unwrap(); + write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); } Some(name) } diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 989df448a319e..e401f6bbcbfb2 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher}; use rustc_hir::def_id::DefId; use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData}; -use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Mutability}; +use rustc_hir::{AsyncCoroutineKind, CoroutineKind, Mutability}; use rustc_middle::ty::layout::{IntegerExt, TyAndLayout}; use rustc_middle::ty::{self, ExistentialProjection, ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{GenericArgKind, GenericArgsRef}; @@ -398,23 +398,23 @@ fn push_debuginfo_type_name<'tcx>( // processing visited.remove(&t); } - ty::Closure(def_id, args) | ty::Generator(def_id, args, ..) => { - // Name will be "{closure_env#0}", "{generator_env#0}", or + ty::Closure(def_id, args) | ty::Coroutine(def_id, args, ..) => { + // Name will be "{closure_env#0}", "{coroutine_env#0}", or // "{async_fn_env#0}", etc. // In the case of cpp-like debuginfo, the name additionally gets wrapped inside of // an artificial `enum2$<>` type, as defined in msvc_enum_fallback(). - if cpp_like_debuginfo && t.is_generator() { + if cpp_like_debuginfo && t.is_coroutine() { let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).unwrap(); msvc_enum_fallback( ty_and_layout, &|output, visited| { - push_closure_or_generator_name(tcx, def_id, args, true, output, visited); + push_closure_or_coroutine_name(tcx, def_id, args, true, output, visited); }, output, visited, ); } else { - push_closure_or_generator_name(tcx, def_id, args, qualified, output, visited); + push_closure_or_coroutine_name(tcx, def_id, args, qualified, output, visited); } } // Type parameters from polymorphized functions. @@ -426,7 +426,7 @@ fn push_debuginfo_type_name<'tcx>( | ty::Placeholder(..) | ty::Alias(..) | ty::Bound(..) - | ty::GeneratorWitness(..) => { + | ty::CoroutineWitness(..) => { bug!( "debuginfo: Trying to create type name for \ unexpected type: {:?}", @@ -558,12 +558,12 @@ pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: & push_unqualified_item_name(tcx, def_id, def_key.disambiguated_data, output); } -fn generator_kind_label(generator_kind: Option) -> &'static str { - match generator_kind { - Some(GeneratorKind::Async(AsyncGeneratorKind::Block)) => "async_block", - Some(GeneratorKind::Async(AsyncGeneratorKind::Closure)) => "async_closure", - Some(GeneratorKind::Async(AsyncGeneratorKind::Fn)) => "async_fn", - Some(GeneratorKind::Gen) => "generator", +fn coroutine_kind_label(coroutine_kind: Option) -> &'static str { + match coroutine_kind { + Some(CoroutineKind::Async(AsyncCoroutineKind::Block)) => "async_block", + Some(CoroutineKind::Async(AsyncCoroutineKind::Closure)) => "async_closure", + Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) => "async_fn", + Some(CoroutineKind::Coroutine) => "coroutine", None => "closure", } } @@ -592,7 +592,7 @@ fn push_unqualified_item_name( output.push_str(tcx.crate_name(def_id.krate).as_str()); } DefPathData::ClosureExpr => { - let label = generator_kind_label(tcx.generator_kind(def_id)); + let label = coroutine_kind_label(tcx.coroutine_kind(def_id)); push_disambiguated_special_name( label, @@ -707,7 +707,7 @@ pub fn push_generic_params<'tcx>( push_generic_params_internal(tcx, args, def_id, output, &mut visited); } -fn push_closure_or_generator_name<'tcx>( +fn push_closure_or_coroutine_name<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>, @@ -715,10 +715,10 @@ fn push_closure_or_generator_name<'tcx>( output: &mut String, visited: &mut FxHashSet>, ) { - // Name will be "{closure_env#0}", "{generator_env#0}", or + // Name will be "{closure_env#0}", "{coroutine_env#0}", or // "{async_fn_env#0}", etc. let def_key = tcx.def_key(def_id); - let generator_kind = tcx.generator_kind(def_id); + let coroutine_kind = tcx.coroutine_kind(def_id); if qualified { let parent_def_id = DefId { index: def_key.parent.unwrap(), ..def_id }; @@ -727,7 +727,7 @@ fn push_closure_or_generator_name<'tcx>( } let mut label = String::with_capacity(20); - write!(&mut label, "{}_env", generator_kind_label(generator_kind)).unwrap(); + write!(&mut label, "{}_env", coroutine_kind_label(coroutine_kind)).unwrap(); push_disambiguated_special_name( &label, @@ -736,7 +736,7 @@ fn push_closure_or_generator_name<'tcx>( output, ); - // We also need to add the generic arguments of the async fn/generator or + // We also need to add the generic arguments of the async fn/coroutine or // the enclosing function (for closures or async blocks), so that we end // up with a unique name for every instantiation. @@ -745,7 +745,7 @@ fn push_closure_or_generator_name<'tcx>( let generics = tcx.generics_of(enclosing_fn_def_id); // Truncate the args to the length of the above generics. This will cut off - // anything closure- or generator-specific. + // anything closure- or coroutine-specific. let args = args.truncate_to(tcx, generics); push_generic_params_internal(tcx, args, enclosing_fn_def_id, output, visited); } diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 62e997e5cfa48..53cc063e55a54 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -272,7 +272,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec> FunctionCx<'a, 'tcx, Bx> { fn_span, mergeable_succ(), ), - mir::TerminatorKind::GeneratorDrop | mir::TerminatorKind::Yield { .. } => { - bug!("generator ops in codegen") + mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => { + bug!("coroutine ops in codegen") } mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => { bug!("borrowck false edges in codegen") diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 166d3d45e7930..0d0ebe6f390b0 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -534,8 +534,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, OverflowNeg(op) => OverflowNeg(eval_to_int(op)?), DivisionByZero(op) => DivisionByZero(eval_to_int(op)?), RemainderByZero(op) => RemainderByZero(eval_to_int(op)?), - ResumedAfterReturn(generator_kind) => ResumedAfterReturn(*generator_kind), - ResumedAfterPanic(generator_kind) => ResumedAfterPanic(*generator_kind), + ResumedAfterReturn(coroutine_kind) => ResumedAfterReturn(*coroutine_kind), + ResumedAfterPanic(coroutine_kind) => ResumedAfterPanic(*coroutine_kind), MisalignedPointerDereference { ref required, ref found } => { MisalignedPointerDereference { required: eval_to_int(required)?, diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 7436ea6ae5756..d6dc1a62f4d0d 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -151,8 +151,8 @@ pub(crate) fn const_to_valtree_inner<'tcx>( | ty::Infer(_) // FIXME(oli-obk): we can probably encode closures just like structs | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) => Err(ValTreeCreationError::NonSupportedType), + | ty::Coroutine(..) + | ty::CoroutineWitness(..) => Err(ValTreeCreationError::NonSupportedType), } } @@ -278,8 +278,8 @@ pub fn valtree_to_const_value<'tcx>( | ty::Placeholder(..) | ty::Infer(_) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::FnPtr(_) | ty::RawPtr(_) | ty::Str diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index b9557eaf6abbf..8fc0205d6c772 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, FloatTy, Ty, TypeAndMut}; use rustc_target::abi::Integer; -use rustc_type_ir::sty::TyKind::*; +use rustc_type_ir::TyKind::*; use super::{ util::ensure_monomorphic_enough, FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, PlaceTy, @@ -185,7 +185,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { src: &ImmTy<'tcx, M::Provenance>, cast_to: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> { - use rustc_type_ir::sty::TyKind::*; + use rustc_type_ir::TyKind::*; let val = match src.layout.ty.kind() { // Floating point @@ -310,7 +310,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { where F: Float + Into> + FloatConvert + FloatConvert, { - use rustc_type_ir::sty::TyKind::*; + use rustc_type_ir::TyKind::*; fn adjust_nan< 'mir, diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 49e01728ff4b0..8dab45d65ee11 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -1,4 +1,4 @@ -//! Functions for reading and writing discriminants of multi-variant layouts (enums and generators). +//! Functions for reading and writing discriminants of multi-variant layouts (enums and coroutines). use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout}; use rustc_middle::{mir, ty}; @@ -170,11 +170,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ty::Adt(adt, _) => { adt.discriminants(*self.tcx).find(|(_, var)| var.val == discr_bits) } - ty::Generator(def_id, args, _) => { - let args = args.as_generator(); + ty::Coroutine(def_id, args, _) => { + let args = args.as_coroutine(); args.discriminants(def_id, *self.tcx).find(|(_, var)| var.val == discr_bits) } - _ => span_bug!(self.cur_span(), "tagged layout for non-adt non-generator"), + _ => span_bug!(self.cur_span(), "tagged layout for non-adt non-coroutine"), } .ok_or_else(|| err_ub!(InvalidTag(Scalar::from_uint(tag_bits, tag_layout.size))))?; // Return the cast value, and the index. diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 1c2e8d807f4e6..791370660fe94 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -963,8 +963,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | ty::RawPtr(..) | ty::Char | ty::Ref(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Array(..) | ty::Closure(..) | ty::Never diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index b7106c37c7b78..c97207a61ac3b 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -99,8 +99,8 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( | ty::FnPtr(_) | ty::Dynamic(_, _, _) | ty::Closure(_, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx), diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index 59e898198806c..b54c668145638 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -218,7 +218,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Unreachable => throw_ub!(Unreachable), // These should never occur for MIR we actually run. - FalseEdge { .. } | FalseUnwind { .. } | Yield { .. } | GeneratorDrop => span_bug!( + FalseEdge { .. } | FalseUnwind { .. } | Yield { .. } | CoroutineDrop => span_bug!( terminator.source_info.span, "{:#?} should have been eliminated by MIR pass", terminator.kind diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index eb639ded70ffd..416443f5f4d22 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -34,7 +34,7 @@ where match *ty.kind() { ty::Param(_) => ControlFlow::Break(FoundParam), ty::Closure(def_id, args) - | ty::Generator(def_id, args, ..) + | ty::Coroutine(def_id, args, ..) | ty::FnDef(def_id, args) => { let instance = ty::InstanceDef::Item(def_id); let unused_params = self.tcx.unused_generic_params(instance); @@ -42,10 +42,10 @@ where let index = index .try_into() .expect("more generic parameters than can fit into a `u32`"); - // Only recurse when generic parameters in fns, closures and generators + // Only recurse when generic parameters in fns, closures and coroutines // are used and have to be instantiated. // - // Just in case there are closures or generators within this subst, + // Just in case there are closures or coroutines within this subst, // recurse. if unused_params.is_used(index) && subst.has_param() { return subst.visit_with(self); diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 082e5466fe2e7..56b7b6bf82692 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -112,13 +112,13 @@ macro_rules! try_validation { pub enum PathElem { Field(Symbol), Variant(Symbol), - GeneratorState(VariantIdx), + CoroutineState(VariantIdx), CapturedVar(Symbol), ArrayElem(usize), TupleElem(usize), Deref, EnumTag, - GeneratorTag, + CoroutineTag, DynDowncast, } @@ -171,8 +171,8 @@ fn write_path(out: &mut String, path: &[PathElem]) { Field(name) => write!(out, ".{name}"), EnumTag => write!(out, "."), Variant(name) => write!(out, "."), - GeneratorTag => write!(out, "."), - GeneratorState(idx) => write!(out, ".", idx.index()), + CoroutineTag => write!(out, "."), + CoroutineState(idx) => write!(out, ".", idx.index()), CapturedVar(name) => write!(out, "."), TupleElem(idx) => write!(out, ".{idx}"), ArrayElem(idx) => write!(out, "[{idx}]"), @@ -206,7 +206,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' if tag_field == field { return match layout.ty.kind() { ty::Adt(def, ..) if def.is_enum() => PathElem::EnumTag, - ty::Generator(..) => PathElem::GeneratorTag, + ty::Coroutine(..) => PathElem::CoroutineTag, _ => bug!("non-variant type {:?}", layout.ty), }; } @@ -216,8 +216,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' // Now we know we are projecting to a field, so figure out which one. match layout.ty.kind() { - // generators and closures. - ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => { + // coroutines and closures. + ty::Closure(def_id, _) | ty::Coroutine(def_id, _, _) => { let mut name = None; // FIXME this should be more descriptive i.e. CapturePlace instead of CapturedVar // https://github.com/rust-lang/project-rfc-2229/issues/46 @@ -225,7 +225,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' let captures = self.ecx.tcx.closure_captures(local_def_id); if let Some(captured_place) = captures.get(field) { // Sometimes the index is beyond the number of upvars (seen - // for a generator). + // for a coroutine). let var_hir_id = captured_place.get_root_variable(); let node = self.ecx.tcx.hir().get(var_hir_id); if let hir::Node::Pat(pat) = node { @@ -580,7 +580,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | ty::Str | ty::Dynamic(..) | ty::Closure(..) - | ty::Generator(..) => Ok(false), + | ty::Coroutine(..) => Ok(false), // Some types only occur during typechecking, they have no layout. // We should not see them here and we could not check them anyway. ty::Error(_) @@ -589,7 +589,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | ty::Bound(..) | ty::Param(..) | ty::Alias(..) - | ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty), + | ty::CoroutineWitness(..) => bug!("Encountered invalid type {:?}", ty), } } @@ -692,8 +692,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> ) -> InterpResult<'tcx> { let name = match old_op.layout.ty.kind() { ty::Adt(adt, _) => PathElem::Variant(adt.variant(variant_id).name), - // Generators also have variants - ty::Generator(..) => PathElem::GeneratorState(variant_id), + // Coroutines also have variants + ty::Coroutine(..) => PathElem::CoroutineState(variant_id), _ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty), }; self.with_elem(name, move |this| this.visit_value(new_op)) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 92e7922ad3b0c..135c99fefbc85 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -247,7 +247,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { // `async` functions cannot be `const fn`. This is checked during AST lowering, so there's // no need to emit duplicate errors here. - if self.ccx.is_async() || body.generator.is_some() { + if self.ccx.is_async() || body.coroutine.is_some() { tcx.sess.delay_span_bug(body.span, "`async` functions cannot be `const fn`"); return; } @@ -463,11 +463,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { | Rvalue::Len(_) => {} Rvalue::Aggregate(kind, ..) => { - if let AggregateKind::Generator(def_id, ..) = kind.as_ref() - && let Some(generator_kind @ hir::GeneratorKind::Async(..)) = - self.tcx.generator_kind(def_id) + if let AggregateKind::Coroutine(def_id, ..) = kind.as_ref() + && let Some(coroutine_kind @ hir::CoroutineKind::Async(..)) = + self.tcx.coroutine_kind(def_id) { - self.check_op(ops::Generator(generator_kind)); + self.check_op(ops::Coroutine(coroutine_kind)); } } @@ -1042,8 +1042,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { TerminatorKind::InlineAsm { .. } => self.check_op(ops::InlineAsm), - TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { - self.check_op(ops::Generator(hir::GeneratorKind::Gen)) + TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => { + self.check_op(ops::Coroutine(hir::CoroutineKind::Coroutine)) } TerminatorKind::UnwindTerminate(_) => { diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index e8d1d5958200e..616fab8fe7d65 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -357,10 +357,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable { } #[derive(Debug)] -pub struct Generator(pub hir::GeneratorKind); -impl<'tcx> NonConstOp<'tcx> for Generator { +pub struct Coroutine(pub hir::CoroutineKind); +impl<'tcx> NonConstOp<'tcx> for Coroutine { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { - if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 { + if let hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) = self.0 { Status::Unstable(sym::const_async_blocks) } else { Status::Forbidden @@ -373,7 +373,7 @@ impl<'tcx> NonConstOp<'tcx> for Generator { span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind()); - if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 { + if let hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) = self.0 { ccx.tcx.sess.create_feature_err( errors::UnallowedOpInConstContext { span, msg }, sym::const_async_blocks, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs index fd6bc2ee9af59..aff256b3eadd6 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs @@ -111,7 +111,7 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> { | mir::TerminatorKind::Assert { .. } | mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } - | mir::TerminatorKind::GeneratorDrop + | mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Goto { .. } | mir::TerminatorKind::InlineAsm { .. } | mir::TerminatorKind::UnwindResume diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index 8ede3bdd2b60a..0590297663873 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -970,7 +970,7 @@ pub fn promote_candidates<'tcx>( 0, vec![], body.span, - body.generator_kind(), + body.coroutine_kind(), body.tainted_by_errors, ); promoted.phase = MirPhase::Analysis(AnalysisPhase::Initial); diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 4711f7b47cccc..b70a342aa15e6 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -67,7 +67,7 @@ impl<'tcx> MirPass<'tcx> for Validator { let body_abi = match body_ty.kind() { ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), ty::Closure(..) => Abi::RustCall, - ty::Generator(..) => Abi::Rust, + ty::Coroutine(..) => Abi::Rust, _ => { span_bug!(body.span, "unexpected body ty: {:?} phase {:?}", body_ty, mir_phase) } @@ -472,11 +472,11 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { self.check_unwind_edge(location, *unwind); } TerminatorKind::Yield { resume, drop, .. } => { - if self.body.generator.is_none() { - self.fail(location, "`Yield` cannot appear outside generator bodies"); + if self.body.coroutine.is_none() { + self.fail(location, "`Yield` cannot appear outside coroutine bodies"); } if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) { - self.fail(location, "`Yield` should have been replaced by generator lowering"); + self.fail(location, "`Yield` should have been replaced by coroutine lowering"); } self.check_edge(location, *resume, EdgeKind::Normal); if let Some(drop) = drop { @@ -509,14 +509,14 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { } self.check_unwind_edge(location, *unwind); } - TerminatorKind::GeneratorDrop => { - if self.body.generator.is_none() { - self.fail(location, "`GeneratorDrop` cannot appear outside generator bodies"); + TerminatorKind::CoroutineDrop => { + if self.body.coroutine.is_none() { + self.fail(location, "`CoroutineDrop` cannot appear outside coroutine bodies"); } if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) { self.fail( location, - "`GeneratorDrop` should have been replaced by generator lowering", + "`CoroutineDrop` should have been replaced by coroutine lowering", ); } } @@ -716,7 +716,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; check_equal(self, location, f_ty); } - &ty::Generator(def_id, args, _) => { + &ty::Coroutine(def_id, args, _) => { let f_ty = if let Some(var) = parent_ty.variant_index { let gen_body = if def_id == self.body.source.def_id() { self.body @@ -724,10 +724,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.tcx.optimized_mir(def_id) }; - let Some(layout) = gen_body.generator_layout() else { + let Some(layout) = gen_body.coroutine_layout() else { self.fail( location, - format!("No generator layout for {parent_ty:?}"), + format!("No coroutine layout for {parent_ty:?}"), ); return; }; @@ -747,7 +747,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ty::EarlyBinder::bind(f_ty.ty).instantiate(self.tcx, args) } else { - let Some(&f_ty) = args.as_generator().prefix_tys().get(f.index()) + let Some(&f_ty) = args.as_coroutine().prefix_tys().get(f.index()) else { fail_out_of_bounds(self, location); return; @@ -1211,11 +1211,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.fail(location, "`SetDiscriminant`is not allowed until deaggregation"); } let pty = place.ty(&self.body.local_decls, self.tcx).ty.kind(); - if !matches!(pty, ty::Adt(..) | ty::Generator(..) | ty::Alias(ty::Opaque, ..)) { + if !matches!(pty, ty::Adt(..) | ty::Coroutine(..) | ty::Alias(ty::Opaque, ..)) { self.fail( location, format!( - "`SetDiscriminant` is only allowed on ADTs and generators, not {pty:?}" + "`SetDiscriminant` is only allowed on ADTs and coroutines, not {pty:?}" ), ); } @@ -1295,7 +1295,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } | TerminatorKind::InlineAsm { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::UnwindResume | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 54eb14ae8fc47..8c7c360acbfdf 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -51,12 +51,12 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { | ty::FnDef(def_id, args) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Closure(def_id, args) - | ty::Generator(def_id, args, _) => self.print_def_path(def_id, args), + | ty::Coroutine(def_id, args, _) => self.print_def_path(def_id, args), ty::Foreign(def_id) => self.print_def_path(def_id, &[]), ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"), ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"), - ty::GeneratorWitness(..) => bug!("type_name: unexpected `GeneratorWitness`"), + ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"), } } diff --git a/compiler/rustc_error_codes/src/error_codes/E0626.md b/compiler/rustc_error_codes/src/error_codes/E0626.md index cc6e03d1ca70f..e2534415d8307 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0626.md +++ b/compiler/rustc_error_codes/src/error_codes/E0626.md @@ -1,11 +1,11 @@ -This error occurs because a borrow in a generator persists across a +This error occurs because a borrow in a coroutine persists across a yield point. Erroneous code example: ```compile_fail,E0626 -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let a = &String::new(); // <-- This borrow... @@ -23,8 +23,8 @@ resolve the previous example by removing the borrow and just storing the integer by value: ``` -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let a = 3; @@ -41,8 +41,8 @@ in those cases, something like the `Rc` or `Arc` types may be useful. This error also frequently arises with iteration: ```compile_fail,E0626 -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let v = vec![1,2,3]; @@ -57,8 +57,8 @@ Such cases can sometimes be resolved by iterating "by value" (or using `into_iter()`) to avoid borrowing: ``` -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let v = vec![1,2,3]; @@ -72,8 +72,8 @@ Pin::new(&mut b).resume(()); If taking ownership is not an option, using indices can work too: ``` -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let v = vec![1,2,3]; diff --git a/compiler/rustc_error_codes/src/error_codes/E0627.md b/compiler/rustc_error_codes/src/error_codes/E0627.md index 21358e1e567dc..5d366f78fc575 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0627.md +++ b/compiler/rustc_error_codes/src/error_codes/E0627.md @@ -1,28 +1,28 @@ -A yield expression was used outside of the generator literal. +A yield expression was used outside of the coroutine literal. Erroneous code example: ```compile_fail,E0627 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -fn fake_generator() -> &'static str { +fn fake_coroutine() -> &'static str { yield 1; return "foo" } fn main() { - let mut generator = fake_generator; + let mut coroutine = fake_coroutine; } ``` -The error occurs because keyword `yield` can only be used inside the generator -literal. This can be fixed by constructing the generator correctly. +The error occurs because keyword `yield` can only be used inside the coroutine +literal. This can be fixed by constructing the coroutine correctly. ``` -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { - let mut generator = || { + let mut coroutine = || { yield 1; return "foo" }; diff --git a/compiler/rustc_error_codes/src/error_codes/E0628.md b/compiler/rustc_error_codes/src/error_codes/E0628.md index 40040c9a56aac..ce19bcd56cc78 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0628.md +++ b/compiler/rustc_error_codes/src/error_codes/E0628.md @@ -1,13 +1,13 @@ -More than one parameter was used for a generator. +More than one parameter was used for a coroutine. Erroneous code example: ```compile_fail,E0628 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { - let generator = |a: i32, b: i32| { - // error: too many parameters for a generator + let coroutine = |a: i32, b: i32| { + // error: too many parameters for a coroutine // Allowed only 0 or 1 parameter yield a; }; @@ -15,15 +15,15 @@ fn main() { ``` At present, it is not permitted to pass more than one explicit -parameter for a generator.This can be fixed by using -at most 1 parameter for the generator. For example, we might resolve +parameter for a coroutine.This can be fixed by using +at most 1 parameter for the coroutine. For example, we might resolve the previous example by passing only one parameter. ``` -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { - let generator = |a: i32| { + let coroutine = |a: i32| { yield a; }; } diff --git a/compiler/rustc_error_codes/src/error_codes/E0698.md b/compiler/rustc_error_codes/src/error_codes/E0698.md index 9bc652e642f6c..d064971293669 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0698.md +++ b/compiler/rustc_error_codes/src/error_codes/E0698.md @@ -1,7 +1,7 @@ #### Note: this error code is no longer emitted by the compiler. -When using generators (or async) all type variables must be bound so a -generator can be constructed. +When using coroutines (or async) all type variables must be bound so a +coroutine can be constructed. Erroneous code example: @@ -15,7 +15,7 @@ async fn foo() { In the above example `T` is unknowable by the compiler. To fix this you must bind `T` to a concrete type such as `String` -so that a generator can then be constructed: +so that a coroutine can then be constructed: ```edition2018 async fn bar() -> () {} diff --git a/compiler/rustc_error_codes/src/error_codes/E0727.md b/compiler/rustc_error_codes/src/error_codes/E0727.md index 386daea0c57e3..fde35885c9208 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0727.md +++ b/compiler/rustc_error_codes/src/error_codes/E0727.md @@ -3,10 +3,10 @@ A `yield` clause was used in an `async` context. Erroneous code example: ```compile_fail,E0727,edition2018 -#![feature(generators)] +#![feature(coroutines)] fn main() { - let generator = || { + let coroutine = || { async { yield; } @@ -20,10 +20,10 @@ which is not yet supported. To fix this error, you have to move `yield` out of the `async` block: ```edition2018 -#![feature(generators)] +#![feature(coroutines)] fn main() { - let generator = || { + let coroutine = || { yield; }; } diff --git a/compiler/rustc_error_codes/src/error_codes/E0790.md b/compiler/rustc_error_codes/src/error_codes/E0790.md index 2aee9dfbdbd94..b52543c48d83f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0790.md +++ b/compiler/rustc_error_codes/src/error_codes/E0790.md @@ -4,24 +4,24 @@ method. Erroneous code example: ```compile_fail,E0790 -trait Generator { +trait Coroutine { fn create() -> u32; } struct Impl; -impl Generator for Impl { +impl Coroutine for Impl { fn create() -> u32 { 1 } } struct AnotherImpl; -impl Generator for AnotherImpl { +impl Coroutine for AnotherImpl { fn create() -> u32 { 2 } } -let cont: u32 = Generator::create(); -// error, impossible to choose one of Generator trait implementation +let cont: u32 = Coroutine::create(); +// error, impossible to choose one of Coroutine trait implementation // Should it be Impl or AnotherImpl, maybe something else? ``` @@ -30,18 +30,18 @@ information to the compiler. In this case, the solution is to use a concrete type: ``` -trait Generator { +trait Coroutine { fn create() -> u32; } struct AnotherImpl; -impl Generator for AnotherImpl { +impl Coroutine for AnotherImpl { fn create() -> u32 { 2 } } let gen1 = AnotherImpl::create(); // if there are multiple methods with same name (different traits) -let gen2 = ::create(); +let gen2 = ::create(); ``` diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index d3ce3617dd658..6d95fbcfad00d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1348,7 +1348,14 @@ impl EmitterWriter { buffer.append(0, "]", Style::Level(*level)); label_width += 2 + code.len(); } - let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg }; + let header_style = if is_secondary { + Style::HeaderMsg + } else if self.short_message { + // For short messages avoid bolding the message, as it doesn't look great (#63835). + Style::NoStyle + } else { + Style::MainHeaderMsg + }; if *level != Level::FailureNote { buffer.append(0, ": ", header_style); label_width += 2; diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 339f596144c94..ac133f8b039d6 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -42,7 +42,7 @@ declare_features! ( Some("subsumed by `.await` syntax")), /// Allows using the `box $expr` syntax. (removed, box_syntax, "1.70.0", Some(49733), None, Some("replaced with `#[rustc_box]`")), - /// Allows capturing disjoint fields in a closure/generator (RFC 2229). + /// Allows capturing disjoint fields in a closure/coroutine (RFC 2229). (removed, capture_disjoint_fields, "1.49.0", Some(53488), None, Some("stabilized in Rust 2021")), /// Allows comparing raw pointers during const eval. (removed, const_compare_raw_pointers, "1.46.0", Some(53020), None, @@ -96,6 +96,10 @@ declare_features! ( /// Allows `#[doc(include = "some-file")]`. (removed, external_doc, "1.54.0", Some(44732), None, Some("use #[doc = include_str!(\"filename\")] instead, which handles macro invocations")), + /// Allows generators to be cloned. + (removed, generator_clone, "1.65.0", Some(95360), None, Some("renamed to `coroutine_clone`")), + /// Allows defining generators. + (removed, generators, "1.21.0", Some(43122), None, Some("renamed to `coroutine`")), /// Allows `impl Trait` in bindings (`let`, `const`, `static`). (removed, impl_trait_in_bindings, "1.55.0", Some(63065), None, Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 27cdf1ba8316e..8185a8a3e437d 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -371,9 +371,9 @@ declare_features! ( (unstable, cfg_version, "1.45.0", Some(64796), None), /// Allows to use the `#[cfi_encoding = ""]` attribute. (unstable, cfi_encoding, "1.71.0", Some(89653), None), - /// Allows `for<...>` on closures and generators. + /// Allows `for<...>` on closures and coroutines. (unstable, closure_lifetime_binder, "1.64.0", Some(97362), None), - /// Allows `#[track_caller]` on closures and generators. + /// Allows `#[track_caller]` on closures and coroutines. (unstable, closure_track_caller, "1.57.0", Some(87417), None), /// Allows to use the `#[cmse_nonsecure_entry]` attribute. (unstable, cmse_nonsecure_entry, "1.48.0", Some(75835), None), @@ -399,6 +399,10 @@ declare_features! ( (unstable, const_trait_impl, "1.42.0", Some(67792), None), /// Allows the `?` operator in const contexts. (unstable, const_try, "1.56.0", Some(74935), None), + /// Allows coroutines to be cloned. + (unstable, coroutine_clone, "1.65.0", Some(95360), None), + /// Allows defining coroutines. + (unstable, coroutines, "1.21.0", Some(43122), None), /// Allows function attribute `#[coverage(on/off)]`, to control coverage /// instrumentation of that function. (unstable, coverage_attribute, "1.74.0", Some(84605), None), @@ -451,10 +455,6 @@ declare_features! ( (unstable, ffi_returns_twice, "1.34.0", Some(58314), None), /// Allows using `#[repr(align(...))]` on function items (unstable, fn_align, "1.53.0", Some(82232), None), - /// Allows generators to be cloned. - (unstable, generator_clone, "1.65.0", Some(95360), None), - /// Allows defining generators. - (unstable, generators, "1.21.0", Some(43122), None), /// Infer generic args for both consts and types. (unstable, generic_arg_infer, "1.55.0", Some(85077), None), /// An extension to the `generic_associated_types` feature, allowing incomplete features. diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 3a4eb90f7f963..ed1dc751fbab7 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -118,7 +118,7 @@ pub enum DefKind { of_trait: bool, }, Closure, - Generator, + Coroutine, } impl DefKind { @@ -126,7 +126,7 @@ impl DefKind { /// /// If you have access to `TyCtxt`, use `TyCtxt::def_descr` or /// `TyCtxt::def_kind_descr` instead, because they give better - /// information for generators and associated functions. + /// information for coroutines and associated functions. pub fn descr(self, def_id: DefId) -> &'static str { match self { DefKind::Fn => "function", @@ -161,7 +161,7 @@ impl DefKind { DefKind::Field => "field", DefKind::Impl { .. } => "implementation", DefKind::Closure => "closure", - DefKind::Generator => "generator", + DefKind::Coroutine => "coroutine", DefKind::ExternCrate => "extern crate", DefKind::GlobalAsm => "global assembly block", } @@ -171,7 +171,7 @@ impl DefKind { /// /// If you have access to `TyCtxt`, use `TyCtxt::def_descr_article` or /// `TyCtxt::def_kind_descr_article` instead, because they give better - /// information for generators and associated functions. + /// information for coroutines and associated functions. pub fn article(&self) -> &'static str { match *self { DefKind::AssocTy @@ -220,7 +220,7 @@ impl DefKind { | DefKind::LifetimeParam | DefKind::ExternCrate | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::Use | DefKind::ForeignMod | DefKind::GlobalAsm @@ -230,7 +230,7 @@ impl DefKind { #[inline] pub fn is_fn_like(self) -> bool { - matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator) + matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine) } /// Whether `query get_codegen_attrs` should be used with this definition. @@ -240,7 +240,7 @@ impl DefKind { | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::Static(_) => true, DefKind::Mod | DefKind::Struct diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 3eec66611edd1..f8d55192a3747 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1485,7 +1485,7 @@ pub struct BodyId { /// /// - an `params` array containing the `(x, y)` pattern /// - a `value` containing the `x + y` expression (maybe wrapped in a block) -/// - `generator_kind` would be `None` +/// - `coroutine_kind` would be `None` /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. @@ -1493,7 +1493,7 @@ pub struct BodyId { pub struct Body<'hir> { pub params: &'hir [Param<'hir>], pub value: &'hir Expr<'hir>, - pub generator_kind: Option, + pub coroutine_kind: Option, } impl<'hir> Body<'hir> { @@ -1501,48 +1501,48 @@ impl<'hir> Body<'hir> { BodyId { hir_id: self.value.hir_id } } - pub fn generator_kind(&self) -> Option { - self.generator_kind + pub fn coroutine_kind(&self) -> Option { + self.coroutine_kind } } -/// The type of source expression that caused this generator to be created. +/// The type of source expression that caused this coroutine to be created. #[derive(Clone, PartialEq, Eq, Debug, Copy, Hash)] #[derive(HashStable_Generic, Encodable, Decodable)] -pub enum GeneratorKind { +pub enum CoroutineKind { /// An explicit `async` block or the body of an async function. - Async(AsyncGeneratorKind), + Async(AsyncCoroutineKind), - /// A generator literal created via a `yield` inside a closure. - Gen, + /// A coroutine literal created via a `yield` inside a closure. + Coroutine, } -impl fmt::Display for GeneratorKind { +impl fmt::Display for CoroutineKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - GeneratorKind::Async(k) => fmt::Display::fmt(k, f), - GeneratorKind::Gen => f.write_str("generator"), + CoroutineKind::Async(k) => fmt::Display::fmt(k, f), + CoroutineKind::Coroutine => f.write_str("coroutine"), } } } -impl GeneratorKind { +impl CoroutineKind { pub fn descr(&self) -> &'static str { match self { - GeneratorKind::Async(ask) => ask.descr(), - GeneratorKind::Gen => "generator", + CoroutineKind::Async(ask) => ask.descr(), + CoroutineKind::Coroutine => "coroutine", } } } -/// In the case of a generator created as part of an async construct, +/// In the case of a coroutine created as part of an async construct, /// which kind of async construct caused it to be created? /// /// This helps error messages but is also used to drive coercions in /// type-checking (see #60424). #[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)] #[derive(HashStable_Generic, Encodable, Decodable)] -pub enum AsyncGeneratorKind { +pub enum AsyncCoroutineKind { /// An explicit `async` block written by the user. Block, @@ -1553,22 +1553,22 @@ pub enum AsyncGeneratorKind { Fn, } -impl fmt::Display for AsyncGeneratorKind { +impl fmt::Display for AsyncCoroutineKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(match self { - AsyncGeneratorKind::Block => "async block", - AsyncGeneratorKind::Closure => "async closure body", - AsyncGeneratorKind::Fn => "async fn body", + AsyncCoroutineKind::Block => "async block", + AsyncCoroutineKind::Closure => "async closure body", + AsyncCoroutineKind::Fn => "async fn body", }) } } -impl AsyncGeneratorKind { +impl AsyncCoroutineKind { pub fn descr(&self) -> &'static str { match self { - AsyncGeneratorKind::Block => "`async` block", - AsyncGeneratorKind::Closure => "`async` closure body", - AsyncGeneratorKind::Fn => "`async fn` body", + AsyncCoroutineKind::Block => "`async` block", + AsyncCoroutineKind::Closure => "`async` closure body", + AsyncCoroutineKind::Fn => "`async fn` body", } } } @@ -2004,7 +2004,7 @@ pub enum ExprKind<'hir> { /// /// The `Span` is the argument block `|...|`. /// - /// This may also be a generator literal or an `async block` as indicated by the + /// This may also be a coroutine literal or an `async block` as indicated by the /// `Option`. Closure(&'hir Closure<'hir>), /// A block (e.g., `'label: { ... }`). @@ -2055,7 +2055,7 @@ pub enum ExprKind<'hir> { /// to be repeated; the second is the number of times to repeat it. Repeat(&'hir Expr<'hir>, ArrayLen), - /// A suspension point for generators (i.e., `yield `). + /// A suspension point for coroutines (i.e., `yield `). Yield(&'hir Expr<'hir>, YieldSource), /// A placeholder for an expression that wasn't syntactically well formed in some way. @@ -2247,12 +2247,12 @@ impl fmt::Display for YieldSource { } } -impl From for YieldSource { - fn from(kind: GeneratorKind) -> Self { +impl From for YieldSource { + fn from(kind: CoroutineKind) -> Self { match kind { - // Guess based on the kind of the current generator. - GeneratorKind::Gen => Self::Yield, - GeneratorKind::Async(_) => Self::Await { expr: None }, + // Guess based on the kind of the current coroutine. + CoroutineKind::Coroutine => Self::Yield, + CoroutineKind::Async(_) => Self::Await { expr: None }, } } } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index d9195a374c24a..8a67285598998 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -62,7 +62,7 @@ //! respectively. (This follows from RPO respecting CFG domination). //! //! This order consistency is required in a few places in rustc, for -//! example generator inference, and possibly also HIR borrowck. +//! example coroutine inference, and possibly also HIR borrowck. use crate::hir::*; use rustc_ast::walk_list; diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 4a89a6f7e3926..cdfc67d5740f6 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -211,8 +211,8 @@ language_item_table! { FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None; Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0); - GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None; - Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1); + CoroutineState, sym::coroutine_state, gen_state, Target::Enum, GenericRequirement::None; + Coroutine, sym::coroutine, gen_trait, Target::Trait, GenericRequirement::Minimum(1); Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None; Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None; diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 1745488dfd39a..360d31b863c1d 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -291,7 +291,7 @@ fn check_opaque_meets_bounds<'tcx>( let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args); - // `ReErased` regions appear in the "parent_args" of closures/generators. + // `ReErased` regions appear in the "parent_args" of closures/coroutines. // We're ignoring them here and replacing them with fresh region variables. // See tests in ui/type-alias-impl-trait/closure_{parent_args,wf_outlives}.rs. // @@ -1394,7 +1394,7 @@ fn opaque_type_cycle_error( self.opaques.push(def); ControlFlow::Continue(()) } - ty::Closure(def_id, ..) | ty::Generator(def_id, ..) => { + ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => { self.closures.push(def_id); t.super_visit_with(self) } @@ -1446,11 +1446,11 @@ fn opaque_type_cycle_error( { label_match(capture.place.ty(), capture.get_path_span(tcx)); } - // Label any generator locals that capture the opaque - if let DefKind::Generator = tcx.def_kind(closure_def_id) - && let Some(generator_layout) = tcx.mir_generator_witnesses(closure_def_id) + // Label any coroutine locals that capture the opaque + if let DefKind::Coroutine = tcx.def_kind(closure_def_id) + && let Some(coroutine_layout) = tcx.mir_coroutine_witnesses(closure_def_id) { - for interior_ty in &generator_layout.field_tys { + for interior_ty in &coroutine_layout.field_tys { label_match(interior_ty.ty, interior_ty.source_info.span); } } @@ -1464,14 +1464,14 @@ fn opaque_type_cycle_error( err.emit() } -pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) { - debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Generator)); +pub(super) fn check_coroutine_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) { + debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Coroutine)); let typeck = tcx.typeck(def_id); let param_env = tcx.param_env(def_id); - let generator_interior_predicates = &typeck.generator_interior_predicates[&def_id]; - debug!(?generator_interior_predicates); + let coroutine_interior_predicates = &typeck.coroutine_interior_predicates[&def_id]; + debug!(?coroutine_interior_predicates); let infcx = tcx .infer_ctxt() @@ -1483,15 +1483,15 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) { .build(); let mut fulfillment_cx = >::new(&infcx); - for (predicate, cause) in generator_interior_predicates { + for (predicate, cause) in coroutine_interior_predicates { let obligation = Obligation::new(tcx, cause.clone(), param_env, *predicate); fulfillment_cx.register_predicate_obligation(&infcx, obligation); } if (tcx.features().unsized_locals || tcx.features().unsized_fn_params) - && let Some(generator) = tcx.mir_generator_witnesses(def_id) + && let Some(coroutine) = tcx.mir_coroutine_witnesses(def_id) { - for field_ty in generator.field_tys.iter() { + for field_ty in coroutine.field_tys.iter() { fulfillment_cx.register_bound( &infcx, param_env, @@ -1500,7 +1500,7 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) { ObligationCause::new( field_ty.source_info.span, def_id, - ObligationCauseCode::SizedGeneratorInterior(def_id), + ObligationCauseCode::SizedCoroutineInterior(def_id), ), ); } diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 5d67a36288c63..8da953e6e2e84 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -114,7 +114,7 @@ pub fn provide(providers: &mut Providers) { region_scope_tree, collect_return_position_impl_trait_in_trait_tys, compare_impl_const: compare_impl_item::compare_impl_const_raw, - check_generator_obligations: check::check_generator_obligations, + check_coroutine_obligations: check::check_coroutine_obligations, ..*providers }; } diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 463fab93e3fde..40b33117f7ccc 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -598,7 +598,7 @@ fn resolve_local<'tcx>( } // Make sure we visit the initializer first, so expr_and_pat_count remains correct. - // The correct order, as shared between generator_interior, drop_ranges and intravisitor, + // The correct order, as shared between coroutine_interior, drop_ranges and intravisitor, // is to walk initializer, followed by pattern bindings, finally followed by the `else` block. if let Some(expr) = init { visitor.visit_expr(expr); @@ -825,7 +825,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { resolve_local(self, None, Some(&body.value)); } - if body.generator_kind.is_some() { + if body.coroutine_kind.is_some() { self.scope_tree.body_expr_count.insert(body_id, self.expr_and_pat_count); } diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 8fafbc4167f41..e5e192e0079bd 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -162,7 +162,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef // trait, they *do* satisfy the repr(transparent) rules, and then we assume that everything else // in the compiler (in particular, all the call ABI logic) will treat them as repr(transparent) // even if they do not carry that attribute. - use rustc_type_ir::sty::TyKind::*; + use rustc_type_ir::TyKind::*; match (source.kind(), target.kind()) { (&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, r_a, *r_b).is_ok() diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index 0042d683b1913..1b4df31b50c70 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -155,8 +155,8 @@ impl<'tcx> InherentCollect<'tcx> { } ty::FnDef(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) => { diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 69020b1f11dc6..faddb0c38298c 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -243,8 +243,8 @@ fn do_orphan_check_impl<'tcx>( | ty::Tuple(..) => (LocalImpl::Allow, NonlocalImpl::DisallowOther), ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => { diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 8e124d8eb1a7b..640138a3e5eff 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -76,7 +76,7 @@ pub fn provide(providers: &mut Providers) { fn_sig, impl_trait_ref, impl_polarity, - generator_kind, + coroutine_kind, collect_mod_item_types, is_type_alias_impl_trait, ..*providers @@ -1548,12 +1548,12 @@ fn compute_sig_of_foreign_fn_decl<'tcx>( fty } -fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { +fn coroutine_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { match tcx.hir().get_by_def_id(def_id) { Node::Expr(&rustc_hir::Expr { kind: rustc_hir::ExprKind::Closure(&rustc_hir::Closure { body, .. }), .. - }) => tcx.hir().body(body).generator_kind(), + }) => tcx.hir().body(body).coroutine_kind(), _ => None, } } diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 61d9c989e2fd9..5f8b1ace68b77 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -235,7 +235,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // leaf type -- noop } - ty::FnDef(..) | ty::Generator(..) | ty::Closure(..) => { + ty::FnDef(..) | ty::Coroutine(..) | ty::Closure(..) => { bug!("Unexpected closure type in variance computation"); } @@ -312,7 +312,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // types, where we use Error as the Self type } - ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Bound(..) | ty::Infer(..) => { + ty::Placeholder(..) | ty::CoroutineWitness(..) | ty::Bound(..) | ty::Infer(..) => { bug!("unexpected type encountered in variance inference: {}", ty); } } diff --git a/compiler/rustc_hir_typeck/messages.ftl b/compiler/rustc_hir_typeck/messages.ftl index 9950a226333e8..4fd9391acc368 100644 --- a/compiler/rustc_hir_typeck/messages.ftl +++ b/compiler/rustc_hir_typeck/messages.ftl @@ -150,5 +150,5 @@ hir_typeck_union_pat_multiple_fields = union patterns should have exactly one fi hir_typeck_use_is_empty = consider using the `is_empty` method on `{$expr_ty}` to determine if it contains anything -hir_typeck_yield_expr_outside_of_generator = - yield expression outside of generator literal +hir_typeck_yield_expr_outside_of_coroutine = + yield expression outside of coroutine literal diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 78d30f3aa12ec..5eb68cf6b28c3 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -304,8 +304,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::ExprKind::Block(..), ) = (parent_node, callee_node) { - let fn_decl_span = if hir.body(body).generator_kind - == Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure)) + let fn_decl_span = if hir.body(body).coroutine_kind + == Some(hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure)) { // Actually need to unwrap one more layer of HIR to get to // the _real_ closure... diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 419e154a17ab0..a834ea150477c 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -128,13 +128,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ty::Uint(..) | ty::Float(_) | ty::Array(..) - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::RawPtr(_) | ty::Ref(..) | ty::FnDef(..) | ty::FnPtr(..) | ty::Closure(..) - | ty::Generator(..) + | ty::Coroutine(..) | ty::Adt(..) | ty::Never | ty::Dynamic(_, _, ty::DynStar) diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index 26ea7b0fdb972..e7060dac844b9 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -2,8 +2,8 @@ use std::cell::RefCell; use crate::coercion::CoerceMany; use crate::gather_locals::GatherLocalsVisitor; +use crate::CoroutineTypes; use crate::FnCtxt; -use crate::GeneratorTypes; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::intravisit::Visitor; @@ -31,9 +31,9 @@ pub(super) fn check_fn<'a, 'tcx>( decl: &'tcx hir::FnDecl<'tcx>, fn_def_id: LocalDefId, body: &'tcx hir::Body<'tcx>, - can_be_generator: Option, + can_be_coroutine: Option, params_can_be_unsized: bool, -) -> Option> { +) -> Option> { let fn_id = fcx.tcx.hir().local_def_id_to_hir_id(fn_def_id); let tcx = fcx.tcx; @@ -55,10 +55,10 @@ pub(super) fn check_fn<'a, 'tcx>( fn_maybe_err(tcx, span, fn_sig.abi); - if let Some(kind) = body.generator_kind - && can_be_generator.is_some() + if let Some(kind) = body.coroutine_kind + && can_be_coroutine.is_some() { - let yield_ty = if kind == hir::GeneratorKind::Gen { + let yield_ty = if kind == hir::CoroutineKind::Coroutine { let yield_ty = fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span, @@ -69,7 +69,7 @@ pub(super) fn check_fn<'a, 'tcx>( Ty::new_unit(tcx) }; - // Resume type defaults to `()` if the generator has no argument. + // Resume type defaults to `()` if the coroutine has no argument. let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| Ty::new_unit(tcx)); fcx.resume_yield_tys = Some((resume_ty, yield_ty)); @@ -124,13 +124,13 @@ pub(super) fn check_fn<'a, 'tcx>( fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::SizedReturnType); fcx.check_return_expr(&body.value, false); - // We insert the deferred_generator_interiors entry after visiting the body. - // This ensures that all nested generators appear before the entry of this generator. - // resolve_generator_interiors relies on this property. - let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_generator, body.generator_kind) { + // We insert the deferred_coroutine_interiors entry after visiting the body. + // This ensures that all nested coroutines appear before the entry of this coroutine. + // resolve_coroutine_interiors relies on this property. + let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_coroutine, body.coroutine_kind) { let interior = fcx .next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span }); - fcx.deferred_generator_interiors.borrow_mut().push(( + fcx.deferred_coroutine_interiors.borrow_mut().push(( fn_def_id, body.id(), interior, @@ -138,11 +138,11 @@ pub(super) fn check_fn<'a, 'tcx>( )); let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap(); - Some(GeneratorTypes { + Some(CoroutineTypes { resume_ty, yield_ty, interior, - movability: can_be_generator.unwrap(), + movability: can_be_coroutine.unwrap(), }) } else { None diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 06542b0cc245c..cf8a4cafbb611 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -1,6 +1,6 @@ //! Code for type-checking closure expressions. -use super::{check_fn, Expectation, FnCtxt, GeneratorTypes}; +use super::{check_fn, CoroutineTypes, Expectation, FnCtxt}; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; @@ -84,7 +84,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!(?bound_sig, ?liberated_sig); let mut fcx = FnCtxt::new(self, self.param_env, closure.def_id); - let generator_types = check_fn( + let coroutine_types = check_fn( &mut fcx, liberated_sig, closure.fn_decl, @@ -105,11 +105,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: self.tcx.def_span(expr_def_id), }); - if let Some(GeneratorTypes { resume_ty, yield_ty, interior, movability }) = generator_types + if let Some(CoroutineTypes { resume_ty, yield_ty, interior, movability }) = coroutine_types { - let generator_args = ty::GeneratorArgs::new( + let coroutine_args = ty::CoroutineArgs::new( self.tcx, - ty::GeneratorArgsParts { + ty::CoroutineArgsParts { parent_args, resume_ty, yield_ty, @@ -119,10 +119,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, ); - return Ty::new_generator( + return Ty::new_coroutine( self.tcx, expr_def_id.to_def_id(), - generator_args.args, + coroutine_args.args, movability, ); } @@ -285,7 +285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } /// Given a projection like "::Result == Y", we can deduce - /// everything we need to know about a closure or generator. + /// everything we need to know about a closure or coroutine. /// /// The `cause_span` should be the span that caused us to /// have this expected signature, or `None` if we can't readily @@ -306,14 +306,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let is_gen = gen_trait == Some(trait_def_id); if !is_fn && !is_gen { - debug!("not fn or generator"); + debug!("not fn or coroutine"); return None; } - // Check that we deduce the signature from the `<_ as std::ops::Generator>::Return` + // Check that we deduce the signature from the `<_ as std::ops::Coroutine>::Return` // associated item and not yield. if is_gen && self.tcx.associated_item(projection.projection_def_id()).name != sym::Return { - debug!("not `Return` assoc item of `Generator`"); + debug!("not `Return` assoc item of `Coroutine`"); return None; } @@ -327,7 +327,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => return None, } } else { - // Generators with a `()` resume type may be defined with 0 or 1 explicit arguments, + // Coroutines with a `()` resume type may be defined with 0 or 1 explicit arguments, // else they must have exactly 1 argument. For now though, just give up in this case. return None; }; @@ -623,7 +623,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let astconv: &dyn AstConv<'_> = self; trace!("decl = {:#?}", decl); - debug!(?body.generator_kind); + debug!(?body.coroutine_kind); let hir_id = self.tcx.hir().local_def_id_to_hir_id(expr_def_id); let bound_vars = self.tcx.late_bound_vars(hir_id); @@ -632,11 +632,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a)); let supplied_return = match decl.output { hir::FnRetTy::Return(ref output) => astconv.ast_ty_to_ty(&output), - hir::FnRetTy::DefaultReturn(_) => match body.generator_kind { + hir::FnRetTy::DefaultReturn(_) => match body.coroutine_kind { // In the case of the async block that we create for a function body, // we expect the return type of the block to match that of the enclosing // function. - Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn)) => { + Some(hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn)) => { debug!("closure is async fn body"); let def_id = self.tcx.hir().body_owner_def_id(body.id()); self.deduce_future_output_from_obligations(expr_def_id, def_id).unwrap_or_else( @@ -675,7 +675,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.normalize(self.tcx.hir().span(hir_id), result) } - /// Invoked when we are translating the generator that results + /// Invoked when we are translating the coroutine that results /// from desugaring an `async fn`. Returns the "sugared" return /// type of the `async fn` -- that is, the return type that the /// user specified. The "desugared" return type is an `impl @@ -688,7 +688,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { body_def_id: LocalDefId, ) -> Option> { let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| { - span_bug!(self.tcx.def_span(expr_def_id), "async fn generator outside of a fn") + span_bug!(self.tcx.def_span(expr_def_id), "async fn coroutine outside of a fn") }); let closure_span = self.tcx.def_span(expr_def_id); @@ -729,7 +729,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Error(_) => return None, _ => span_bug!( closure_span, - "async fn generator return type not an inference variable: {ret_ty}" + "async fn coroutine return type not an inference variable: {ret_ty}" ), }; diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index 8efccd5ba3eef..aff1baa19601d 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -62,8 +62,8 @@ pub struct RustCallIncorrectArgs { } #[derive(Diagnostic)] -#[diag(hir_typeck_yield_expr_outside_of_generator, code = "E0627")] -pub struct YieldExprOutsideOfGenerator { +#[diag(hir_typeck_yield_expr_outside_of_coroutine, code = "E0627")] +pub struct YieldExprOutsideOfCoroutine { #[primary_span] pub span: Span, } diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 96df0346ac643..be225ceb84321 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -10,7 +10,7 @@ use crate::errors::TypeMismatchFruTypo; use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive}; use crate::errors::{ FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct, HelpUseLatestEdition, - YieldExprOutsideOfGenerator, + YieldExprOutsideOfCoroutine, }; use crate::fatally_break_rust; use crate::method::{MethodCallComponents, SelfSource}; @@ -3019,7 +3019,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Ty::new_unit(self.tcx) } _ => { - self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span }); + self.tcx.sess.emit_err(YieldExprOutsideOfCoroutine { span: expr.span }); // Avoid expressions without types during writeback (#78653). self.check_expr(value); Ty::new_unit(self.tcx) diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 8bc66ac5509be..6be3ad6577bdb 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -779,7 +779,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { let closure_def_id = closure_expr.def_id; let upvars = tcx.upvars_mentioned(self.body_owner); - // For purposes of this function, generator and closures are equivalent. + // For purposes of this function, coroutine and closures are equivalent. let body_owner_is_closure = matches!(tcx.hir().body_owner_kind(self.body_owner), hir::BodyOwnerKind::Closure,); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 6e0e02b78149e..afa5a3b9379ea 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -509,40 +509,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { typeck_results.rvalue_scopes = rvalue_scopes; } - /// Unify the inference variables corresponding to generator witnesses, and save all the + /// Unify the inference variables corresponding to coroutine witnesses, and save all the /// predicates that were stalled on those inference variables. /// - /// This process allows to conservatively save all predicates that do depend on the generator - /// interior types, for later processing by `check_generator_obligations`. + /// This process allows to conservatively save all predicates that do depend on the coroutine + /// interior types, for later processing by `check_coroutine_obligations`. /// /// We must not attempt to select obligations after this method has run, or risk query cycle /// ICE. #[instrument(level = "debug", skip(self))] - pub(in super::super) fn resolve_generator_interiors(&self, def_id: DefId) { + pub(in super::super) fn resolve_coroutine_interiors(&self, def_id: DefId) { // Try selecting all obligations that are not blocked on inference variables. - // Once we start unifying generator witnesses, trying to select obligations on them will + // Once we start unifying coroutine witnesses, trying to select obligations on them will // trigger query cycle ICEs, as doing so requires MIR. self.select_obligations_where_possible(|_| {}); - let generators = std::mem::take(&mut *self.deferred_generator_interiors.borrow_mut()); - debug!(?generators); + let coroutines = std::mem::take(&mut *self.deferred_coroutine_interiors.borrow_mut()); + debug!(?coroutines); - for &(expr_def_id, body_id, interior, _) in generators.iter() { + for &(expr_def_id, body_id, interior, _) in coroutines.iter() { debug!(?expr_def_id); - // Create the `GeneratorWitness` type that we will unify with `interior`. + // Create the `CoroutineWitness` type that we will unify with `interior`. let args = ty::GenericArgs::identity_for_item( self.tcx, self.tcx.typeck_root_def_id(expr_def_id.to_def_id()), ); - let witness = Ty::new_generator_witness(self.tcx, expr_def_id.to_def_id(), args); + let witness = Ty::new_coroutine_witness(self.tcx, expr_def_id.to_def_id(), args); // Unify `interior` with `witness` and collect all the resulting obligations. let span = self.tcx.hir().body(body_id).value.span; let ok = self .at(&self.misc(span), self.param_env) .eq(DefineOpaqueTypes::No, interior, witness) - .expect("Failed to unify generator interior type"); + .expect("Failed to unify coroutine interior type"); let mut obligations = ok.obligations; // Also collect the obligations that were unstalled by this unification. @@ -553,7 +553,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!(?obligations); self.typeck_results .borrow_mut() - .generator_interior_predicates + .coroutine_interior_predicates .insert(expr_def_id, obligations); } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 522d0e2616bc8..facbeb8badfac 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -366,7 +366,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { box traits::SelectionOutputTypeParameterMismatch { expected_trait_ref, .. }, ), ) = error.code - && let ty::Closure(def_id, _) | ty::Generator(def_id, ..) = + && let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) = expected_trait_ref.skip_binder().self_ty().kind() && span.overlaps(self.tcx.def_span(*def_id)) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 9f1800b45c33a..33dfa16a651fb 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -367,13 +367,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } - // For this check, we do *not* want to treat async generator closures (async blocks) + // For this check, we do *not* want to treat async coroutine closures (async blocks) // as proper closures. Doing so would regress type inference when feeding // the return value of an argument-position async block to an argument-position // closure wrapped in a block. // See . let is_closure = if let ExprKind::Closure(closure) = arg.kind { - !tcx.generator_is_async(closure.def_id.to_def_id()) + !tcx.coroutine_is_async(closure.def_id.to_def_id()) } else { false }; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 14d6914134343..04220397872ee 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -9,7 +9,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind}; use rustc_hir::lang_items::LangItem; use rustc_hir::{ - AsyncGeneratorKind, Expr, ExprKind, GeneratorKind, GenericBound, HirId, Node, Path, QPath, + AsyncCoroutineKind, CoroutineKind, Expr, ExprKind, GenericBound, HirId, Node, Path, QPath, Stmt, StmtKind, TyKind, WherePredicate, }; use rustc_hir_analysis::astconv::AstConv; @@ -532,10 +532,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Tuple(tuple) if tuple.is_empty() => { errors::SuggestBoxing::Unit { start: span.shrink_to_lo(), end: span } } - ty::Generator(def_id, ..) + ty::Coroutine(def_id, ..) if matches!( - self.tcx.generator_kind(def_id), - Some(GeneratorKind::Async(AsyncGeneratorKind::Closure)) + self.tcx.coroutine_kind(def_id), + Some(CoroutineKind::Async(AsyncCoroutineKind::Closure)) ) => { errors::SuggestBoxing::AsyncBody diff --git a/compiler/rustc_hir_typeck/src/inherited.rs b/compiler/rustc_hir_typeck/src/inherited.rs index bee79242fd1ee..efd0b8577cf9a 100644 --- a/compiler/rustc_hir_typeck/src/inherited.rs +++ b/compiler/rustc_hir_typeck/src/inherited.rs @@ -55,8 +55,8 @@ pub struct Inherited<'tcx> { pub(super) deferred_asm_checks: RefCell, hir::HirId)>>, - pub(super) deferred_generator_interiors: - RefCell, hir::GeneratorKind)>>, + pub(super) deferred_coroutine_interiors: + RefCell, hir::CoroutineKind)>>, /// Whenever we introduce an adjustment from `!` into a type variable, /// we record that type variable here. This is later used to inform @@ -94,7 +94,7 @@ impl<'tcx> Inherited<'tcx> { deferred_cast_checks: RefCell::new(Vec::new()), deferred_transmute_checks: RefCell::new(Vec::new()), deferred_asm_checks: RefCell::new(Vec::new()), - deferred_generator_interiors: RefCell::new(Vec::new()), + deferred_coroutine_interiors: RefCell::new(Vec::new()), diverging_type_vars: RefCell::new(Default::default()), infer_var_info: RefCell::new(Default::default()), } diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index cd6adb345e7a3..46dcc455558be 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -255,11 +255,11 @@ fn typeck_with_fallback<'tcx>( fcx.check_casts(); fcx.select_obligations_where_possible(|_| {}); - // Closure and generator analysis may run after fallback + // Closure and coroutine analysis may run after fallback // because they don't constrain other type variables. fcx.closure_analyze(body); assert!(fcx.deferred_call_resolutions.borrow().is_empty()); - // Before the generator analysis, temporary scopes shall be marked to provide more + // Before the coroutine analysis, temporary scopes shall be marked to provide more // precise information on types to be captured. fcx.resolve_rvalue_scopes(def_id.to_def_id()); @@ -273,7 +273,7 @@ fn typeck_with_fallback<'tcx>( debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations()); // This must be the last thing before `report_ambiguity_errors`. - fcx.resolve_generator_interiors(def_id.to_def_id()); + fcx.resolve_coroutine_interiors(def_id.to_def_id()); debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations()); @@ -298,20 +298,20 @@ fn typeck_with_fallback<'tcx>( typeck_results } -/// When `check_fn` is invoked on a generator (i.e., a body that +/// When `check_fn` is invoked on a coroutine (i.e., a body that /// includes yield), it returns back some information about the yield /// points. -struct GeneratorTypes<'tcx> { - /// Type of generator argument / values returned by `yield`. +struct CoroutineTypes<'tcx> { + /// Type of coroutine argument / values returned by `yield`. resume_ty: Ty<'tcx>, /// Type of value that is yielded. yield_ty: Ty<'tcx>, - /// Types that are captured (see `GeneratorInterior` for more). + /// Types that are captured (see `CoroutineInterior` for more). interior: Ty<'tcx>, - /// Indicates if the generator is movable or static (immovable). + /// Indicates if the coroutine is movable or static (immovable). movability: hir::Movability, } diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index c46e641b10d24..d0d3b0e5b73cf 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -20,7 +20,7 @@ use rustc_span::Span; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _; use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt}; -use rustc_type_ir::sty::TyKind::*; +use rustc_type_ir::TyKind::*; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Checks a `a = b` diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 4d64139036811..75c70ec59fb79 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -172,7 +172,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.node_ty(closure_hir_id); let (closure_def_id, args) = match *ty.kind() { ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args)), - ty::Generator(def_id, args, _) => (def_id, UpvarArgs::Generator(args)), + ty::Coroutine(def_id, args, _) => (def_id, UpvarArgs::Coroutine(args)), ty::Error(_) => { // #51714: skip analysis when we have already encountered type errors return; @@ -366,7 +366,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Note that we *always* infer a minimal kind, even if /// we don't always *use* that in the final result (i.e., sometimes /// we've taken the closure kind from the expectations instead, and - /// for generators we don't even implement the closure traits + /// for coroutines we don't even implement the closure traits /// really). /// /// If we inferred that the closure needs to be FnMut/FnOnce, last element of the returned tuple diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 322859154bbce..896aacc699312 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -63,7 +63,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.visit_coercion_casts(); wbcx.visit_user_provided_tys(); wbcx.visit_user_provided_sigs(); - wbcx.visit_generator_interior(); + wbcx.visit_coroutine_interior(); wbcx.visit_offset_of_container_types(); wbcx.typeck_results.rvalue_scopes = @@ -540,16 +540,16 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { ); } - fn visit_generator_interior(&mut self) { + fn visit_coroutine_interior(&mut self) { let fcx_typeck_results = self.fcx.typeck_results.borrow(); assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner); self.tcx().with_stable_hashing_context(move |ref hcx| { for (&expr_def_id, predicates) in - fcx_typeck_results.generator_interior_predicates.to_sorted(hcx, false).into_iter() + fcx_typeck_results.coroutine_interior_predicates.to_sorted(hcx, false).into_iter() { let predicates = self.resolve(predicates.clone(), &self.fcx.tcx.def_span(expr_def_id)); - self.typeck_results.generator_interior_predicates.insert(expr_def_id, predicates); + self.typeck_results.coroutine_interior_predicates.insert(expr_def_id, predicates); } }) } diff --git a/compiler/rustc_infer/messages.ftl b/compiler/rustc_infer/messages.ftl index b36fb6a4dbac9..2de87cbe631ac 100644 --- a/compiler/rustc_infer/messages.ftl +++ b/compiler/rustc_infer/messages.ftl @@ -181,19 +181,19 @@ infer_more_targeted = {$has_param_name -> infer_msl_introduces_static = introduces a `'static` lifetime requirement infer_msl_unmet_req = because this has an unmet lifetime requirement -infer_need_type_info_in_generator = - type inside {$generator_kind -> +infer_need_type_info_in_coroutine = + type inside {$coroutine_kind -> [async_block] `async` block [async_closure] `async` closure [async_fn] `async fn` body - *[generator] generator + *[coroutine] coroutine } must be known in this context infer_nothing = {""} infer_oc_cant_coerce = cannot coerce intrinsics to function pointers -infer_oc_closure_selfref = closure/generator type that references itself +infer_oc_closure_selfref = closure/coroutine type that references itself infer_oc_const_compat = const not compatible with trait infer_oc_fn_lang_correct_type = {$lang_item_name -> [panic_impl] `#[panic_handler]` @@ -284,7 +284,7 @@ infer_sbfrit_change_return_type = you could change the return type to be a boxed infer_source_kind_closure_return = try giving this closure an explicit return type -# generator_kind may need to be translated +# coroutine_kind may need to be translated infer_source_kind_fully_qualified = try using a fully qualified path to specify the expected types diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 4124c9eada9c1..0e2f9ba70fecb 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -457,8 +457,8 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { } ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Bool | ty::Char | ty::Int(..) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 496bb1766a71f..fdeaf7f6850d8 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2821,7 +2821,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> { // say, also take a look at the error code, maybe we can // tailor to that. _ => match terr { - TypeError::CyclicTy(ty) if ty.is_closure() || ty.is_generator() => Error0644, + TypeError::CyclicTy(ty) if ty.is_closure() || ty.is_coroutine() => Error0644, TypeError::IntrinsicCast => Error0308, _ => Error0308, }, @@ -2868,7 +2868,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> { // say, also take a look at the error code, maybe we can // tailor to that. _ => match terr { - TypeError::CyclicTy(ty) if ty.is_closure() || ty.is_generator() => { + TypeError::CyclicTy(ty) if ty.is_closure() || ty.is_coroutine() => { ObligationCauseFailureCode::ClosureSelfref { span } } TypeError::IntrinsicCast => { @@ -2936,7 +2936,7 @@ pub enum TyCategory { Closure, Opaque, OpaqueFuture, - Generator(hir::GeneratorKind), + Coroutine(hir::CoroutineKind), Foreign, } @@ -2946,7 +2946,7 @@ impl TyCategory { Self::Closure => "closure", Self::Opaque => "opaque type", Self::OpaqueFuture => "future", - Self::Generator(gk) => gk.descr(), + Self::Coroutine(gk) => gk.descr(), Self::Foreign => "foreign type", } } @@ -2959,8 +2959,8 @@ impl TyCategory { if tcx.ty_is_opaque_future(ty) { Self::OpaqueFuture } else { Self::Opaque }; Some((kind, def_id)) } - ty::Generator(def_id, ..) => { - Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id)) + ty::Coroutine(def_id, ..) => { + Some((Self::Coroutine(tcx.coroutine_kind(def_id).unwrap()), def_id)) } ty::Foreign(def_id) => Some((Self::Foreign, def_id)), _ => None, diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 5408b99235d42..7bc414ff52218 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -864,11 +864,11 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { GenericArgKind::Type(ty) => { if matches!( ty.kind(), - ty::Alias(ty::Opaque, ..) | ty::Closure(..) | ty::Generator(..) + ty::Alias(ty::Opaque, ..) | ty::Closure(..) | ty::Coroutine(..) ) { // Opaque types can't be named by the user right now. // - // Both the generic arguments of closures and generators can + // Both the generic arguments of closures and coroutines can // also not be named. We may want to only look into the closure // signature in case it has no captures, as that can be represented // using `fn(T) -> R`. diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index 3da6d8a89e102..faea8bc98aa2d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -215,7 +215,7 @@ impl Trait for X { #traits-as-parameters", ); } - (ty::Param(p), ty::Closure(..) | ty::Generator(..)) => { + (ty::Param(p), ty::Closure(..) | ty::Coroutine(..)) => { let generics = tcx.generics_of(body_owner_def_id); let p_span = tcx.def_span(generics.type_param(p, tcx).def_id); if !sp.contains(p_span) { @@ -325,7 +325,7 @@ impl Trait for X { } CyclicTy(ty) => { // Watch out for various cases of cyclic types and try to explain. - if ty.is_closure() || ty.is_generator() { + if ty.is_closure() || ty.is_coroutine() { diag.note( "closures cannot capture themselves or take themselves as argument;\n\ this error may be the result of a recent compiler bug-fix,\n\ diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 1c3a5c3607650..e1a14ed0faf6c 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -454,16 +454,16 @@ where args.as_closure().sig_as_fn_ptr_ty().visit_with(self); } - ty::Generator(_, ref args, _) => { + ty::Coroutine(_, ref args, _) => { // Skip lifetime parameters of the enclosing item(s) // Also skip the witness type, because that has no free regions. - for upvar in args.as_generator().upvar_tys() { + for upvar in args.as_coroutine().upvar_tys() { upvar.visit_with(self); } - args.as_generator().return_ty().visit_with(self); - args.as_generator().yield_ty().visit_with(self); - args.as_generator().resume_ty().visit_with(self); + args.as_coroutine().return_ty().visit_with(self); + args.as_coroutine().yield_ty().visit_with(self); + args.as_coroutine().resume_ty().visit_with(self); } ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref args, .. }) => { diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index 6a9d40daab62f..38819e8ad8a62 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -102,17 +102,17 @@ fn compute_components<'tcx>( compute_components(tcx, tupled_ty, out, visited); } - ty::Generator(_, ref args, _) => { + ty::Coroutine(_, ref args, _) => { // Same as the closure case - let tupled_ty = args.as_generator().tupled_upvars_ty(); + let tupled_ty = args.as_coroutine().tupled_upvars_ty(); compute_components(tcx, tupled_ty, out, visited); - // We ignore regions in the generator interior as we don't + // We ignore regions in the coroutine interior as we don't // want these to affect region inference } // All regions are bound inside a witness - ty::GeneratorWitness(..) => (), + ty::CoroutineWitness(..) => (), // OutlivesTypeParameterEnv -- the actual checking that `X:'a` // is implied by the environment is done in regionck. diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 718dbaaafccec..7a7e9024bd88c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -799,9 +799,9 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { }); tcx.hir().par_body_owners(|def_id| { - if let rustc_hir::def::DefKind::Generator = tcx.def_kind(def_id) { - tcx.ensure().mir_generator_witnesses(def_id); - tcx.ensure().check_generator_obligations(def_id); + if let rustc_hir::def::DefKind::Coroutine = tcx.def_kind(def_id) { + tcx.ensure().mir_coroutine_witnesses(def_id); + tcx.ensure().check_coroutine_obligations(def_id); } }); diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 4c4d2933bf4f4..068f1372c0ecd 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -551,19 +551,19 @@ lint_unused_closure = lint_unused_comparisons = comparison is useless due to type limits +lint_unused_coroutine = + unused {$pre}{$count -> + [one] coroutine + *[other] coroutine + }{$post} that must be used + .note = coroutines are lazy and do nothing unless resumed + lint_unused_def = unused {$pre}`{$def}`{$post} that must be used .suggestion = use `let _ = ...` to ignore the resulting value lint_unused_delim = unnecessary {$delim} around {$item} .suggestion = remove these {$delim} -lint_unused_generator = - unused {$pre}{$count -> - [one] generator - *[other] generator - }{$post} that must be used - .note = generators are lazy and do nothing unless resumed - lint_unused_import_braces = braces around {$node} is unnecessary lint_unused_op = unused {$op} that must be used diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index f6c7f4071dc75..6f6150a4172f5 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2475,7 +2475,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { ty: Ty<'tcx>, init: InitKind, ) -> Option { - use rustc_type_ir::sty::TyKind::*; + use rustc_type_ir::TyKind::*; match ty.kind() { // Primitive types that don't like 0 as a value. Ref(..) => Some("references must be non-null".into()), diff --git a/compiler/rustc_lint/src/foreign_modules.rs b/compiler/rustc_lint/src/foreign_modules.rs index e1df69bdaf252..86b3b4ad0ca95 100644 --- a/compiler/rustc_lint/src/foreign_modules.rs +++ b/compiler/rustc_lint/src/foreign_modules.rs @@ -262,7 +262,7 @@ fn structurally_same_type_impl<'tcx>( true } else { // Do a full, depth-first comparison between the two. - use rustc_type_ir::sty::TyKind::*; + use rustc_type_ir::TyKind::*; let a_kind = a.kind(); let b_kind = b.kind(); @@ -369,8 +369,8 @@ fn structurally_same_type_impl<'tcx>( (Dynamic(..), Dynamic(..)) | (Error(..), Error(..)) | (Closure(..), Closure(..)) - | (Generator(..), Generator(..)) - | (GeneratorWitness(..), GeneratorWitness(..)) + | (Coroutine(..), Coroutine(..)) + | (CoroutineWitness(..), CoroutineWitness(..)) | (Alias(ty::Projection, ..), Alias(ty::Projection, ..)) | (Alias(ty::Inherent, ..), Alias(ty::Inherent, ..)) | (Alias(ty::Opaque, ..), Alias(ty::Opaque, ..)) => false, diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 4eaf8bbf5ded2..756899e50a8cd 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1700,9 +1700,9 @@ pub struct UnusedClosure<'a> { // FIXME(davidtwco): this isn't properly translatable because of the // pre/post strings #[derive(LintDiagnostic)] -#[diag(lint_unused_generator)] +#[diag(lint_unused_coroutine)] #[note] -pub struct UnusedGenerator<'a> { +pub struct UnusedCoroutine<'a> { pub count: usize, pub pre: &'a str, pub post: &'a str, diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index f89b63e6f9fc0..c04053d1865db 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1272,8 +1272,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { | ty::Bound(..) | ty::Error(_) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Placeholder(..) | ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty), } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 65de7e10272bb..6b31fb079e01b 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1,7 +1,7 @@ use crate::lints::{ PathStatementDrop, PathStatementDropSub, PathStatementNoEffect, UnusedAllocationDiag, - UnusedAllocationMutDiag, UnusedClosure, UnusedDef, UnusedDefSuggestion, UnusedDelim, - UnusedDelimSuggestion, UnusedGenerator, UnusedImportBracesDiag, UnusedOp, UnusedOpSuggestion, + UnusedAllocationMutDiag, UnusedClosure, UnusedCoroutine, UnusedDef, UnusedDefSuggestion, + UnusedDelim, UnusedDelimSuggestion, UnusedImportBracesDiag, UnusedOp, UnusedOpSuggestion, UnusedResult, }; use crate::Lint; @@ -257,8 +257,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { Array(Box, u64), /// The root of the unused_closures lint. Closure(Span), - /// The root of the unused_generators lint. - Generator(Span), + /// The root of the unused_coroutines lint. + Coroutine(Span), } #[instrument(skip(cx, expr), level = "debug", ret)] @@ -350,16 +350,16 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { .map(|inner| MustUsePath::Array(Box::new(inner), len)), }, ty::Closure(..) => Some(MustUsePath::Closure(span)), - ty::Generator(def_id, ..) => { + ty::Coroutine(def_id, ..) => { // async fn should be treated as "implementor of `Future`" - let must_use = if cx.tcx.generator_is_async(def_id) { + let must_use = if cx.tcx.coroutine_is_async(def_id) { let def_id = cx.tcx.lang_items().future_trait()?; is_def_must_use(cx, def_id, span) .map(|inner| MustUsePath::Opaque(Box::new(inner))) } else { None }; - must_use.or(Some(MustUsePath::Generator(span))) + must_use.or(Some(MustUsePath::Coroutine(span))) } _ => None, } @@ -482,11 +482,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { UnusedClosure { count: plural_len, pre: descr_pre, post: descr_post }, ); } - MustUsePath::Generator(span) => { + MustUsePath::Coroutine(span) => { cx.emit_spanned_lint( UNUSED_MUST_USE, *span, - UnusedGenerator { count: plural_len, pre: descr_pre, post: descr_post }, + UnusedCoroutine { count: plural_len, pre: descr_pre, post: descr_post }, ); } MustUsePath::Def(span, def_id, reason) => { diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index ddeb39669dc7f..ec2517b581e3e 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -4,8 +4,9 @@ #![cfg_attr(not(bootstrap), allow(internal_features))] #![feature(decl_macro)] #![feature(extract_if)] -#![feature(generators)] -#![feature(iter_from_generator)] +#![cfg_attr(bootstrap, feature(generators))] +#![cfg_attr(not(bootstrap), feature(coroutines))] +#![feature(iter_from_coroutine)] #![feature(let_chains)] #![feature(proc_macro_internals)] #![feature(macro_metavar_expr)] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index d6ceaa8a0914b..354023cea9e07 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1239,7 +1239,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { id: DefIndex, sess: &'a Session, ) -> impl Iterator + 'a { - iter::from_generator(move || { + iter::from_coroutine(move || { if let Some(data) = &self.root.proc_macro_data { // If we are loading as a proc macro, we want to return // the view of this crate as a proc macro crate. diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 6b6c0d5274251..595d816e9493c 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -221,7 +221,7 @@ provide! { tcx, def_id, other, cdata, optimized_mir => { table } mir_for_ctfe => { table } closure_saved_names_of_captured_variables => { table } - mir_generator_witnesses => { table } + mir_coroutine_witnesses => { table } promoted_mir => { table } def_span => { table } def_ident_span => { table } @@ -241,7 +241,7 @@ provide! { tcx, def_id, other, cdata, rendered_const => { table } asyncness => { table_direct } fn_arg_names => { table } - generator_kind => { table } + coroutine_kind => { table } trait_def => { table } deduced_param_attrs => { table } is_type_alias_impl_trait => { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 345b3d5e57f8f..de436c16ca924 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -856,7 +856,7 @@ fn should_encode_span(def_kind: DefKind) -> bool { | DefKind::Field | DefKind::Impl { .. } | DefKind::Closure - | DefKind::Generator => true, + | DefKind::Coroutine => true, DefKind::ForeignMod | DefKind::GlobalAsm => false, } } @@ -897,7 +897,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool { | DefKind::OpaqueTy | DefKind::LifetimeParam | DefKind::GlobalAsm - | DefKind::Generator => false, + | DefKind::Coroutine => false, } } @@ -933,7 +933,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool { | DefKind::LifetimeParam | DefKind::GlobalAsm | DefKind::Closure - | DefKind::Generator => false, + | DefKind::Coroutine => false, } } @@ -968,7 +968,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool { | DefKind::GlobalAsm | DefKind::Impl { .. } | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::ExternCrate => false, } } @@ -1004,7 +1004,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool { | DefKind::InlineConst | DefKind::GlobalAsm | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::ExternCrate => false, } } @@ -1060,8 +1060,8 @@ fn should_encode_mir( || tcx.is_const_default_method(def_id.to_def_id()); (is_const_fn, opt) } - // Generators require optimized MIR to compute layout. - DefKind::Generator => (false, true), + // Coroutines require optimized MIR to compute layout. + DefKind::Coroutine => (false, true), // The others don't have MIR. _ => (false, false), } @@ -1097,7 +1097,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def | DefKind::InlineConst | DefKind::GlobalAsm | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::ExternCrate => false, DefKind::TyAlias => tcx.type_alias_is_lazy(def_id), } @@ -1127,7 +1127,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool { | DefKind::Field | DefKind::TyParam | DefKind::Closure - | DefKind::Generator => true, + | DefKind::Coroutine => true, DefKind::Mod | DefKind::ForeignMod | DefKind::ConstParam @@ -1156,7 +1156,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> | DefKind::AssocFn | DefKind::AssocConst | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst => true, @@ -1217,7 +1217,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool { | DefKind::Impl { .. } | DefKind::AssocConst | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst @@ -1256,7 +1256,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool { | DefKind::OpaqueTy | DefKind::Impl { of_trait: false } | DefKind::ForeignTy - | DefKind::Generator + | DefKind::Coroutine | DefKind::ConstParam | DefKind::InlineConst | DefKind::AssocTy @@ -1291,7 +1291,7 @@ fn should_encode_const(def_kind: DefKind) -> bool { | DefKind::Impl { .. } | DefKind::AssocFn | DefKind::Closure - | DefKind::Generator + | DefKind::Coroutine | DefKind::ConstParam | DefKind::AssocTy | DefKind::TyParam @@ -1446,9 +1446,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.encode_info_for_assoc_item(def_id); } } - if let DefKind::Generator = def_kind { - let data = self.tcx.generator_kind(def_id).unwrap(); - record!(self.tables.generator_kind[def_id] <- data); + if let DefKind::Coroutine = def_kind { + let data = self.tcx.coroutine_kind(def_id).unwrap(); + record!(self.tables.coroutine_kind[def_id] <- data); } if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind { self.encode_info_for_adt(local_id); @@ -1629,10 +1629,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()] <- tcx.closure_saved_names_of_captured_variables(def_id)); - if let DefKind::Generator = self.tcx.def_kind(def_id) - && let Some(witnesses) = tcx.mir_generator_witnesses(def_id) + if let DefKind::Coroutine = self.tcx.def_kind(def_id) + && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id) { - record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses); + record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses); } } if encode_const { @@ -1656,10 +1656,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id)); - if let DefKind::Generator = self.tcx.def_kind(def_id) - && let Some(witnesses) = tcx.mir_generator_witnesses(def_id) + if let DefKind::Coroutine = self.tcx.def_kind(def_id) + && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id) { - record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses); + record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses); } let instance = ty::InstanceDef::Item(def_id.to_def_id()); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 2609767a85c5d..9ae5c0af0b248 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -429,7 +429,7 @@ define_tables! { mir_for_ctfe: Table>>, cross_crate_inlinable: Table, closure_saved_names_of_captured_variables: Table>>, - mir_generator_witnesses: Table>>, + mir_coroutine_witnesses: Table>>, promoted_mir: Table>>>, thir_abstract_const: Table>>>, impl_parent: Table, @@ -442,7 +442,7 @@ define_tables! { rendered_const: Table>, asyncness: Table, fn_arg_names: Table>, - generator_kind: Table>, + coroutine_kind: Table>, trait_def: Table>, trait_item_def_id: Table, expn_that_defined: Table>, diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 34118e9e8a331..027994c40ab72 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -167,7 +167,7 @@ fixed_size_enum! { ( Impl { of_trait: false } ) ( Impl { of_trait: true } ) ( Closure ) - ( Generator ) + ( Coroutine ) ( Static(ast::Mutability::Not) ) ( Static(ast::Mutability::Mut) ) ( Ctor(CtorOf::Struct, CtorKind::Fn) ) diff --git a/compiler/rustc_middle/messages.ftl b/compiler/rustc_middle/messages.ftl index 82162fd85711b..37ff5bcf1e2da 100644 --- a/compiler/rustc_middle/messages.ftl +++ b/compiler/rustc_middle/messages.ftl @@ -5,12 +5,12 @@ middle_assert_async_resume_after_panic = `async fn` resumed after panicking middle_assert_async_resume_after_return = `async fn` resumed after completion -middle_assert_divide_by_zero = - attempt to divide `{$val}` by zero +middle_assert_coroutine_resume_after_panic = coroutine resumed after panicking -middle_assert_generator_resume_after_panic = generator resumed after panicking +middle_assert_coroutine_resume_after_return = coroutine resumed after completion -middle_assert_generator_resume_after_return = generator resumed after completion +middle_assert_divide_by_zero = + attempt to divide `{$val}` by zero middle_assert_misaligned_ptr_deref = misaligned pointer dereference: address must be a multiple of {$required} but is {$found} diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 77643715fff5e..3ca26ec98c631 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -240,7 +240,7 @@ impl<'hir> Map<'hir> { Node::Field(_) => DefKind::Field, Node::Expr(expr) => match expr.kind { ExprKind::Closure(Closure { movability: None, .. }) => DefKind::Closure, - ExprKind::Closure(Closure { movability: Some(_), .. }) => DefKind::Generator, + ExprKind::Closure(Closure { movability: Some(_), .. }) => DefKind::Coroutine, _ => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)), }, Node::GenericParam(param) => match param.kind { @@ -445,7 +445,7 @@ impl<'hir> Map<'hir> { } DefKind::InlineConst => BodyOwnerKind::Const { inline: true }, DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn, - DefKind::Closure | DefKind::Generator => BodyOwnerKind::Closure, + DefKind::Closure | DefKind::Coroutine => BodyOwnerKind::Closure, DefKind::Static(mt) => BodyOwnerKind::Static(mt), dk => bug!("{:?} is not a body node: {:?}", def_id, dk), } diff --git a/compiler/rustc_middle/src/hir/nested_filter.rs b/compiler/rustc_middle/src/hir/nested_filter.rs index 6896837aa9109..adbe81bb22c77 100644 --- a/compiler/rustc_middle/src/hir/nested_filter.rs +++ b/compiler/rustc_middle/src/hir/nested_filter.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::nested_filter::NestedFilter; /// that are inside of an item-like. /// /// Notably, possible occurrences of bodies in non-item-like things -/// include: closures/generators, inline `const {}` blocks, and +/// include: closures/coroutines, inline `const {}` blocks, and /// constant arguments of types, e.g. in `let _: [(); /* HERE */];`. /// /// **This is the most common choice.** A very common pattern is diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index dee18dc11628c..448a3029ae97a 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -32,11 +32,12 @@ #![feature(core_intrinsics)] #![feature(discriminant_kind)] #![feature(exhaustive_patterns)] -#![feature(generators)] +#![cfg_attr(bootstrap, feature(generators))] +#![cfg_attr(not(bootstrap), feature(coroutines))] #![feature(get_mut_unchecked)] #![feature(if_let_guard)] #![feature(inline_const)] -#![feature(iter_from_generator)] +#![feature(iter_from_coroutine)] #![feature(negative_impls)] #![feature(never_type)] #![feature(extern_types)] diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index c50c5e6f701cd..56fed05c63f74 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -308,7 +308,7 @@ pub struct ScopeTree { /// The number of visit_expr and visit_pat calls done in the body. /// Used to sanity check visit_expr/visit_pat call count when - /// calculating generator interiors. + /// calculating coroutine interiors. pub body_expr_count: FxHashMap, } @@ -413,7 +413,7 @@ impl ScopeTree { /// Gives the number of expressions visited in a body. /// Used to sanity check visit_expr call count when - /// calculating generator interiors. + /// calculating coroutine interiors. pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option { self.body_expr_count.get(&body_id).copied() } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 3a5ff4dc91fde..a85af7c3fb511 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -17,7 +17,7 @@ use rustc_data_structures::captures::Captures; use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; -use rustc_hir::{self, GeneratorKind, ImplicitSelfKind}; +use rustc_hir::{self, CoroutineKind, ImplicitSelfKind}; use rustc_hir::{self as hir, HirId}; use rustc_session::Session; use rustc_target::abi::{FieldIdx, VariantIdx}; @@ -246,19 +246,19 @@ impl<'tcx> MirSource<'tcx> { } #[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)] -pub struct GeneratorInfo<'tcx> { - /// The yield type of the function, if it is a generator. +pub struct CoroutineInfo<'tcx> { + /// The yield type of the function, if it is a coroutine. pub yield_ty: Option>, - /// Generator drop glue. - pub generator_drop: Option>, + /// Coroutine drop glue. + pub coroutine_drop: Option>, - /// The layout of a generator. Produced by the state transformation. - pub generator_layout: Option>, + /// The layout of a coroutine. Produced by the state transformation. + pub coroutine_layout: Option>, - /// If this is a generator then record the type of source expression that caused this generator + /// If this is a coroutine then record the type of source expression that caused this coroutine /// to be created. - pub generator_kind: GeneratorKind, + pub coroutine_kind: CoroutineKind, } /// The lowered representation of a single function. @@ -284,7 +284,7 @@ pub struct Body<'tcx> { /// and used for debuginfo. Indexed by a `SourceScope`. pub source_scopes: IndexVec>, - pub generator: Option>>, + pub coroutine: Option>>, /// Declarations of locals. /// @@ -365,7 +365,7 @@ impl<'tcx> Body<'tcx> { arg_count: usize, var_debug_info: Vec>, span: Span, - generator_kind: Option, + coroutine_kind: Option, tainted_by_errors: Option, ) -> Self { // We need `arg_count` locals, and one for the return place. @@ -382,12 +382,12 @@ impl<'tcx> Body<'tcx> { source, basic_blocks: BasicBlocks::new(basic_blocks), source_scopes, - generator: generator_kind.map(|generator_kind| { - Box::new(GeneratorInfo { + coroutine: coroutine_kind.map(|coroutine_kind| { + Box::new(CoroutineInfo { yield_ty: None, - generator_drop: None, - generator_layout: None, - generator_kind, + coroutine_drop: None, + coroutine_layout: None, + coroutine_kind, }) }), local_decls, @@ -418,7 +418,7 @@ impl<'tcx> Body<'tcx> { source: MirSource::item(CRATE_DEF_ID.to_def_id()), basic_blocks: BasicBlocks::new(basic_blocks), source_scopes: IndexVec::new(), - generator: None, + coroutine: None, local_decls: IndexVec::new(), user_type_annotations: IndexVec::new(), arg_count: 0, @@ -548,22 +548,22 @@ impl<'tcx> Body<'tcx> { #[inline] pub fn yield_ty(&self) -> Option> { - self.generator.as_ref().and_then(|generator| generator.yield_ty) + self.coroutine.as_ref().and_then(|coroutine| coroutine.yield_ty) } #[inline] - pub fn generator_layout(&self) -> Option<&GeneratorLayout<'tcx>> { - self.generator.as_ref().and_then(|generator| generator.generator_layout.as_ref()) + pub fn coroutine_layout(&self) -> Option<&CoroutineLayout<'tcx>> { + self.coroutine.as_ref().and_then(|coroutine| coroutine.coroutine_layout.as_ref()) } #[inline] - pub fn generator_drop(&self) -> Option<&Body<'tcx>> { - self.generator.as_ref().and_then(|generator| generator.generator_drop.as_ref()) + pub fn coroutine_drop(&self) -> Option<&Body<'tcx>> { + self.coroutine.as_ref().and_then(|coroutine| coroutine.coroutine_drop.as_ref()) } #[inline] - pub fn generator_kind(&self) -> Option { - self.generator.as_ref().map(|generator| generator.generator_kind) + pub fn coroutine_kind(&self) -> Option { + self.coroutine.as_ref().map(|coroutine| coroutine.coroutine_kind) } #[inline] diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 3b3b61e4e21d3..dee25df53bd2b 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -130,8 +130,8 @@ fn dump_matched_mir_node<'tcx, F>( Some(promoted) => write!(file, "::{promoted:?}`")?, } writeln!(file, " {disambiguator} {pass_name}")?; - if let Some(ref layout) = body.generator_layout() { - writeln!(file, "/* generator_layout = {layout:#?} */")?; + if let Some(ref layout) = body.coroutine_layout() { + writeln!(file, "/* coroutine_layout = {layout:#?} */")?; } writeln!(file)?; extra_data(PassWhere::BeforeCFG, &mut file)?; @@ -782,7 +782,7 @@ impl<'tcx> TerminatorKind<'tcx> { Goto { .. } => write!(fmt, "goto"), SwitchInt { discr, .. } => write!(fmt, "switchInt({discr:?})"), Return => write!(fmt, "return"), - GeneratorDrop => write!(fmt, "generator_drop"), + CoroutineDrop => write!(fmt, "coroutine_drop"), UnwindResume => write!(fmt, "resume"), UnwindTerminate(reason) => { write!(fmt, "abort({})", reason.as_short_str()) @@ -865,7 +865,7 @@ impl<'tcx> TerminatorKind<'tcx> { pub fn fmt_successor_labels(&self) -> Vec> { use self::TerminatorKind::*; match *self { - Return | UnwindResume | UnwindTerminate(_) | Unreachable | GeneratorDrop => vec![], + Return | UnwindResume | UnwindTerminate(_) | Unreachable | CoroutineDrop => vec![], Goto { .. } => vec!["".into()], SwitchInt { ref targets, .. } => targets .values @@ -1046,8 +1046,8 @@ impl<'tcx> Debug for Rvalue<'tcx> { struct_fmt.finish() }), - AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { - let name = format!("{{generator@{:?}}}", tcx.def_span(def_id)); + AggregateKind::Coroutine(def_id, _, _) => ty::tls::with(|tcx| { + let name = format!("{{coroutine@{:?}}}", tcx.def_span(def_id)); let mut struct_fmt = fmt.debug_struct(&name); // FIXME(project-rfc-2229#48): This should be a list of capture names/places @@ -1301,8 +1301,8 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { self.push(&format!("+ args: {args:#?}")); } - AggregateKind::Generator(def_id, args, movability) => { - self.push("generator"); + AggregateKind::Coroutine(def_id, args, movability) => { + self.push("coroutine"); self.push(&format!("+ def_id: {def_id:?}")); self.push(&format!("+ args: {args:#?}")); self.push(&format!("+ movability: {movability:?}")); diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index f407dc4d7ae32..0540eb0efd6c9 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -133,11 +133,11 @@ pub struct UnsafetyCheckResult { rustc_index::newtype_index! { #[derive(HashStable)] #[debug_format = "_{}"] - pub struct GeneratorSavedLocal {} + pub struct CoroutineSavedLocal {} } #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] -pub struct GeneratorSavedTy<'tcx> { +pub struct CoroutineSavedTy<'tcx> { pub ty: Ty<'tcx>, /// Source info corresponding to the local in the original MIR body. pub source_info: SourceInfo, @@ -145,18 +145,18 @@ pub struct GeneratorSavedTy<'tcx> { pub ignore_for_traits: bool, } -/// The layout of generator state. +/// The layout of coroutine state. #[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] -pub struct GeneratorLayout<'tcx> { - /// The type of every local stored inside the generator. - pub field_tys: IndexVec>, +pub struct CoroutineLayout<'tcx> { + /// The type of every local stored inside the coroutine. + pub field_tys: IndexVec>, /// The name for debuginfo. - pub field_names: IndexVec>, + pub field_names: IndexVec>, /// Which of the above fields are in each variant. Note that one field may /// be stored in multiple variants. - pub variant_fields: IndexVec>, + pub variant_fields: IndexVec>, /// The source that led to each variant being created (usually, a yield or /// await). @@ -167,10 +167,10 @@ pub struct GeneratorLayout<'tcx> { /// layout. #[type_foldable(identity)] #[type_visitable(ignore)] - pub storage_conflicts: BitMatrix, + pub storage_conflicts: BitMatrix, } -impl Debug for GeneratorLayout<'_> { +impl Debug for CoroutineLayout<'_> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { /// Prints an iterator of (key, value) tuples as a map. struct MapPrinter<'a, K, V>(Cell + 'a>>>); @@ -185,7 +185,7 @@ impl Debug for GeneratorLayout<'_> { } } - /// Prints the generator variant name. + /// Prints the coroutine variant name. struct GenVariantPrinter(VariantIdx); impl From for GenVariantPrinter { fn from(idx: VariantIdx) -> Self { @@ -194,7 +194,7 @@ impl Debug for GeneratorLayout<'_> { } impl Debug for GenVariantPrinter { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let variant_name = ty::GeneratorArgs::variant_name(self.0); + let variant_name = ty::CoroutineArgs::variant_name(self.0); if fmt.alternate() { write!(fmt, "{:9}({:?})", variant_name, self.0) } else { @@ -211,7 +211,7 @@ impl Debug for GeneratorLayout<'_> { } } - fmt.debug_struct("GeneratorLayout") + fmt.debug_struct("CoroutineLayout") .field("field_tys", &MapPrinter::new(self.field_tys.iter_enumerated())) .field( "variant_fields", @@ -259,7 +259,7 @@ pub struct ConstQualifs { /// /// The requirements are listed as being between various `RegionVid`. The 0th /// region refers to `'static`; subsequent region vids refer to the free -/// regions that appear in the closure (or generator's) type, in order of +/// regions that appear in the closure (or coroutine's) type, in order of /// appearance. (This numbering is actually defined by the `UniversalRegions` /// struct in the NLL region checker. See for example /// `UniversalRegions::closure_mapping`.) Note the free regions in the diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 7a645fb5d62ba..b89c7bc512e1e 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -15,7 +15,7 @@ use crate::ty::{Region, UserTypeAnnotationIndex}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir}; -use rustc_hir::{self, GeneratorKind}; +use rustc_hir::{self, CoroutineKind}; use rustc_index::IndexVec; use rustc_target::abi::{FieldIdx, VariantIdx}; @@ -82,10 +82,10 @@ pub enum MirPhase { /// that Rust itself has them. Where exactly these are is generally subject to change, and so we /// don't document this here. Runtime MIR has most retags explicit (though implicit retags /// can still occur at `Rvalue::{Ref,AddrOf}`). - /// - Generator bodies: In analysis MIR, locals may actually be behind a pointer that user code has - /// access to. This occurs in generator bodies. Such locals do not behave like other locals, + /// - Coroutine bodies: In analysis MIR, locals may actually be behind a pointer that user code has + /// access to. This occurs in coroutine bodies. Such locals do not behave like other locals, /// because they eg may be aliased in surprising ways. Runtime MIR has no such special locals - - /// all generator bodies are lowered and so all places that look like locals really are locals. + /// all coroutine bodies are lowered and so all places that look like locals really are locals. /// /// Also note that the lint pass which reports eg `200_u8 + 200_u8` as an error is run as a part /// of analysis to runtime MIR lowering. To ensure lints are reported reliably, this means that @@ -137,7 +137,7 @@ pub enum RuntimePhase { /// In addition to the semantic changes, beginning with this phase, the following variants are /// disallowed: /// * [`TerminatorKind::Yield`] - /// * [`TerminatorKind::GeneratorDrop`] + /// * [`TerminatorKind::CoroutineDrop`] /// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array` /// * [`PlaceElem::OpaqueCast`] /// @@ -292,7 +292,7 @@ pub enum StatementKind<'tcx> { /// Write the discriminant for a variant to the enum Place. /// - /// This is permitted for both generators and ADTs. This does not necessarily write to the + /// This is permitted for both coroutines and ADTs. This does not necessarily write to the /// entire place; instead, it writes to the minimum set of bytes as required by the layout for /// the type. SetDiscriminant { place: Box>, variant_index: VariantIdx }, @@ -626,8 +626,8 @@ pub enum TerminatorKind<'tcx> { /// `dest = move _0`. It might additionally do other things, like have side-effects in the /// aliasing model. /// - /// If the body is a generator body, this has slightly different semantics; it instead causes a - /// `GeneratorState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned + /// If the body is a coroutine body, this has slightly different semantics; it instead causes a + /// `CoroutineState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned /// to the return place. Return, @@ -709,14 +709,14 @@ pub enum TerminatorKind<'tcx> { /// Marks a suspend point. /// - /// Like `Return` terminators in generator bodies, this computes `value` and then a - /// `GeneratorState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to + /// Like `Return` terminators in coroutine bodies, this computes `value` and then a + /// `CoroutineState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to /// the return place of the function calling this one, and execution continues in the calling /// function. When next invoked with the same first argument, execution of this function /// continues at the `resume` basic block, with the second argument written to the `resume_arg` - /// place. If the generator is dropped before then, the `drop` basic block is invoked. + /// place. If the coroutine is dropped before then, the `drop` basic block is invoked. /// - /// Not permitted in bodies that are not generator bodies, or after generator lowering. + /// Not permitted in bodies that are not coroutine bodies, or after coroutine lowering. /// /// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`? Yield { @@ -726,21 +726,21 @@ pub enum TerminatorKind<'tcx> { resume: BasicBlock, /// The place to store the resume argument in. resume_arg: Place<'tcx>, - /// Cleanup to be done if the generator is dropped at this suspend point. + /// Cleanup to be done if the coroutine is dropped at this suspend point. drop: Option, }, - /// Indicates the end of dropping a generator. + /// Indicates the end of dropping a coroutine. /// - /// Semantically just a `return` (from the generators drop glue). Only permitted in the same situations + /// Semantically just a `return` (from the coroutines drop glue). Only permitted in the same situations /// as `yield`. /// - /// **Needs clarification**: Is that even correct? The generator drop code is always confusing + /// **Needs clarification**: Is that even correct? The coroutine drop code is always confusing /// to me, because it's not even really in the current body. /// /// **Needs clarification**: Are there type system constraints on these terminators? Should /// there be a "block type" like `cleanup` blocks for them? - GeneratorDrop, + CoroutineDrop, /// A block where control flow only ever takes one real path, but borrowck needs to be more /// conservative. @@ -815,7 +815,7 @@ impl TerminatorKind<'_> { TerminatorKind::Call { .. } => "Call", TerminatorKind::Assert { .. } => "Assert", TerminatorKind::Yield { .. } => "Yield", - TerminatorKind::GeneratorDrop => "GeneratorDrop", + TerminatorKind::CoroutineDrop => "CoroutineDrop", TerminatorKind::FalseEdge { .. } => "FalseEdge", TerminatorKind::FalseUnwind { .. } => "FalseUnwind", TerminatorKind::InlineAsm { .. } => "InlineAsm", @@ -883,8 +883,8 @@ pub enum AssertKind { OverflowNeg(O), DivisionByZero(O), RemainderByZero(O), - ResumedAfterReturn(GeneratorKind), - ResumedAfterPanic(GeneratorKind), + ResumedAfterReturn(CoroutineKind), + ResumedAfterPanic(CoroutineKind), MisalignedPointerDereference { required: O, found: O }, } @@ -961,8 +961,8 @@ pub type AssertMessage<'tcx> = AssertKind>; /// was unsized and so had metadata associated with it, then the metadata is retained if the /// field is unsized and thrown out if it is sized. /// -/// These projections are only legal for tuples, ADTs, closures, and generators. If the ADT or -/// generator has more than one variant, the parent place's variant index must be set, indicating +/// These projections are only legal for tuples, ADTs, closures, and coroutines. If the ADT or +/// coroutine has more than one variant, the parent place's variant index must be set, indicating /// which variant is being used. If it has just one variant, the variant index may or may not be /// included - the single possible variant is inferred if it is not included. /// - [`OpaqueCast`](ProjectionElem::OpaqueCast): This projection changes the place's type to the @@ -1068,7 +1068,7 @@ pub enum ProjectionElem { from_end: bool, }, - /// "Downcast" to a variant of an enum or a generator. + /// "Downcast" to a variant of an enum or a coroutine. /// /// The included Symbol is the name of the variant, used for printing MIR. Downcast(Option, VariantIdx), @@ -1278,8 +1278,8 @@ pub enum Rvalue<'tcx> { /// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo` /// has a destructor. /// - /// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After - /// generator lowering, `Generator` aggregate kinds are disallowed too. + /// Disallowed after deaggregation for all aggregate kinds except `Array` and `Coroutine`. After + /// coroutine lowering, `Coroutine` aggregate kinds are disallowed too. Aggregate(Box>, IndexVec>), /// Transmutes a `*mut u8` into shallow-initialized `Box`. @@ -1344,7 +1344,7 @@ pub enum AggregateKind<'tcx> { Adt(DefId, VariantIdx, GenericArgsRef<'tcx>, Option, Option), Closure(DefId, GenericArgsRef<'tcx>), - Generator(DefId, GenericArgsRef<'tcx>, hir::Movability), + Coroutine(DefId, GenericArgsRef<'tcx>, hir::Movability), } #[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 44ae75e2de701..931ee7fd05ef7 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -11,7 +11,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx}; #[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)] pub struct PlaceTy<'tcx> { pub ty: Ty<'tcx>, - /// Downcast to a particular variant of an enum or a generator, if included. + /// Downcast to a particular variant of an enum or a coroutine, if included. pub variant_index: Option, } @@ -205,8 +205,8 @@ impl<'tcx> Rvalue<'tcx> { } AggregateKind::Adt(did, _, args, _, _) => tcx.type_of(did).instantiate(tcx, args), AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args), - AggregateKind::Generator(did, args, movability) => { - Ty::new_generator(tcx, did, args, movability) + AggregateKind::Coroutine(did, args, movability) => { + Ty::new_coroutine(tcx, did, args, movability) } }, Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty), diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index 02aab4a892d05..e3d346c0698d8 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -139,10 +139,10 @@ impl AssertKind { Overflow(op, _, _) => bug!("{:?} cannot overflow", op), DivisionByZero(_) => "attempt to divide by zero", RemainderByZero(_) => "attempt to calculate the remainder with a divisor of zero", - ResumedAfterReturn(GeneratorKind::Gen) => "generator resumed after completion", - ResumedAfterReturn(GeneratorKind::Async(_)) => "`async fn` resumed after completion", - ResumedAfterPanic(GeneratorKind::Gen) => "generator resumed after panicking", - ResumedAfterPanic(GeneratorKind::Async(_)) => "`async fn` resumed after panicking", + ResumedAfterReturn(CoroutineKind::Coroutine) => "coroutine resumed after completion", + ResumedAfterReturn(CoroutineKind::Async(_)) => "`async fn` resumed after completion", + ResumedAfterPanic(CoroutineKind::Coroutine) => "coroutine resumed after panicking", + ResumedAfterPanic(CoroutineKind::Async(_)) => "`async fn` resumed after panicking", BoundsCheck { .. } | MisalignedPointerDereference { .. } => { bug!("Unexpected AssertKind") } @@ -228,10 +228,14 @@ impl AssertKind { OverflowNeg(_) => middle_assert_overflow_neg, DivisionByZero(_) => middle_assert_divide_by_zero, RemainderByZero(_) => middle_assert_remainder_by_zero, - ResumedAfterReturn(GeneratorKind::Async(_)) => middle_assert_async_resume_after_return, - ResumedAfterReturn(GeneratorKind::Gen) => middle_assert_generator_resume_after_return, - ResumedAfterPanic(GeneratorKind::Async(_)) => middle_assert_async_resume_after_panic, - ResumedAfterPanic(GeneratorKind::Gen) => middle_assert_generator_resume_after_panic, + ResumedAfterReturn(CoroutineKind::Async(_)) => middle_assert_async_resume_after_return, + ResumedAfterReturn(CoroutineKind::Coroutine) => { + middle_assert_coroutine_resume_after_return + } + ResumedAfterPanic(CoroutineKind::Async(_)) => middle_assert_async_resume_after_panic, + ResumedAfterPanic(CoroutineKind::Coroutine) => { + middle_assert_coroutine_resume_after_panic + } MisalignedPointerDereference { .. } => middle_assert_misaligned_ptr_deref, } @@ -331,7 +335,7 @@ impl<'tcx> TerminatorKind<'tcx> { } UnwindResume | UnwindTerminate(_) - | GeneratorDrop + | CoroutineDrop | Return | Unreachable | Call { target: None, unwind: _, .. } @@ -373,7 +377,7 @@ impl<'tcx> TerminatorKind<'tcx> { } UnwindResume | UnwindTerminate(_) - | GeneratorDrop + | CoroutineDrop | Return | Unreachable | Call { target: None, unwind: _, .. } @@ -392,7 +396,7 @@ impl<'tcx> TerminatorKind<'tcx> { | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::FalseEdge { .. } => None, @@ -411,7 +415,7 @@ impl<'tcx> TerminatorKind<'tcx> { | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::FalseEdge { .. } => None, @@ -493,7 +497,7 @@ impl<'tcx> TerminatorKind<'tcx> { pub fn edges(&self) -> TerminatorEdges<'_, 'tcx> { use TerminatorKind::*; match *self { - Return | UnwindResume | UnwindTerminate(_) | GeneratorDrop | Unreachable => { + Return | UnwindResume | UnwindTerminate(_) | CoroutineDrop | Unreachable => { TerminatorEdges::None } diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 8d427fdb6f519..d5c81b6cd7930 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -19,8 +19,8 @@ TrivialTypeTraversalImpls! { hir::Movability, BasicBlock, SwitchTargets, - GeneratorKind, - GeneratorSavedLocal, + CoroutineKind, + CoroutineSavedLocal, } TrivialTypeTraversalImpls! { diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 95c1848bc9bae..0f0ca3a1420e9 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -473,7 +473,7 @@ macro_rules! make_mir_visitor { TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume | TerminatorKind::UnwindTerminate(_) | - TerminatorKind::GeneratorDrop | + TerminatorKind::CoroutineDrop | TerminatorKind::Unreachable | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {} @@ -735,12 +735,12 @@ macro_rules! make_mir_visitor { ) => { self.visit_args(closure_args, location); } - AggregateKind::Generator( + AggregateKind::Coroutine( _, - generator_args, + coroutine_args, _movability, ) => { - self.visit_args(generator_args, location); + self.visit_args(coroutine_args, location); } } @@ -992,7 +992,7 @@ macro_rules! extra_body_methods { macro_rules! super_body { ($self:ident, $body:ident, $($mutability:ident, $invalidate:tt)?) => { let span = $body.span; - if let Some(gen) = &$($mutability)? $body.generator { + if let Some(gen) = &$($mutability)? $body.coroutine { if let Some(yield_ty) = $(& $mutability)? gen.yield_ty { $self.visit_ty( yield_ty, diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 8ba3764bcc317..e20e9d9312c1b 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -210,7 +210,7 @@ trivial! { Option, Option, Option, - Option, + Option, Option, Option, Option, @@ -239,7 +239,7 @@ trivial! { rustc_hir::def::DefKind, rustc_hir::Defaultness, rustc_hir::definitions::DefKey, - rustc_hir::GeneratorKind, + rustc_hir::CoroutineKind, rustc_hir::HirId, rustc_hir::IsAsync, rustc_hir::ItemLocalId, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index afe94d1075219..b5f873c9257f0 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -541,28 +541,28 @@ rustc_queries! { } } - /// Returns names of captured upvars for closures and generators. + /// Returns names of captured upvars for closures and coroutines. /// /// Here are some examples: /// - `name__field1__field2` when the upvar is captured by value. /// - `_ref__name__field` when the upvar is captured by reference. /// - /// For generators this only contains upvars that are shared by all states. + /// For coroutines this only contains upvars that are shared by all states. query closure_saved_names_of_captured_variables(def_id: DefId) -> &'tcx IndexVec { arena_cache desc { |tcx| "computing debuginfo for closure `{}`", tcx.def_path_str(def_id) } separate_provide_extern } - query mir_generator_witnesses(key: DefId) -> &'tcx Option> { + query mir_coroutine_witnesses(key: DefId) -> &'tcx Option> { arena_cache - desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) } + desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) } cache_on_disk_if { key.is_local() } separate_provide_extern } - query check_generator_obligations(key: LocalDefId) { - desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key) } + query check_coroutine_obligations(key: LocalDefId) { + desc { |tcx| "verify auto trait bounds for coroutine interior type `{}`", tcx.def_path_str(key) } } /// MIR after our optimization passes have run. This is MIR that is ready @@ -743,9 +743,9 @@ rustc_queries! { desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) } } - /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator. - query generator_kind(def_id: DefId) -> Option { - desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) } + /// Returns `Some(coroutine_kind)` if the node pointed to by `def_id` is a coroutine. + query coroutine_kind(def_id: DefId) -> Option { + desc { |tcx| "looking up coroutine kind of `{}`", tcx.def_path_str(def_id) } separate_provide_extern } diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 67804998a3293..20e3349073d44 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -382,9 +382,9 @@ pub enum ExprKind<'tcx> { VarRef { id: LocalVarId, }, - /// Used to represent upvars mentioned in a closure/generator + /// Used to represent upvars mentioned in a closure/coroutine UpvarRef { - /// DefId of the closure/generator + /// DefId of the closure/coroutine closure_def_id: DefId, /// HirId of the root variable diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 99b750c9afc8c..9397e98343e31 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -301,8 +301,8 @@ pub enum ObligationCauseCode<'tcx> { InlineAsmSized, /// Captured closure type must be `Sized`. SizedClosureCapture(LocalDefId), - /// Types live across generator yields must be `Sized`. - SizedGeneratorInterior(LocalDefId), + /// Types live across coroutine yields must be `Sized`. + SizedCoroutineInterior(LocalDefId), /// `[expr; N]` requires `type_of(expr): Copy`. RepeatElementCopy { /// If element is a `const fn` we display a help message suggesting to move the diff --git a/compiler/rustc_middle/src/traits/select.rs b/compiler/rustc_middle/src/traits/select.rs index 90bc5dd8f6962..bc6856bc9009e 100644 --- a/compiler/rustc_middle/src/traits/select.rs +++ b/compiler/rustc_middle/src/traits/select.rs @@ -136,11 +136,11 @@ pub enum SelectionCandidate<'tcx> { is_const: bool, }, - /// Implementation of a `Generator` trait by one of the anonymous types - /// generated for a generator. - GeneratorCandidate, + /// Implementation of a `Coroutine` trait by one of the anonymous types + /// generated for a coroutine. + CoroutineCandidate, - /// Implementation of a `Future` trait by one of the generator types + /// Implementation of a `Future` trait by one of the coroutine types /// generated for an async construct. FutureCandidate, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index cad3aac23d87a..561699d317088 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -65,7 +65,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{FieldIdx, Layout, LayoutS, TargetDataLayout, VariantIdx}; use rustc_target::spec::abi; -use rustc_type_ir::sty::TyKind::*; +use rustc_type_ir::TyKind::*; use rustc_type_ir::WithCachedTypeInfo; use rustc_type_ir::{CollectAndApply, Interner, TypeFlags}; @@ -761,9 +761,9 @@ impl<'tcx> TyCtxt<'tcx> { self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did) } - /// Returns `true` if the node pointed to by `def_id` is a generator for an async construct. - pub fn generator_is_async(self, def_id: DefId) -> bool { - matches!(self.generator_kind(def_id), Some(hir::GeneratorKind::Async(_))) + /// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct. + pub fn coroutine_is_async(self, def_id: DefId) -> bool { + matches!(self.coroutine_kind(def_id), Some(hir::CoroutineKind::Async(_))) } pub fn stability(self) -> &'tcx stability::Index { @@ -951,7 +951,7 @@ impl<'tcx> TyCtxt<'tcx> { self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE); let definitions = &self.untracked.definitions; - std::iter::from_generator(|| { + std::iter::from_coroutine(|| { let mut i = 0; // Recompute the number of definitions each time, because our caller may be creating @@ -1382,8 +1382,8 @@ impl<'tcx> TyCtxt<'tcx> { FnDef, FnPtr, Placeholder, - Generator, - GeneratorWitness, + Coroutine, + CoroutineWitness, Dynamic, Closure, Tuple, diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 49014c60a6de0..7a782b2c24985 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -17,7 +17,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{PredicateOrigin, WherePredicate}; use rustc_span::{BytePos, Span}; -use rustc_type_ir::sty::TyKind::*; +use rustc_type_ir::TyKind::*; impl<'tcx> IntoDiagnosticArg for Ty<'tcx> { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { @@ -482,8 +482,8 @@ impl<'tcx> TypeVisitor> for IsSuggestableVisitor<'tcx> { FnDef(..) | Closure(..) | Infer(..) - | Generator(..) - | GeneratorWitness(..) + | Coroutine(..) + | CoroutineWitness(..) | Bound(_, _) | Placeholder(_) | Error(_) => { @@ -567,8 +567,8 @@ impl<'tcx> FallibleTypeFolder> for MakeSuggestableFolder<'tcx> { // FIXME(compiler-errors): We could replace these with infer, I guess. Closure(..) | Infer(..) - | Generator(..) - | GeneratorWitness(..) + | Coroutine(..) + | CoroutineWitness(..) | Bound(_, _) | Placeholder(_) | Error(_) => { diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 0fe1284eed991..8b4375f0270b5 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -241,8 +241,8 @@ impl<'tcx> Ty<'tcx> { } ty::Dynamic(..) => "trait object".into(), ty::Closure(..) => "closure".into(), - ty::Generator(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(), - ty::GeneratorWitness(..) => "generator witness".into(), + ty::Coroutine(def_id, ..) => tcx.coroutine_kind(def_id).unwrap().descr().into(), + ty::CoroutineWitness(..) => "coroutine witness".into(), ty::Infer(ty::TyVar(_)) => "inferred type".into(), ty::Infer(ty::IntVar(_)) => "integer".into(), ty::Infer(ty::FloatVar(_)) => "floating-point number".into(), @@ -299,8 +299,8 @@ impl<'tcx> Ty<'tcx> { ty::FnPtr(_) => "fn pointer".into(), ty::Dynamic(..) => "trait object".into(), ty::Closure(..) => "closure".into(), - ty::Generator(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(), - ty::GeneratorWitness(..) => "generator witness".into(), + ty::Coroutine(def_id, ..) => tcx.coroutine_kind(def_id).unwrap().descr().into(), + ty::CoroutineWitness(..) => "coroutine witness".into(), ty::Tuple(..) => "tuple".into(), ty::Placeholder(..) => "higher-ranked type".into(), ty::Bound(..) => "bound type variable".into(), diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 16935d5b38042..75ea53195a3ac 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -28,8 +28,8 @@ pub enum SimplifiedType { MarkerTraitObject, Trait(DefId), Closure(DefId), - Generator(DefId), - GeneratorWitness(DefId), + Coroutine(DefId), + CoroutineWitness(DefId), Function(usize), Placeholder, } @@ -128,8 +128,8 @@ pub fn simplify_type<'tcx>( }, ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)), ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id)), - ty::Generator(def_id, _, _) => Some(SimplifiedType::Generator(def_id)), - ty::GeneratorWitness(def_id, _) => Some(SimplifiedType::GeneratorWitness(def_id)), + ty::Coroutine(def_id, _, _) => Some(SimplifiedType::Coroutine(def_id)), + ty::CoroutineWitness(def_id, _) => Some(SimplifiedType::CoroutineWitness(def_id)), ty::Never => Some(SimplifiedType::Never), ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())), ty::FnPtr(f) => Some(SimplifiedType::Function(f.skip_binder().inputs().len())), @@ -164,8 +164,8 @@ impl SimplifiedType { | SimplifiedType::Foreign(d) | SimplifiedType::Trait(d) | SimplifiedType::Closure(d) - | SimplifiedType::Generator(d) - | SimplifiedType::GeneratorWitness(d) => Some(d), + | SimplifiedType::Coroutine(d) + | SimplifiedType::CoroutineWitness(d) => Some(d), _ => None, } } @@ -234,8 +234,8 @@ impl DeepRejectCtxt { | ty::Foreign(..) => {} ty::FnDef(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => bug!("unexpected impl_ty: {impl_ty}"), @@ -310,7 +310,7 @@ impl DeepRejectCtxt { }, // Impls cannot contain these types as these cannot be named directly. - ty::FnDef(..) | ty::Closure(..) | ty::Generator(..) => false, + ty::FnDef(..) | ty::Closure(..) | ty::Coroutine(..) => false, // Placeholder types don't unify with anything on their own ty::Placeholder(..) | ty::Bound(..) => false, @@ -337,7 +337,7 @@ impl DeepRejectCtxt { ty::Error(_) => true, - ty::GeneratorWitness(..) => { + ty::CoroutineWitness(..) => { bug!("unexpected obligation type: {:?}", obligation_ty) } } diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 7ed31fbbfd885..d75315b7ac955 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -111,8 +111,8 @@ impl FlagComputation { self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } - ty::Generator(_, args, _) => { - let args = args.as_generator(); + ty::Coroutine(_, args, _) => { + let args = args.as_coroutine(); let should_remove_further_specializable = !self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE); self.add_args(args.parent_args()); @@ -127,7 +127,7 @@ impl FlagComputation { self.add_ty(args.tupled_upvars_ty()); } - ty::GeneratorWitness(_, args) => { + ty::CoroutineWitness(_, args) => { let should_remove_further_specializable = !self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE); self.add_args(args); diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index a861af4785945..41a1bf04e5f3f 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -2,7 +2,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; -use crate::ty::sty::{ClosureArgs, GeneratorArgs, InlineConstArgs}; +use crate::ty::sty::{ClosureArgs, CoroutineArgs, InlineConstArgs}; use crate::ty::visit::{TypeVisitable, TypeVisitableExt, TypeVisitor}; use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt}; @@ -266,12 +266,12 @@ impl<'tcx> GenericArgs<'tcx> { ClosureArgs { args: self } } - /// Interpret these generic args as the args of a generator type. - /// Generator args have a particular structure controlled by the - /// compiler that encodes information like the signature and generator kind; - /// see `ty::GeneratorArgs` struct for more comments. - pub fn as_generator(&'tcx self) -> GeneratorArgs<'tcx> { - GeneratorArgs { args: self } + /// Interpret these generic args as the args of a coroutine type. + /// Coroutine args have a particular structure controlled by the + /// compiler that encodes information like the signature and coroutine kind; + /// see `ty::CoroutineArgs` struct for more comments. + pub fn as_coroutine(&'tcx self) -> CoroutineArgs<'tcx> { + CoroutineArgs { args: self } } /// Interpret these generic args as the args of an inline const. diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 4dac6891b3062..68ac54e899ac3 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -47,7 +47,7 @@ use crate::query::Providers; use crate::ty::context::TyCtxt; use crate::ty::{self, DefId, Ty, VariantDef, Visibility}; -use rustc_type_ir::sty::TyKind::*; +use rustc_type_ir::TyKind::*; pub mod inhabited_predicate; diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 0b308d5dec14f..a7d6e97c941f9 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -36,7 +36,7 @@ pub enum InstanceDef<'tcx> { /// This includes: /// - `fn` items /// - closures - /// - generators + /// - coroutines Item(DefId), /// An intrinsic `fn` item (with `"rust-intrinsic"` or `"platform-intrinsic"` ABI). @@ -653,15 +653,15 @@ fn polymorphize<'tcx>( let unused = tcx.unused_generic_params(instance); debug!("polymorphize: unused={:?}", unused); - // If this is a closure or generator then we need to handle the case where another closure + // If this is a closure or coroutine then we need to handle the case where another closure // from the function is captured as an upvar and hasn't been polymorphized. In this case, // the unpolymorphized upvar closure would result in a polymorphized closure producing // multiple mono items (and eventually symbol clashes). let def_id = instance.def_id(); let upvars_ty = if tcx.is_closure(def_id) { Some(args.as_closure().tupled_upvars_ty()) - } else if tcx.type_of(def_id).skip_binder().is_generator() { - Some(args.as_generator().tupled_upvars_ty()) + } else if tcx.type_of(def_id).skip_binder().is_coroutine() { + Some(args.as_coroutine().tupled_upvars_ty()) } else { None }; @@ -689,13 +689,13 @@ fn polymorphize<'tcx>( Ty::new_closure(self.tcx, def_id, polymorphized_args) } } - ty::Generator(def_id, args, movability) => { + ty::Coroutine(def_id, args, movability) => { let polymorphized_args = polymorphize(self.tcx, ty::InstanceDef::Item(def_id), args); if args == polymorphized_args { ty } else { - Ty::new_generator(self.tcx, def_id, polymorphized_args, movability) + Ty::new_coroutine(self.tcx, def_id, polymorphized_args, movability) } } _ => ty.super_fold_with(self), @@ -715,7 +715,7 @@ fn polymorphize<'tcx>( upvars_ty == Some(args[param.index as usize].expect_ty()) => { // ..then double-check that polymorphization marked it used.. debug_assert!(!is_unused); - // ..and polymorphize any closures/generators captured as upvars. + // ..and polymorphize any closures/coroutines captured as upvars. let upvars_ty = upvars_ty.unwrap(); let polymorphized_upvars_ty = upvars_ty.fold_with( &mut PolymorphizationFolder { tcx }); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 5ef7ee5263641..4223e503f5e22 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -809,7 +809,7 @@ where | ty::FnPtr(_) | ty::Never | ty::FnDef(..) - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::Foreign(..) | ty::Dynamic(_, _, ty::Dyn) => { bug!("TyAndLayout::field({:?}): not applicable", this) @@ -898,16 +898,16 @@ where ty::Array(element, _) | ty::Slice(element) => TyMaybeWithLayout::Ty(element), ty::Str => TyMaybeWithLayout::Ty(tcx.types.u8), - // Tuples, generators and closures. + // Tuples, coroutines and closures. ty::Closure(_, ref args) => field_ty_or_layout( TyAndLayout { ty: args.as_closure().tupled_upvars_ty(), ..this }, cx, i, ), - ty::Generator(def_id, ref args, _) => match this.variants { + ty::Coroutine(def_id, ref args, _) => match this.variants { Variants::Single { index } => TyMaybeWithLayout::Ty( - args.as_generator() + args.as_coroutine() .state_tys(def_id, tcx) .nth(index.as_usize()) .unwrap() @@ -918,7 +918,7 @@ where if i == tag_field { return TyMaybeWithLayout::TyAndLayout(tag_layout(tag)); } - TyMaybeWithLayout::Ty(args.as_generator().prefix_tys()[i]) + TyMaybeWithLayout::Ty(args.as_coroutine().prefix_tys()[i]) } }, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index e6cd3dd4d82d7..9b0ceb23e3eab 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -20,7 +20,7 @@ pub use self::Variance::*; use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason}; use crate::metadata::ModChild; use crate::middle::privacy::EffectiveVisibilities; -use crate::mir::{Body, GeneratorLayout}; +use crate::mir::{Body, CoroutineLayout}; use crate::query::Providers; use crate::traits::{self, Reveal}; use crate::ty; @@ -98,8 +98,8 @@ pub use self::sty::BoundRegionKind::*; pub use self::sty::{ AliasTy, Article, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind, CanonicalPolyFnSig, ClosureArgs, ClosureArgsParts, ConstKind, ConstVid, - EarlyBoundRegion, EffectVid, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, - FnSig, FreeRegion, GenSig, GeneratorArgs, GeneratorArgsParts, InlineConstArgs, + CoroutineArgs, CoroutineArgsParts, EarlyBoundRegion, EffectVid, ExistentialPredicate, + ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig, InlineConstArgs, InlineConstArgsParts, ParamConst, ParamTy, PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarArgs, VarianceDiagInfo, @@ -2421,10 +2421,10 @@ impl<'tcx> TyCtxt<'tcx> { self.def_kind(trait_def_id) == DefKind::TraitAlias } - /// Returns layout of a generator. Layout might be unavailable if the - /// generator is tainted by errors. - pub fn generator_layout(self, def_id: DefId) -> Option<&'tcx GeneratorLayout<'tcx>> { - self.optimized_mir(def_id).generator_layout() + /// Returns layout of a coroutine. Layout might be unavailable if the + /// coroutine is tainted by errors. + pub fn coroutine_layout(self, def_id: DefId) -> Option<&'tcx CoroutineLayout<'tcx>> { + self.optimized_mir(def_id).coroutine_layout() } /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements. diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 6491936c21921..8d895732dff20 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -152,14 +152,14 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { Ty::new_closure(self.tcx, def_id, args) } - ty::Generator(def_id, args, movability) => { + ty::Coroutine(def_id, args, movability) => { let args = self.fold_closure_args(def_id, args); - Ty::new_generator(self.tcx, def_id, args, movability) + Ty::new_coroutine(self.tcx, def_id, args, movability) } - ty::GeneratorWitness(def_id, args) => { + ty::CoroutineWitness(def_id, args) => { let args = self.fold_closure_args(def_id, args); - Ty::new_generator_witness(self.tcx, def_id, args) + Ty::new_coroutine_witness(self.tcx, def_id, args) } ty::Param(param) => { diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs index 9aa673e4418c6..9afa50cf584c3 100644 --- a/compiler/rustc_middle/src/ty/parameterized.rs +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -82,7 +82,7 @@ trivially_parameterized_over_tcx! { rustc_attr::Stability, rustc_hir::Constness, rustc_hir::Defaultness, - rustc_hir::GeneratorKind, + rustc_hir::CoroutineKind, rustc_hir::IsAsync, rustc_hir::LangItem, rustc_hir::def::DefKind, @@ -123,7 +123,7 @@ macro_rules! parameterized_over_tcx { parameterized_over_tcx! { crate::middle::exported_symbols::ExportedSymbol, crate::mir::Body, - crate::mir::GeneratorLayout, + crate::mir::CoroutineLayout, ty::Ty, ty::FnSig, ty::GenericPredicates, diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 107b44285ac0e..164e4232e4c61 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -261,8 +261,8 @@ fn characteristic_def_id_of_type_cached<'a>( ty::FnDef(def_id, _) | ty::Closure(def_id, _) - | ty::Generator(def_id, _, _) - | ty::GeneratorWitness(def_id, _) + | ty::Coroutine(def_id, _, _) + | ty::CoroutineWitness(def_id, _) | ty::Foreign(def_id) => Some(def_id), ty::Bool diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 117aa69596c80..38b3096f85182 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -784,11 +784,11 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } } ty::Str => p!("str"), - ty::Generator(did, args, movability) => { + ty::Coroutine(did, args, movability) => { p!(write("{{")); - let generator_kind = self.tcx().generator_kind(did).unwrap(); + let coroutine_kind = self.tcx().coroutine_kind(did).unwrap(); let should_print_movability = - self.should_print_verbose() || generator_kind == hir::GeneratorKind::Gen; + self.should_print_verbose() || coroutine_kind == hir::CoroutineKind::Coroutine; if should_print_movability { match movability { @@ -798,7 +798,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } if !self.should_print_verbose() { - p!(write("{}", generator_kind)); + p!(write("{}", coroutine_kind)); // FIXME(eddyb) should use `def_span`. if let Some(did) = did.as_local() { let span = self.tcx().def_span(did); @@ -814,24 +814,24 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } else { p!(print_def_path(did, args)); p!(" upvar_tys=("); - if !args.as_generator().is_valid() { + if !args.as_coroutine().is_valid() { p!("unavailable"); } else { - self = self.comma_sep(args.as_generator().upvar_tys().iter())?; + self = self.comma_sep(args.as_coroutine().upvar_tys().iter())?; } p!(")"); - if args.as_generator().is_valid() { - p!(" ", print(args.as_generator().witness())); + if args.as_coroutine().is_valid() { + p!(" ", print(args.as_coroutine().witness())); } } p!("}}") } - ty::GeneratorWitness(did, args) => { + ty::CoroutineWitness(did, args) => { p!(write("{{")); if !self.tcx().sess.verbose() { - p!("generator witness"); + p!("coroutine witness"); // FIXME(eddyb) should use `def_span`. if let Some(did) = did.as_local() { let span = self.tcx().def_span(did); @@ -1048,16 +1048,16 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } for (assoc_item_def_id, term) in assoc_items { - // Skip printing `<{generator@} as Generator<_>>::Return` from async blocks, - // unless we can find out what generator return type it comes from. + // Skip printing `<{coroutine@} as Coroutine<_>>::Return` from async blocks, + // unless we can find out what coroutine return type it comes from. let term = if let Some(ty) = term.skip_binder().ty() && let ty::Alias(ty::Projection, proj) = ty.kind() && let Some(assoc) = tcx.opt_associated_item(proj.def_id) && assoc.trait_container(tcx) == tcx.lang_items().gen_trait() && assoc.name == rustc_span::sym::Return { - if let ty::Generator(_, args, _) = args.type_at(0).kind() { - let return_ty = args.as_generator().return_ty(); + if let ty::Coroutine(_, args, _) = args.type_at(0).kind() { + let return_ty = args.as_coroutine().return_ty(); if !return_ty.is_ty_var() { return_ty.into() } else { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index fdfdd6cc8d6d9..27e9be37fbfff 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -352,19 +352,19 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> { } #[derive(PartialEq, Copy, Debug, Clone, TypeFoldable, TypeVisitable)] -struct GeneratorWitness<'tcx>(&'tcx ty::List>); +struct CoroutineWitness<'tcx>(&'tcx ty::List>); -impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> { +impl<'tcx> Relate<'tcx> for CoroutineWitness<'tcx> { fn relate>( relation: &mut R, - a: GeneratorWitness<'tcx>, - b: GeneratorWitness<'tcx>, - ) -> RelateResult<'tcx, GeneratorWitness<'tcx>> { + a: CoroutineWitness<'tcx>, + b: CoroutineWitness<'tcx>, + ) -> RelateResult<'tcx, CoroutineWitness<'tcx>> { assert_eq!(a.0.len(), b.0.len()); let tcx = relation.tcx(); let types = tcx.mk_type_list_from_iter(iter::zip(a.0, b.0).map(|(a, b)| relation.relate(a, b)))?; - Ok(GeneratorWitness(types)) + Ok(CoroutineWitness(types)) } } @@ -457,24 +457,24 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( Ok(Ty::new_dynamic(tcx, relation.relate(a_obj, b_obj)?, region_bound, a_repr)) } - (&ty::Generator(a_id, a_args, movability), &ty::Generator(b_id, b_args, _)) + (&ty::Coroutine(a_id, a_args, movability), &ty::Coroutine(b_id, b_args, _)) if a_id == b_id => { - // All Generator types with the same id represent - // the (anonymous) type of the same generator expression. So + // All Coroutine types with the same id represent + // the (anonymous) type of the same coroutine expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(Ty::new_generator(tcx, a_id, args, movability)) + Ok(Ty::new_coroutine(tcx, a_id, args, movability)) } - (&ty::GeneratorWitness(a_id, a_args), &ty::GeneratorWitness(b_id, b_args)) + (&ty::CoroutineWitness(a_id, a_args), &ty::CoroutineWitness(b_id, b_args)) if a_id == b_id => { - // All GeneratorWitness types with the same id represent - // the (anonymous) type of the same generator expression. So + // All CoroutineWitness types with the same id represent + // the (anonymous) type of the same coroutine expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(Ty::new_generator_witness(tcx, a_id, args)) + Ok(Ty::new_coroutine_witness(tcx, a_id, args)) } (&ty::Closure(a_id, a_args), &ty::Closure(b_id, b_args)) if a_id == b_id => { @@ -710,14 +710,14 @@ impl<'tcx> Relate<'tcx> for ty::ClosureArgs<'tcx> { } } -impl<'tcx> Relate<'tcx> for ty::GeneratorArgs<'tcx> { +impl<'tcx> Relate<'tcx> for ty::CoroutineArgs<'tcx> { fn relate>( relation: &mut R, - a: ty::GeneratorArgs<'tcx>, - b: ty::GeneratorArgs<'tcx>, - ) -> RelateResult<'tcx, ty::GeneratorArgs<'tcx>> { + a: ty::CoroutineArgs<'tcx>, + b: ty::CoroutineArgs<'tcx>, + ) -> RelateResult<'tcx, ty::CoroutineArgs<'tcx>> { let args = relate_args_invariantly(relation, a.args, b.args)?; - Ok(ty::GeneratorArgs { args }) + Ok(ty::CoroutineArgs { args }) } } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 2adbe9e030997..012bb74941286 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -654,11 +654,11 @@ impl<'tcx> TypeSuperFoldable> for Ty<'tcx> { ty::Ref(r, ty, mutbl) => { ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl) } - ty::Generator(did, args, movability) => { - ty::Generator(did, args.try_fold_with(folder)?, movability) + ty::Coroutine(did, args, movability) => { + ty::Coroutine(did, args.try_fold_with(folder)?, movability) } - ty::GeneratorWitness(did, args) => { - ty::GeneratorWitness(did, args.try_fold_with(folder)?) + ty::CoroutineWitness(did, args) => { + ty::CoroutineWitness(did, args.try_fold_with(folder)?) } ty::Closure(did, args) => ty::Closure(did, args.try_fold_with(folder)?), ty::Alias(kind, data) => ty::Alias(kind, data.try_fold_with(folder)?), @@ -706,8 +706,8 @@ impl<'tcx> TypeSuperVisitable> for Ty<'tcx> { r.visit_with(visitor)?; ty.visit_with(visitor) } - ty::Generator(_did, ref args, _) => args.visit_with(visitor), - ty::GeneratorWitness(_did, ref args) => args.visit_with(visitor), + ty::Coroutine(_did, ref args, _) => args.visit_with(visitor), + ty::CoroutineWitness(_did, ref args) => args.visit_with(visitor), ty::Closure(_did, ref args) => args.visit_with(visitor), ty::Alias(_, ref data) => data.visit_with(visitor), diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index fc207a2c350de..46aa5d950cb18 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -33,13 +33,13 @@ use std::marker::PhantomData; use std::ops::{ControlFlow, Deref, Range}; use ty::util::IntTypeExt; -use rustc_type_ir::sty::TyKind::*; use rustc_type_ir::CollectAndApply; use rustc_type_ir::ConstKind as IrConstKind; use rustc_type_ir::DebugWithInfcx; use rustc_type_ir::DynKind; use rustc_type_ir::RegionKind as IrRegionKind; use rustc_type_ir::TyKind as IrTyKind; +use rustc_type_ir::TyKind::*; use super::GenericParamDefKind; @@ -215,20 +215,20 @@ impl<'tcx> Article for TyKind<'tcx> { /// closure C (which would then require fixed point iteration to /// handle). Plus it fixes an ICE. :P /// -/// ## Generators +/// ## Coroutines /// -/// Generators are handled similarly in `GeneratorArgs`. The set of +/// Coroutines are handled similarly in `CoroutineArgs`. The set of /// type parameters is similar, but `CK` and `CS` are replaced by the /// following type parameters: /// -/// * `GS`: The generator's "resume type", which is the type of the +/// * `GS`: The coroutine's "resume type", which is the type of the /// argument passed to `resume`, and the type of `yield` expressions -/// inside the generator. +/// inside the coroutine. /// * `GY`: The "yield type", which is the type of values passed to -/// `yield` inside the generator. +/// `yield` inside the coroutine. /// * `GR`: The "return type", which is the type of value returned upon -/// completion of the generator. -/// * `GW`: The "generator witness". +/// completion of the coroutine. +/// * `GW`: The "coroutine witness". #[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable, Lift)] pub struct ClosureArgs<'tcx> { /// Lifetime and type parameters from the enclosing function, @@ -352,11 +352,11 @@ impl<'tcx> ClosureArgs<'tcx> { /// Similar to `ClosureArgs`; see the above documentation for more. #[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)] -pub struct GeneratorArgs<'tcx> { +pub struct CoroutineArgs<'tcx> { pub args: GenericArgsRef<'tcx>, } -pub struct GeneratorArgsParts<'tcx, T> { +pub struct CoroutineArgsParts<'tcx, T> { pub parent_args: &'tcx [GenericArg<'tcx>], pub resume_ty: T, pub yield_ty: T, @@ -365,14 +365,14 @@ pub struct GeneratorArgsParts<'tcx, T> { pub tupled_upvars_ty: T, } -impl<'tcx> GeneratorArgs<'tcx> { - /// Construct `GeneratorArgs` from `GeneratorArgsParts`, containing `Args` - /// for the generator parent, alongside additional generator-specific components. +impl<'tcx> CoroutineArgs<'tcx> { + /// Construct `CoroutineArgs` from `CoroutineArgsParts`, containing `Args` + /// for the coroutine parent, alongside additional coroutine-specific components. pub fn new( tcx: TyCtxt<'tcx>, - parts: GeneratorArgsParts<'tcx, Ty<'tcx>>, - ) -> GeneratorArgs<'tcx> { - GeneratorArgs { + parts: CoroutineArgsParts<'tcx, Ty<'tcx>>, + ) -> CoroutineArgs<'tcx> { + CoroutineArgs { args: tcx.mk_args_from_iter( parts.parent_args.iter().copied().chain( [ @@ -389,12 +389,12 @@ impl<'tcx> GeneratorArgs<'tcx> { } } - /// Divides the generator args into their respective components. - /// The ordering assumed here must match that used by `GeneratorArgs::new` above. - fn split(self) -> GeneratorArgsParts<'tcx, GenericArg<'tcx>> { + /// Divides the coroutine args into their respective components. + /// The ordering assumed here must match that used by `CoroutineArgs::new` above. + fn split(self) -> CoroutineArgsParts<'tcx, GenericArg<'tcx>> { match self.args[..] { [ref parent_args @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => { - GeneratorArgsParts { + CoroutineArgsParts { parent_args, resume_ty, yield_ty, @@ -403,34 +403,34 @@ impl<'tcx> GeneratorArgs<'tcx> { tupled_upvars_ty, } } - _ => bug!("generator args missing synthetics"), + _ => bug!("coroutine args missing synthetics"), } } /// Returns `true` only if enough of the synthetic types are known to - /// allow using all of the methods on `GeneratorArgs` without panicking. + /// allow using all of the methods on `CoroutineArgs` without panicking. /// - /// Used primarily by `ty::print::pretty` to be able to handle generator + /// Used primarily by `ty::print::pretty` to be able to handle coroutine /// types that haven't had their synthetic types substituted in. pub fn is_valid(self) -> bool { self.args.len() >= 5 && matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_)) } - /// Returns the substitutions of the generator's parent. + /// Returns the substitutions of the coroutine's parent. pub fn parent_args(self) -> &'tcx [GenericArg<'tcx>] { self.split().parent_args } - /// This describes the types that can be contained in a generator. + /// This describes the types that can be contained in a coroutine. /// It will be a type variable initially and unified in the last stages of typeck of a body. - /// It contains a tuple of all the types that could end up on a generator frame. + /// It contains a tuple of all the types that could end up on a coroutine frame. /// The state transformation MIR pass may only produce layouts which mention types /// in this tuple. Upvars are not counted here. pub fn witness(self) -> Ty<'tcx> { self.split().witness.expect_ty() } - /// Returns an iterator over the list of types of captured paths by the generator. + /// Returns an iterator over the list of types of captured paths by the coroutine. /// In case there was a type error in figuring out the types of the captured path, an /// empty iterator is returned. #[inline] @@ -443,28 +443,28 @@ impl<'tcx> GeneratorArgs<'tcx> { } } - /// Returns the tuple type representing the upvars for this generator. + /// Returns the tuple type representing the upvars for this coroutine. #[inline] pub fn tupled_upvars_ty(self) -> Ty<'tcx> { self.split().tupled_upvars_ty.expect_ty() } - /// Returns the type representing the resume type of the generator. + /// Returns the type representing the resume type of the coroutine. pub fn resume_ty(self) -> Ty<'tcx> { self.split().resume_ty.expect_ty() } - /// Returns the type representing the yield type of the generator. + /// Returns the type representing the yield type of the coroutine. pub fn yield_ty(self) -> Ty<'tcx> { self.split().yield_ty.expect_ty() } - /// Returns the type representing the return type of the generator. + /// Returns the type representing the return type of the coroutine. pub fn return_ty(self) -> Ty<'tcx> { self.split().return_ty.expect_ty() } - /// Returns the "generator signature", which consists of its yield + /// Returns the "coroutine signature", which consists of its yield /// and return types. /// /// N.B., some bits of the code prefers to see this wrapped in a @@ -474,7 +474,7 @@ impl<'tcx> GeneratorArgs<'tcx> { ty::Binder::dummy(self.sig()) } - /// Returns the "generator signature", which consists of its resume, yield + /// Returns the "coroutine signature", which consists of its resume, yield /// and return types. pub fn sig(self) -> GenSig<'tcx> { ty::GenSig { @@ -485,23 +485,23 @@ impl<'tcx> GeneratorArgs<'tcx> { } } -impl<'tcx> GeneratorArgs<'tcx> { - /// Generator has not been resumed yet. +impl<'tcx> CoroutineArgs<'tcx> { + /// Coroutine has not been resumed yet. pub const UNRESUMED: usize = 0; - /// Generator has returned or is completed. + /// Coroutine has returned or is completed. pub const RETURNED: usize = 1; - /// Generator has been poisoned. + /// Coroutine has been poisoned. pub const POISONED: usize = 2; const UNRESUMED_NAME: &'static str = "Unresumed"; const RETURNED_NAME: &'static str = "Returned"; const POISONED_NAME: &'static str = "Panicked"; - /// The valid variant indices of this generator. + /// The valid variant indices of this coroutine. #[inline] pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range { // FIXME requires optimized MIR - FIRST_VARIANT..tcx.generator_layout(def_id).unwrap().variant_fields.next_index() + FIRST_VARIANT..tcx.coroutine_layout(def_id).unwrap().variant_fields.next_index() } /// The discriminant for the given variant. Panics if the `variant_index` is @@ -513,13 +513,13 @@ impl<'tcx> GeneratorArgs<'tcx> { tcx: TyCtxt<'tcx>, variant_index: VariantIdx, ) -> Discr<'tcx> { - // Generators don't support explicit discriminant values, so they are + // Coroutines don't support explicit discriminant values, so they are // the same as the variant index. assert!(self.variant_range(def_id, tcx).contains(&variant_index)); Discr { val: variant_index.as_usize() as u128, ty: self.discr_ty(tcx) } } - /// The set of all discriminants for the generator, enumerated with their + /// The set of all discriminants for the coroutine, enumerated with their /// variant indices. #[inline] pub fn discriminants( @@ -543,15 +543,15 @@ impl<'tcx> GeneratorArgs<'tcx> { } } - /// The type of the state discriminant used in the generator type. + /// The type of the state discriminant used in the coroutine type. #[inline] pub fn discr_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { tcx.types.u32 } /// This returns the types of the MIR locals which had to be stored across suspension points. - /// It is calculated in rustc_mir_transform::generator::StateTransform. - /// All the types here must be in the tuple in GeneratorInterior. + /// It is calculated in rustc_mir_transform::coroutine::StateTransform. + /// All the types here must be in the tuple in CoroutineInterior. /// /// The locals are grouped by their variant number. Note that some locals may /// be repeated in multiple variants. @@ -561,7 +561,7 @@ impl<'tcx> GeneratorArgs<'tcx> { def_id: DefId, tcx: TyCtxt<'tcx>, ) -> impl Iterator> + Captures<'tcx>> { - let layout = tcx.generator_layout(def_id).unwrap(); + let layout = tcx.coroutine_layout(def_id).unwrap(); layout.variant_fields.iter().map(move |variant| { variant.iter().map(move |field| { ty::EarlyBinder::bind(layout.field_tys[*field].ty).instantiate(tcx, self.args) @@ -569,7 +569,7 @@ impl<'tcx> GeneratorArgs<'tcx> { }) } - /// This is the types of the fields of a generator which are not stored in a + /// This is the types of the fields of a coroutine which are not stored in a /// variant. #[inline] pub fn prefix_tys(self) -> &'tcx List> { @@ -580,18 +580,18 @@ impl<'tcx> GeneratorArgs<'tcx> { #[derive(Debug, Copy, Clone, HashStable)] pub enum UpvarArgs<'tcx> { Closure(GenericArgsRef<'tcx>), - Generator(GenericArgsRef<'tcx>), + Coroutine(GenericArgsRef<'tcx>), } impl<'tcx> UpvarArgs<'tcx> { - /// Returns an iterator over the list of types of captured paths by the closure/generator. + /// Returns an iterator over the list of types of captured paths by the closure/coroutine. /// In case there was a type error in figuring out the types of the captured path, an /// empty iterator is returned. #[inline] pub fn upvar_tys(self) -> &'tcx List> { let tupled_tys = match self { UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(), - UpvarArgs::Generator(args) => args.as_generator().tupled_upvars_ty(), + UpvarArgs::Coroutine(args) => args.as_coroutine().tupled_upvars_ty(), }; match tupled_tys.kind() { @@ -606,7 +606,7 @@ impl<'tcx> UpvarArgs<'tcx> { pub fn tupled_upvars_ty(self) -> Ty<'tcx> { match self { UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(), - UpvarArgs::Generator(args) => args.as_generator().tupled_upvars_ty(), + UpvarArgs::Coroutine(args) => args.as_coroutine().tupled_upvars_ty(), } } } @@ -2165,27 +2165,27 @@ impl<'tcx> Ty<'tcx> { } #[inline] - pub fn new_generator( + pub fn new_coroutine( tcx: TyCtxt<'tcx>, def_id: DefId, - generator_args: GenericArgsRef<'tcx>, + coroutine_args: GenericArgsRef<'tcx>, movability: hir::Movability, ) -> Ty<'tcx> { debug_assert_eq!( - generator_args.len(), + coroutine_args.len(), tcx.generics_of(tcx.typeck_root_def_id(def_id)).count() + 5, - "generator constructed with incorrect number of substitutions" + "coroutine constructed with incorrect number of substitutions" ); - Ty::new(tcx, Generator(def_id, generator_args, movability)) + Ty::new(tcx, Coroutine(def_id, coroutine_args, movability)) } #[inline] - pub fn new_generator_witness( + pub fn new_coroutine_witness( tcx: TyCtxt<'tcx>, id: DefId, args: GenericArgsRef<'tcx>, ) -> Ty<'tcx> { - Ty::new(tcx, GeneratorWitness(id, args)) + Ty::new(tcx, CoroutineWitness(id, args)) } // misc @@ -2495,8 +2495,8 @@ impl<'tcx> Ty<'tcx> { } #[inline] - pub fn is_generator(self) -> bool { - matches!(self.kind(), Generator(..)) + pub fn is_coroutine(self) -> bool { + matches!(self.kind(), Coroutine(..)) } #[inline] @@ -2652,13 +2652,13 @@ impl<'tcx> Ty<'tcx> { /// If the type contains variants, returns the valid range of variant indices. // - // FIXME: This requires the optimized MIR in the case of generators. + // FIXME: This requires the optimized MIR in the case of coroutines. #[inline] pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option> { match self.kind() { TyKind::Adt(adt, _) => Some(adt.variant_range()), - TyKind::Generator(def_id, args, _) => { - Some(args.as_generator().variant_range(*def_id, tcx)) + TyKind::Coroutine(def_id, args, _) => { + Some(args.as_coroutine().variant_range(*def_id, tcx)) } _ => None, } @@ -2667,7 +2667,7 @@ impl<'tcx> Ty<'tcx> { /// If the type contains variants, returns the variant for `variant_index`. /// Panics if `variant_index` is out of range. // - // FIXME: This requires the optimized MIR in the case of generators. + // FIXME: This requires the optimized MIR in the case of coroutines. #[inline] pub fn discriminant_for_variant( self, @@ -2678,8 +2678,8 @@ impl<'tcx> Ty<'tcx> { TyKind::Adt(adt, _) if adt.is_enum() => { Some(adt.discriminant_for_variant(tcx, variant_index)) } - TyKind::Generator(def_id, args, _) => { - Some(args.as_generator().discriminant_for_variant(*def_id, tcx, variant_index)) + TyKind::Coroutine(def_id, args, _) => { + Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index)) } _ => None, } @@ -2689,7 +2689,7 @@ impl<'tcx> Ty<'tcx> { pub fn discriminant_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self.kind() { ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx), - ty::Generator(_, args, _) => args.as_generator().discr_ty(tcx), + ty::Coroutine(_, args, _) => args.as_coroutine().discr_ty(tcx), ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => { let assoc_items = tcx.associated_item_def_ids( @@ -2714,7 +2714,7 @@ impl<'tcx> Ty<'tcx> { | ty::FnPtr(..) | ty::Dynamic(..) | ty::Closure(..) - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Error(_) @@ -2748,8 +2748,8 @@ impl<'tcx> Ty<'tcx> { | ty::RawPtr(..) | ty::Char | ty::Ref(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Array(..) | ty::Closure(..) | ty::Never @@ -2836,8 +2836,8 @@ impl<'tcx> Ty<'tcx> { | ty::RawPtr(..) | ty::Char | ty::Ref(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Array(..) | ty::Closure(..) | ty::Never @@ -2900,7 +2900,7 @@ impl<'tcx> Ty<'tcx> { // anything with custom metadata it might be more complicated. ty::Ref(_, _, hir::Mutability::Not) | ty::RawPtr(..) => false, - ty::Generator(..) | ty::GeneratorWitness(..) => false, + ty::Coroutine(..) | ty::CoroutineWitness(..) => false, // Might be, but not "trivial" so just giving the safe answer. ty::Adt(..) | ty::Closure(..) => false, @@ -2975,8 +2975,8 @@ impl<'tcx> Ty<'tcx> { | FnPtr(_) | Dynamic(_, _, _) | Closure(_, _) - | Generator(_, _, _) - | GeneratorWitness(..) + | Coroutine(_, _, _) + | CoroutineWitness(..) | Never | Tuple(_) => true, Error(_) | Infer(_) | Alias(_, _) | Param(_) | Bound(_, _) | Placeholder(_) => false, diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index a44224e4dc7e2..7d516410b201f 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -189,9 +189,9 @@ pub struct TypeckResults<'tcx> { /// Details may be find in `rustc_hir_analysis::check::rvalue_scopes`. pub rvalue_scopes: RvalueScopes, - /// Stores the predicates that apply on generator witness types. - /// formatting modified file tests/ui/generator/retain-resume-ref.rs - pub generator_interior_predicates: + /// Stores the predicates that apply on coroutine witness types. + /// formatting modified file tests/ui/coroutine/retain-resume-ref.rs + pub coroutine_interior_predicates: LocalDefIdMap, ObligationCause<'tcx>)>>, /// We sometimes treat byte string literals (which are of type `&[u8; N]`) @@ -231,7 +231,7 @@ impl<'tcx> TypeckResults<'tcx> { closure_min_captures: Default::default(), closure_fake_reads: Default::default(), rvalue_scopes: Default::default(), - generator_interior_predicates: Default::default(), + coroutine_interior_predicates: Default::default(), treat_byte_string_as_slice: Default::default(), closure_size_eval: Default::default(), offset_of_data: Default::default(), diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 31b52677b2797..be48c0e8926b7 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -548,15 +548,15 @@ impl<'tcx> TyCtxt<'tcx> { /// those are not yet phased out). The parent of the closure's /// `DefId` will also be the context where it appears. pub fn is_closure(self, def_id: DefId) -> bool { - matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Generator) + matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Coroutine) } /// Returns `true` if `def_id` refers to a definition that does not have its own - /// type-checking context, i.e. closure, generator or inline const. + /// type-checking context, i.e. closure, coroutine or inline const. pub fn is_typeck_child(self, def_id: DefId) -> bool { matches!( self.def_kind(def_id), - DefKind::Closure | DefKind::Generator | DefKind::InlineConst + DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst ) } @@ -686,13 +686,13 @@ impl<'tcx> TyCtxt<'tcx> { } /// Return the set of types that should be taken into account when checking - /// trait bounds on a generator's internal state. - pub fn generator_hidden_types( + /// trait bounds on a coroutine's internal state. + pub fn coroutine_hidden_types( self, def_id: DefId, ) -> impl Iterator>> { - let generator_layout = self.mir_generator_witnesses(def_id); - generator_layout + let coroutine_layout = self.mir_coroutine_witnesses(def_id); + coroutine_layout .as_ref() .map_or_else(|| [].iter(), |l| l.field_tys.iter()) .filter(|decl| !decl.ignore_for_traits) @@ -709,7 +709,7 @@ impl<'tcx> TyCtxt<'tcx> { found_recursion: false, found_any_recursion: false, check_recursion: false, - expand_generators: false, + expand_coroutines: false, tcx: self, }; val.fold_with(&mut visitor) @@ -729,7 +729,7 @@ impl<'tcx> TyCtxt<'tcx> { found_recursion: false, found_any_recursion: false, check_recursion: true, - expand_generators: true, + expand_coroutines: true, tcx: self, }; @@ -746,9 +746,9 @@ impl<'tcx> TyCtxt<'tcx> { pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str { match def_kind { DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method", - DefKind::Generator => match self.generator_kind(def_id).unwrap() { - rustc_hir::GeneratorKind::Async(..) => "async closure", - rustc_hir::GeneratorKind::Gen => "generator", + DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() { + rustc_hir::CoroutineKind::Async(..) => "async closure", + rustc_hir::CoroutineKind::Coroutine => "coroutine", }, _ => def_kind.descr(def_id), } @@ -763,9 +763,9 @@ impl<'tcx> TyCtxt<'tcx> { pub fn def_kind_descr_article(self, def_kind: DefKind, def_id: DefId) -> &'static str { match def_kind { DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a", - DefKind::Generator => match self.generator_kind(def_id).unwrap() { - rustc_hir::GeneratorKind::Async(..) => "an", - rustc_hir::GeneratorKind::Gen => "a", + DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() { + rustc_hir::CoroutineKind::Async(..) => "an", + rustc_hir::CoroutineKind::Coroutine => "a", }, _ => def_kind.article(), } @@ -804,7 +804,7 @@ struct OpaqueTypeExpander<'tcx> { primary_def_id: Option, found_recursion: bool, found_any_recursion: bool, - expand_generators: bool, + expand_coroutines: bool, /// Whether or not to check for recursive opaque types. /// This is `true` when we're explicitly checking for opaque type /// recursion, and 'false' otherwise to avoid unnecessary work. @@ -842,7 +842,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> { } } - fn expand_generator(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> Option> { + fn expand_coroutine(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> Option> { if self.found_any_recursion { return None; } @@ -851,11 +851,11 @@ impl<'tcx> OpaqueTypeExpander<'tcx> { let expanded_ty = match self.expanded_cache.get(&(def_id, args)) { Some(expanded_ty) => *expanded_ty, None => { - for bty in self.tcx.generator_hidden_types(def_id) { + for bty in self.tcx.coroutine_hidden_types(def_id) { let hidden_ty = bty.instantiate(self.tcx, args); self.fold_ty(hidden_ty); } - let expanded_ty = Ty::new_generator_witness(self.tcx, def_id, args); + let expanded_ty = Ty::new_coroutine_witness(self.tcx, def_id, args); self.expanded_cache.insert((def_id, args), expanded_ty); expanded_ty } @@ -882,14 +882,14 @@ impl<'tcx> TypeFolder> for OpaqueTypeExpander<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { let mut t = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) = *t.kind() { self.expand_opaque_ty(def_id, args).unwrap_or(t) - } else if t.has_opaque_types() || t.has_generators() { + } else if t.has_opaque_types() || t.has_coroutines() { t.super_fold_with(self) } else { t }; - if self.expand_generators { - if let ty::GeneratorWitness(def_id, args) = *t.kind() { - t = self.expand_generator(def_id, args).unwrap_or(t); + if self.expand_coroutines { + if let ty::CoroutineWitness(def_id, args) = *t.kind() { + t = self.expand_coroutine(def_id, args).unwrap_or(t); } } t @@ -1024,8 +1024,8 @@ impl<'tcx> Ty<'tcx> { | ty::Closure(..) | ty::Dynamic(..) | ty::Foreign(_) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Alias(..) | ty::Param(_) @@ -1063,8 +1063,8 @@ impl<'tcx> Ty<'tcx> { | ty::Closure(..) | ty::Dynamic(..) | ty::Foreign(_) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Alias(..) | ty::Param(_) @@ -1182,7 +1182,7 @@ impl<'tcx> Ty<'tcx> { // Conservatively return `false` for all others... // Anonymous function types - ty::FnDef(..) | ty::Closure(..) | ty::Dynamic(..) | ty::Generator(..) => false, + ty::FnDef(..) | ty::Closure(..) | ty::Dynamic(..) | ty::Coroutine(..) => false, // Generic or inferred types // @@ -1192,7 +1192,7 @@ impl<'tcx> Ty<'tcx> { false } - ty::Foreign(_) | ty::GeneratorWitness(..) | ty::Error(_) => false, + ty::Foreign(_) | ty::CoroutineWitness(..) | ty::Error(_) => false, } } @@ -1287,7 +1287,7 @@ pub fn needs_drop_components<'tcx>( | ty::FnDef(..) | ty::FnPtr(_) | ty::Char - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::RawPtr(_) | ty::Ref(..) | ty::Str => Ok(SmallVec::new()), @@ -1327,7 +1327,7 @@ pub fn needs_drop_components<'tcx>( | ty::Placeholder(..) | ty::Infer(_) | ty::Closure(..) - | ty::Generator(..) => Ok(smallvec![ty]), + | ty::Coroutine(..) => Ok(smallvec![ty]), } } @@ -1358,7 +1358,7 @@ pub fn is_trivially_const_drop(ty: Ty<'_>) -> bool { // Not trivial because they have components, and instead of looking inside, // we'll just perform trait selection. - ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(..) | ty::Adt(..) => false, + ty::Closure(..) | ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Adt(..) => false, ty::Array(ty, _) | ty::Slice(ty) => is_trivially_const_drop(ty), @@ -1419,7 +1419,7 @@ pub fn reveal_opaque_types_in_bounds<'tcx>( found_recursion: false, found_any_recursion: false, check_recursion: false, - expand_generators: false, + expand_coroutines: false, tcx, }; val.fold_with(&mut visitor) diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index 5deb5bfb19ee4..15de994864462 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -47,7 +47,7 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable> { fn has_opaque_types(&self) -> bool { self.has_type_flags(TypeFlags::HAS_TY_OPAQUE) } - fn has_generators(&self) -> bool { + fn has_coroutines(&self) -> bool { self.has_type_flags(TypeFlags::HAS_TY_GENERATOR) } fn references_error(&self) -> bool { diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index a86ff64bd0ca3..20bdbcb5b7bb4 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -189,8 +189,8 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) } ty::Adt(_, args) | ty::Closure(_, args) - | ty::Generator(_, args, _) - | ty::GeneratorWitness(_, args) + | ty::Coroutine(_, args, _) + | ty::CoroutineWitness(_, args) | ty::FnDef(_, args) => { stack.extend(args.iter().rev()); } diff --git a/compiler/rustc_mir_build/src/build/custom/mod.rs b/compiler/rustc_mir_build/src/build/custom/mod.rs index a81f70e3346a4..3de2f45ad9a83 100644 --- a/compiler/rustc_mir_build/src/build/custom/mod.rs +++ b/compiler/rustc_mir_build/src/build/custom/mod.rs @@ -48,7 +48,7 @@ pub(super) fn build_custom_mir<'tcx>( source: MirSource::item(did), phase: MirPhase::Built, source_scopes: IndexVec::new(), - generator: None, + coroutine: None, local_decls: IndexVec::new(), user_type_annotations: IndexVec::new(), arg_count: params.len(), diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 4aff406b37686..c6a09f6568a5e 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -75,7 +75,7 @@ pub(in crate::build) struct PlaceBuilder<'tcx> { /// Given a list of MIR projections, convert them to list of HIR ProjectionKind. /// The projections are truncated to represent a path that might be captured by a -/// closure/generator. This implies the vector returned from this function doesn't contain +/// closure/coroutine. This implies the vector returned from this function doesn't contain /// ProjectionElems `Downcast`, `ConstantIndex`, `Index`, or `Subslice` because those will never be /// part of a path that is captured by a closure. We stop applying projections once we see the first /// projection that isn't captured by a closure. @@ -213,7 +213,7 @@ fn to_upvars_resolved_place_builder<'tcx>( /// projections. /// /// Supports only HIR projection kinds that represent a path that might be -/// captured by a closure or a generator, i.e., an `Index` or a `Subslice` +/// captured by a closure or a coroutine, i.e., an `Index` or a `Subslice` /// projection kinds are unsupported. fn strip_prefix<'a, 'tcx>( mut base_ty: Ty<'tcx>, diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 7d7542a9a6af3..eece8684e3601 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -181,7 +181,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block = success; // The `Box` temporary created here is not a part of the HIR, - // and therefore is not considered during generator auto-trait + // and therefore is not considered during coroutine auto-trait // determination. See the comment about `box` at `yield_in_scope`. let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span)); this.cfg.push( @@ -487,11 +487,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .collect(); let result = match args { - UpvarArgs::Generator(args) => { + UpvarArgs::Coroutine(args) => { // We implicitly set the discriminant to 0. See // librustc_mir/transform/deaggregator.rs for details. let movability = movability.unwrap(); - Box::new(AggregateKind::Generator(closure_id.to_def_id(), args, movability)) + Box::new(AggregateKind::Coroutine(closure_id.to_def_id(), args, movability)) } UpvarArgs::Closure(args) => { Box::new(AggregateKind::Closure(closure_id.to_def_id(), args)) diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index a4de42d45c995..054661cf2373b 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -547,7 +547,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { source_info, TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None }, ); - this.generator_drop_cleanup(block); + this.coroutine_drop_cleanup(block); resume.unit() } diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index d9098bac1c2b2..8a3b67b8f03d6 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -9,7 +9,7 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::{GeneratorKind, Node}; +use rustc_hir::{CoroutineKind, Node}; use rustc_index::bit_set::GrowableBitSet; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; @@ -173,7 +173,7 @@ struct Builder<'a, 'tcx> { check_overflow: bool, fn_span: Span, arg_count: usize, - generator_kind: Option, + coroutine_kind: Option, /// The current set of scopes, updated as we traverse; /// see the `scope` module for more details. @@ -448,7 +448,7 @@ fn construct_fn<'tcx>( ) -> Body<'tcx> { let span = tcx.def_span(fn_def); let fn_id = tcx.hir().local_def_id_to_hir_id(fn_def); - let generator_kind = tcx.generator_kind(fn_def); + let coroutine_kind = tcx.coroutine_kind(fn_def); // The representation of thir for `-Zunpretty=thir-tree` relies on // the entry expression being the last element of `thir.exprs`. @@ -478,12 +478,12 @@ fn construct_fn<'tcx>( let arguments = &thir.params; - let (yield_ty, return_ty) = if generator_kind.is_some() { + let (yield_ty, return_ty) = if coroutine_kind.is_some() { let gen_ty = arguments[thir::UPVAR_ENV_PARAM].ty; let gen_sig = match gen_ty.kind() { - ty::Generator(_, gen_args, ..) => gen_args.as_generator().sig(), + ty::Coroutine(_, gen_args, ..) => gen_args.as_coroutine().sig(), _ => { - span_bug!(span, "generator w/o generator type: {:?}", gen_ty) + span_bug!(span, "coroutine w/o coroutine type: {:?}", gen_ty) } }; (Some(gen_sig.yield_ty), gen_sig.return_ty) @@ -519,7 +519,7 @@ fn construct_fn<'tcx>( safety, return_ty, return_ty_span, - generator_kind, + coroutine_kind, ); let call_site_scope = @@ -553,7 +553,7 @@ fn construct_fn<'tcx>( None }; if yield_ty.is_some() { - body.generator.as_mut().unwrap().yield_ty = yield_ty; + body.coroutine.as_mut().unwrap().yield_ty = yield_ty; } body } @@ -619,7 +619,7 @@ fn construct_const<'a, 'tcx>( fn construct_error(tcx: TyCtxt<'_>, def: LocalDefId, err: ErrorGuaranteed) -> Body<'_> { let span = tcx.def_span(def); let hir_id = tcx.hir().local_def_id_to_hir_id(def); - let generator_kind = tcx.generator_kind(def); + let coroutine_kind = tcx.coroutine_kind(def); let body_owner_kind = tcx.hir().body_owner_kind(def); let ty = Ty::new_error(tcx, err); @@ -629,8 +629,8 @@ fn construct_error(tcx: TyCtxt<'_>, def: LocalDefId, err: ErrorGuaranteed) -> Bo let ty = tcx.type_of(def).instantiate_identity(); match ty.kind() { ty::Closure(_, args) => 1 + args.as_closure().sig().inputs().skip_binder().len(), - ty::Generator(..) => 2, - _ => bug!("expected closure or generator, found {ty:?}"), + ty::Coroutine(..) => 2, + _ => bug!("expected closure or coroutine, found {ty:?}"), } } hir::BodyOwnerKind::Const { .. } => 0, @@ -669,10 +669,10 @@ fn construct_error(tcx: TyCtxt<'_>, def: LocalDefId, err: ErrorGuaranteed) -> Bo num_params, vec![], span, - generator_kind, + coroutine_kind, Some(err), ); - body.generator.as_mut().map(|gen| gen.yield_ty = Some(ty)); + body.coroutine.as_mut().map(|gen| gen.yield_ty = Some(ty)); body } @@ -687,7 +687,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { safety: Safety, return_ty: Ty<'tcx>, return_span: Span, - generator_kind: Option, + coroutine_kind: Option, ) -> Builder<'a, 'tcx> { let tcx = infcx.tcx; let attrs = tcx.hir().attrs(hir_id); @@ -718,7 +718,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { cfg: CFG { basic_blocks: IndexVec::new() }, fn_span: span, arg_count, - generator_kind, + coroutine_kind, scopes: scope::Scopes::new(), block_context: BlockContext::new(), source_scopes: IndexVec::new(), @@ -760,7 +760,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.arg_count, self.var_debug_info, self.fn_span, - self.generator_kind, + self.coroutine_kind, None, ) } @@ -777,7 +777,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let upvar_args = match closure_ty.kind() { ty::Closure(_, args) => ty::UpvarArgs::Closure(args), - ty::Generator(_, args, _) => ty::UpvarArgs::Generator(args), + ty::Coroutine(_, args, _) => ty::UpvarArgs::Coroutine(args), _ => return, }; diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index bc151cc705898..b3d3863b5db77 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -108,8 +108,8 @@ pub struct Scopes<'tcx> { /// [DropTree] for more details. unwind_drops: DropTree, - /// Drops that need to be done on paths to the `GeneratorDrop` terminator. - generator_drops: DropTree, + /// Drops that need to be done on paths to the `CoroutineDrop` terminator. + coroutine_drops: DropTree, } #[derive(Debug)] @@ -133,8 +133,8 @@ struct Scope { cached_unwind_block: Option, /// The drop index that will drop everything in and below this scope on a - /// generator drop path. - cached_generator_drop_block: Option, + /// coroutine drop path. + cached_coroutine_drop_block: Option, } #[derive(Clone, Copy, Debug)] @@ -194,7 +194,7 @@ const ROOT_NODE: DropIdx = DropIdx::from_u32(0); /// A tree of drops that we have deferred lowering. It's used for: /// /// * Drops on unwind paths -/// * Drops on generator drop paths (when a suspended generator is dropped) +/// * Drops on coroutine drop paths (when a suspended coroutine is dropped) /// * Drops on return and loop exit paths /// * Drops on the else path in an `if let` chain /// @@ -222,8 +222,8 @@ impl Scope { /// * polluting the cleanup MIR with StorageDead creates /// landing pads even though there's no actual destructors /// * freeing up stack space has no effect during unwinding - /// Note that for generators we do emit StorageDeads, for the - /// use of optimizations in the MIR generator transform. + /// Note that for coroutines we do emit StorageDeads, for the + /// use of optimizations in the MIR coroutine transform. fn needs_cleanup(&self) -> bool { self.drops.iter().any(|drop| match drop.kind { DropKind::Value => true, @@ -233,7 +233,7 @@ impl Scope { fn invalidate_cache(&mut self) { self.cached_unwind_block = None; - self.cached_generator_drop_block = None; + self.cached_coroutine_drop_block = None; } } @@ -407,7 +407,7 @@ impl<'tcx> Scopes<'tcx> { breakable_scopes: Vec::new(), if_then_scope: None, unwind_drops: DropTree::new(), - generator_drops: DropTree::new(), + coroutine_drops: DropTree::new(), } } @@ -419,7 +419,7 @@ impl<'tcx> Scopes<'tcx> { drops: vec![], moved_locals: vec![], cached_unwind_block: None, - cached_generator_drop_block: None, + cached_coroutine_drop_block: None, }); } @@ -734,7 +734,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // If we are emitting a `drop` statement, we need to have the cached // diverge cleanup pads ready in case that drop panics. let needs_cleanup = self.scopes.scopes.last().is_some_and(|scope| scope.needs_cleanup()); - let is_generator = self.generator_kind.is_some(); + let is_coroutine = self.coroutine_kind.is_some(); let unwind_to = if needs_cleanup { self.diverge_cleanup() } else { DropIdx::MAX }; let scope = self.scopes.scopes.last().expect("leave_top_scope called with no scopes"); @@ -744,7 +744,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { scope, block, unwind_to, - is_generator && needs_cleanup, + is_coroutine && needs_cleanup, self.arg_count, )) } @@ -984,11 +984,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // caches gets invalidated. i.e., if a new drop is added into the middle scope, the // cache of outer scope stays intact. // - // Since we only cache drops for the unwind path and the generator drop + // Since we only cache drops for the unwind path and the coroutine drop // path, we only need to invalidate the cache for drops that happen on - // the unwind or generator drop paths. This means that for - // non-generators we don't need to invalidate caches for `DropKind::Storage`. - let invalidate_caches = needs_drop || self.generator_kind.is_some(); + // the unwind or coroutine drop paths. This means that for + // non-coroutines we don't need to invalidate caches for `DropKind::Storage`. + let invalidate_caches = needs_drop || self.coroutine_kind.is_some(); for scope in self.scopes.scopes.iter_mut().rev() { if invalidate_caches { scope.invalidate_cache(); @@ -1101,10 +1101,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { return cached_drop; } - let is_generator = self.generator_kind.is_some(); + let is_coroutine = self.coroutine_kind.is_some(); for scope in &mut self.scopes.scopes[uncached_scope..=target] { for drop in &scope.drops { - if is_generator || drop.kind == DropKind::Value { + if is_coroutine || drop.kind == DropKind::Value { cached_drop = self.scopes.unwind_drops.add_drop(*drop, cached_drop); } } @@ -1137,17 +1137,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } /// Sets up a path that performs all required cleanup for dropping a - /// generator, starting from the given block that ends in + /// coroutine, starting from the given block that ends in /// [TerminatorKind::Yield]. /// - /// This path terminates in GeneratorDrop. - pub(crate) fn generator_drop_cleanup(&mut self, yield_block: BasicBlock) { + /// This path terminates in CoroutineDrop. + pub(crate) fn coroutine_drop_cleanup(&mut self, yield_block: BasicBlock) { debug_assert!( matches!( self.cfg.block_data(yield_block).terminator().kind, TerminatorKind::Yield { .. } ), - "generator_drop_cleanup called on block with non-yield terminator." + "coroutine_drop_cleanup called on block with non-yield terminator." ); let (uncached_scope, mut cached_drop) = self .scopes @@ -1156,18 +1156,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .enumerate() .rev() .find_map(|(scope_idx, scope)| { - scope.cached_generator_drop_block.map(|cached_block| (scope_idx + 1, cached_block)) + scope.cached_coroutine_drop_block.map(|cached_block| (scope_idx + 1, cached_block)) }) .unwrap_or((0, ROOT_NODE)); for scope in &mut self.scopes.scopes[uncached_scope..] { for drop in &scope.drops { - cached_drop = self.scopes.generator_drops.add_drop(*drop, cached_drop); + cached_drop = self.scopes.coroutine_drops.add_drop(*drop, cached_drop); } - scope.cached_generator_drop_block = Some(cached_drop); + scope.cached_coroutine_drop_block = Some(cached_drop); } - self.scopes.generator_drops.add_entry(yield_block, cached_drop); + self.scopes.coroutine_drops.add_entry(yield_block, cached_drop); } /// Utility function for *non*-scope code to build their own drops @@ -1274,7 +1274,7 @@ fn build_scope_drops<'tcx>( // drops panic (panicking while unwinding will abort, so there's no need for // another set of arrows). // - // For generators, we unwind from a drop on a local to its StorageDead + // For coroutines, we unwind from a drop on a local to its StorageDead // statement. For other functions we don't worry about StorageDead. The // drops for the unwind path should have already been generated by // `diverge_cleanup_gen`. @@ -1346,7 +1346,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> { blocks[ROOT_NODE] = continue_block; drops.build_mir::(&mut self.cfg, &mut blocks); - let is_generator = self.generator_kind.is_some(); + let is_coroutine = self.coroutine_kind.is_some(); // Link the exit drop tree to unwind drop tree. if drops.drops.iter().any(|(drop, _)| drop.kind == DropKind::Value) { @@ -1355,7 +1355,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> { for (drop_idx, drop_data) in drops.drops.iter_enumerated().skip(1) { match drop_data.0.kind { DropKind::Storage => { - if is_generator { + if is_coroutine { let unwind_drop = self .scopes .unwind_drops @@ -1381,10 +1381,10 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> { blocks[ROOT_NODE].map(BasicBlock::unit) } - /// Build the unwind and generator drop trees. + /// Build the unwind and coroutine drop trees. pub(crate) fn build_drop_trees(&mut self) { - if self.generator_kind.is_some() { - self.build_generator_drop_trees(); + if self.coroutine_kind.is_some() { + self.build_coroutine_drop_trees(); } else { Self::build_unwind_tree( &mut self.cfg, @@ -1395,18 +1395,18 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> { } } - fn build_generator_drop_trees(&mut self) { - // Build the drop tree for dropping the generator while it's suspended. - let drops = &mut self.scopes.generator_drops; + fn build_coroutine_drop_trees(&mut self) { + // Build the drop tree for dropping the coroutine while it's suspended. + let drops = &mut self.scopes.coroutine_drops; let cfg = &mut self.cfg; let fn_span = self.fn_span; let mut blocks = IndexVec::from_elem(None, &drops.drops); - drops.build_mir::(cfg, &mut blocks); + drops.build_mir::(cfg, &mut blocks); if let Some(root_block) = blocks[ROOT_NODE] { cfg.terminate( root_block, SourceInfo::outermost(fn_span), - TerminatorKind::GeneratorDrop, + TerminatorKind::CoroutineDrop, ); } @@ -1416,11 +1416,11 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> { Self::build_unwind_tree(cfg, unwind_drops, fn_span, resume_block); // Build the drop tree for unwinding when dropping a suspended - // generator. + // coroutine. // // This is a different tree to the standard unwind paths here to // prevent drop elaboration from creating drop flags that would have - // to be captured by the generator. I'm not sure how important this + // to be captured by the coroutine. I'm not sure how important this // optimization is, but it is here. for (drop_idx, drop_data) in drops.drops.iter_enumerated() { if let DropKind::Value = drop_data.0.kind { @@ -1461,9 +1461,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for ExitScopes { } } -struct GeneratorDrop; +struct CoroutineDrop; -impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop { +impl<'tcx> DropTreeBuilder<'tcx> for CoroutineDrop { fn make_block(cfg: &mut CFG<'tcx>) -> BasicBlock { cfg.start_new_block() } @@ -1474,7 +1474,7 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop { } else { span_bug!( term.source_info.span, - "cannot enter generator drop tree from {:?}", + "cannot enter coroutine drop tree from {:?}", term.kind ) } @@ -1511,7 +1511,7 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind { | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Yield { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } => { span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind) } diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 2d221b826c9bf..00d2afce8c658 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -121,7 +121,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> { self.tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, self.hir_context).0 == Level::Allow } - /// Handle closures/generators/inline-consts, which is unsafecked with their parent body. + /// Handle closures/coroutines/inline-consts, which is unsafecked with their parent body. fn visit_inner_body(&mut self, def: LocalDefId) { if let Ok((inner_thir, expr)) = self.tcx.thir_body(def) { let inner_thir = &inner_thir.borrow(); diff --git a/compiler/rustc_mir_build/src/lints.rs b/compiler/rustc_mir_build/src/lints.rs index e78274b4284c4..acf4d6bc2a071 100644 --- a/compiler/rustc_mir_build/src/lints.rs +++ b/compiler/rustc_mir_build/src/lints.rs @@ -192,7 +192,7 @@ impl<'mir, 'tcx, C: TerminatorClassifier<'tcx>> TriColorVisitor Cx<'tcx> { let closure_ty = self.typeck_results().expr_ty(expr); let (def_id, args, movability) = match *closure_ty.kind() { ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None), - ty::Generator(def_id, args, movability) => { - (def_id, UpvarArgs::Generator(args), Some(movability)) + ty::Coroutine(def_id, args, movability) => { + (def_id, UpvarArgs::Coroutine(args), Some(movability)) } _ => { span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty); diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index d98cc76adfbd7..8bc4cbb953296 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -37,7 +37,7 @@ pub(crate) fn thir_body( // The resume argument may be missing, in that case we need to provide it here. // It will always be `()` in this case. - if tcx.def_kind(owner_def) == DefKind::Generator && body.params.is_empty() { + if tcx.def_kind(owner_def) == DefKind::Coroutine && body.params.is_empty() { cx.thir.params.push(Param { ty: Ty::new_unit(tcx), pat: None, @@ -148,7 +148,7 @@ impl<'tcx> Cx<'tcx> { Some(env_param) } - DefKind::Generator => { + DefKind::Coroutine => { let gen_ty = self.typeck_results.node_type(owner_id); let gen_param = Param { ty: gen_ty, pat: None, ty_span: None, self_kind: None, hir_id: None }; diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index c9991e499b32a..25ba67a63ecee 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -860,13 +860,13 @@ where let ty = self.place_ty(self.place); match ty.kind() { ty::Closure(_, args) => self.open_drop_for_tuple(&args.as_closure().upvar_tys()), - // Note that `elaborate_drops` only drops the upvars of a generator, + // Note that `elaborate_drops` only drops the upvars of a coroutine, // and this is ok because `open_drop` here can only be reached - // within that own generator's resume function. + // within that own coroutine's resume function. // This should only happen for the self argument on the resume function. - // It effectively only contains upvars until the generator transformation runs. - // See librustc_body/transform/generator.rs for more details. - ty::Generator(_, args, _) => self.open_drop_for_tuple(&args.as_generator().upvar_tys()), + // It effectively only contains upvars until the coroutine transformation runs. + // See librustc_body/transform/coroutine.rs for more details. + ty::Coroutine(_, args, _) => self.open_drop_for_tuple(&args.as_coroutine().upvar_tys()), ty::Tuple(fields) => self.open_drop_for_tuple(fields), ty::Adt(def, args) => self.open_drop_for_adt(*def, args), ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind), diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs index bdddaaebca41d..c12ccba1e5c6d 100644 --- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -267,7 +267,7 @@ where mir::TerminatorKind::Yield { resume, resume_arg, .. } => { self.write_row(w, "", "(on yield resume)", |this, w, fmt| { - let state_on_generator_drop = this.results.get().clone(); + let state_on_coroutine_drop = this.results.get().clone(); this.results.apply_custom_effect(|analysis, state| { analysis.apply_call_return_effect( state, @@ -283,7 +283,7 @@ where fmt = fmt, diff = diff_pretty( this.results.get(), - &state_on_generator_drop, + &state_on_coroutine_drop, this.results.analysis() ), ) diff --git a/compiler/rustc_mir_dataflow/src/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs index ce30c642fcc9f..b785a999f08b5 100644 --- a/compiler/rustc_mir_dataflow/src/framework/mod.rs +++ b/compiler/rustc_mir_dataflow/src/framework/mod.rs @@ -114,7 +114,7 @@ pub trait AnalysisDomain<'tcx> { // // FIXME: For backward dataflow analyses, the initial state should be applied to every basic // block where control flow could exit the MIR body (e.g., those terminated with `return` or - // `resume`). It's not obvious how to handle `yield` points in generators, however. + // `resume`). It's not obvious how to handle `yield` points in coroutines, however. fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain); } diff --git a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs index 3ad9d3d426404..1e8e09ac333b1 100644 --- a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs @@ -9,7 +9,7 @@ use crate::{AnalysisDomain, GenKill, GenKillAnalysis}; /// /// At present, this is used as a very limited form of alias analysis. For example, /// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for -/// immovable generators. +/// immovable coroutines. #[derive(Clone, Copy)] pub struct MaybeBorrowedLocals; @@ -136,7 +136,7 @@ where | TerminatorKind::Call { .. } | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Goto { .. } | TerminatorKind::InlineAsm { .. } | TerminatorKind::UnwindResume diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index e6d383d626ad5..182f2590137e2 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -763,9 +763,9 @@ fn switch_on_enum_discriminant<'mir, 'tcx>( ty::Adt(def, _) => return Some((*discriminated, *def)), // `Rvalue::Discriminant` is also used to get the active yield point for a - // generator, but we do not need edge-specific effects in that case. This may + // coroutine, but we do not need edge-specific effects in that case. This may // change in the future. - ty::Generator(..) => return None, + ty::Coroutine(..) => return None, t => bug!("`discriminant` called on unexpected type {:?}", t), } diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index 5aa73c7a90699..c1152e88cd0f2 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -98,7 +98,7 @@ where { fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) { if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context { - // The resume place is evaluated and assigned to only after generator resumes, so its + // The resume place is evaluated and assigned to only after coroutine resumes, so its // effect is handled separately in `call_resume_effect`. return; } diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 94d6eb67d4994..5a58e3af8be1a 100644 --- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -268,7 +268,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> { // Note that we do *not* gen the `resume_arg` of `Yield` terminators. The reason for // that is that a `yield` will return from the function, and `resume_arg` is written - // only when the generator is later resumed. Unlike `Call`, this doesn't require the + // only when the coroutine is later resumed. Unlike `Call`, this doesn't require the // place to have storage *before* the yield, only after. TerminatorKind::Yield { .. } => {} @@ -296,7 +296,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> { | TerminatorKind::Drop { .. } | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume | TerminatorKind::Return @@ -333,7 +333,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> { | TerminatorKind::Drop { .. } | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume | TerminatorKind::Return diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index 7a5b3585d5971..91a96593173ca 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -143,8 +143,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { | ty::FnPtr(_) | ty::Dynamic(_, _, _) | ty::Closure(_, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Alias(_, _) @@ -168,7 +168,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { union_path.get_or_insert(base); } } - ty::Closure(_, _) | ty::Generator(_, _, _) | ty::Tuple(_) => (), + ty::Closure(_, _) | ty::Coroutine(_, _, _) | ty::Tuple(_) => (), ty::Bool | ty::Char | ty::Int(_) @@ -183,7 +183,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { | ty::FnDef(_, _) | ty::FnPtr(_) | ty::Dynamic(_, _, _) - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Alias(_, _) | ty::Param(_) @@ -454,7 +454,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { | TerminatorKind::Return | TerminatorKind::UnwindResume | TerminatorKind::UnwindTerminate(_) - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } => {} diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 44bbb8374dc95..04108aeedf625 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -274,7 +274,7 @@ pub trait ValueAnalysis<'tcx> { | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Assert { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => { // These terminators have no effect on the analysis. @@ -915,7 +915,7 @@ impl Map { ) { for sibling in self.children(parent) { let elem = self.places[sibling].proj_elem; - // Only invalidate variants and discriminant. Fields (for generators) are not + // Only invalidate variants and discriminant. Fields (for coroutines) are not // invalidated by assignment to a variant. if let Some(TrackElem::Variant(..) | TrackElem::Discriminant) = elem // Only invalidate the other variants, the current one is fine. diff --git a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index 74243f1f8f272..2b3d423ea61ae 100644 --- a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -40,7 +40,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { let body_abi = match body_ty.kind() { ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), ty::Closure(..) => Abi::RustCall, - ty::Generator(..) => Abi::Rust, + ty::Coroutine(..) => Abi::Rust, _ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty), }; let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi); diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index 7e4731f5d8a56..8872f9a97d746 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -56,7 +56,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { | TerminatorKind::Drop { .. } | TerminatorKind::Yield { .. } | TerminatorKind::Assert { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::UnwindResume | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return @@ -128,7 +128,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { ), } } - &AggregateKind::Closure(def_id, _) | &AggregateKind::Generator(def_id, _, _) => { + &AggregateKind::Closure(def_id, _) | &AggregateKind::Coroutine(def_id, _, _) => { let def_id = def_id.expect_local(); let UnsafetyCheckResult { violations, used_unsafe_blocks, .. } = self.tcx.unsafety_check_result(def_id); diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 3450a0f3686f8..53c0d0dea2924 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -82,11 +82,11 @@ impl<'tcx> MirPass<'tcx> for ConstProp { return; } - // FIXME(welseywiser) const prop doesn't work on generators because of query cycles + // FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles // computing their layout. - let is_generator = def_kind == DefKind::Generator; - if is_generator { - trace!("ConstProp skipped for generator {:?}", def_id); + let is_coroutine = def_kind == DefKind::Coroutine; + if is_coroutine { + trace!("ConstProp skipped for coroutine {:?}", def_id); return; } @@ -512,7 +512,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn replace_with_const(&mut self, place: Place<'tcx>) -> Option> { // This will return None if the above `const_prop` invocation only "wrote" a - // type whose creation requires no write. E.g. a generator whose initial state + // type whose creation requires no write. E.g. a coroutine whose initial state // consists solely of uninitialized memory (so it doesn't capture any locals). let value = self.get_const(place)?; if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - {value:?}")) { diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index aad513d735586..a23ba9c4aa9fd 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -59,10 +59,10 @@ impl<'tcx> MirLint<'tcx> for ConstPropLint { return; } - // FIXME(welseywiser) const prop doesn't work on generators because of query cycles + // FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles // computing their layout. - if let DefKind::Generator = def_kind { - trace!("ConstPropLint skipped for generator {:?}", def_id); + if let DefKind::Coroutine = def_kind { + trace!("ConstPropLint skipped for coroutine {:?}", def_id); return; } @@ -648,7 +648,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> { | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } | TerminatorKind::Yield { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } | TerminatorKind::Call { .. } diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/coroutine.rs similarity index 86% rename from compiler/rustc_mir_transform/src/generator.rs rename to compiler/rustc_mir_transform/src/coroutine.rs index a6693519e54b2..fa56d59dd80b2 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -1,53 +1,53 @@ -//! This is the implementation of the pass which transforms generators into state machines. +//! This is the implementation of the pass which transforms coroutines into state machines. //! -//! MIR generation for generators creates a function which has a self argument which -//! passes by value. This argument is effectively a generator type which only contains upvars and -//! is only used for this argument inside the MIR for the generator. +//! MIR generation for coroutines creates a function which has a self argument which +//! passes by value. This argument is effectively a coroutine type which only contains upvars and +//! is only used for this argument inside the MIR for the coroutine. //! It is passed by value to enable upvars to be moved out of it. Drop elaboration runs on that //! MIR before this pass and creates drop flags for MIR locals. -//! It will also drop the generator argument (which only consists of upvars) if any of the upvars -//! are moved out of. This pass elaborates the drops of upvars / generator argument in the case +//! It will also drop the coroutine argument (which only consists of upvars) if any of the upvars +//! are moved out of. This pass elaborates the drops of upvars / coroutine argument in the case //! that none of the upvars were moved out of. This is because we cannot have any drops of this -//! generator in the MIR, since it is used to create the drop glue for the generator. We'd get +//! coroutine in the MIR, since it is used to create the drop glue for the coroutine. We'd get //! infinite recursion otherwise. //! -//! This pass creates the implementation for either the `Generator::resume` or `Future::poll` -//! function and the drop shim for the generator based on the MIR input. -//! It converts the generator argument from Self to &mut Self adding derefs in the MIR as needed. -//! It computes the final layout of the generator struct which looks like this: +//! This pass creates the implementation for either the `Coroutine::resume` or `Future::poll` +//! function and the drop shim for the coroutine based on the MIR input. +//! It converts the coroutine argument from Self to &mut Self adding derefs in the MIR as needed. +//! It computes the final layout of the coroutine struct which looks like this: //! First upvars are stored -//! It is followed by the generator state field. +//! It is followed by the coroutine state field. //! Then finally the MIR locals which are live across a suspension point are stored. //! ```ignore (illustrative) -//! struct Generator { +//! struct Coroutine { //! upvars..., //! state: u32, //! mir_locals..., //! } //! ``` //! This pass computes the meaning of the state field and the MIR locals which are live -//! across a suspension point. There are however three hardcoded generator states: -//! 0 - Generator have not been resumed yet -//! 1 - Generator has returned / is completed -//! 2 - Generator has been poisoned +//! across a suspension point. There are however three hardcoded coroutine states: +//! 0 - Coroutine have not been resumed yet +//! 1 - Coroutine has returned / is completed +//! 2 - Coroutine has been poisoned //! -//! It also rewrites `return x` and `yield y` as setting a new generator state and returning -//! `GeneratorState::Complete(x)` and `GeneratorState::Yielded(y)`, +//! It also rewrites `return x` and `yield y` as setting a new coroutine state and returning +//! `CoroutineState::Complete(x)` and `CoroutineState::Yielded(y)`, //! or `Poll::Ready(x)` and `Poll::Pending` respectively. -//! MIR locals which are live across a suspension point are moved to the generator struct -//! with references to them being updated with references to the generator struct. +//! MIR locals which are live across a suspension point are moved to the coroutine struct +//! with references to them being updated with references to the coroutine struct. //! -//! The pass creates two functions which have a switch on the generator state giving +//! The pass creates two functions which have a switch on the coroutine state giving //! the action to take. //! -//! One of them is the implementation of `Generator::resume` / `Future::poll`. -//! For generators with state 0 (unresumed) it starts the execution of the generator. -//! For generators with state 1 (returned) and state 2 (poisoned) it panics. +//! One of them is the implementation of `Coroutine::resume` / `Future::poll`. +//! For coroutines with state 0 (unresumed) it starts the execution of the coroutine. +//! For coroutines with state 1 (returned) and state 2 (poisoned) it panics. //! Otherwise it continues the execution from the last suspension point. //! -//! The other function is the drop glue for the generator. -//! For generators with state 0 (unresumed) it drops the upvars of the generator. -//! For generators with state 1 (returned) and state 2 (poisoned) it does nothing. +//! The other function is the drop glue for the coroutine. +//! For coroutines with state 0 (unresumed) it drops the upvars of the coroutine. +//! For coroutines with state 1 (returned) and state 2 (poisoned) it does nothing. //! Otherwise it drops all the values in scope at the last suspension point. use crate::abort_unwinding_calls; @@ -60,7 +60,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::pluralize; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; -use rustc_hir::GeneratorKind; +use rustc_hir::CoroutineKind; use rustc_index::bit_set::{BitMatrix, BitSet, GrowableBitSet}; use rustc_index::{Idx, IndexVec}; use rustc_middle::mir::dump_mir; @@ -68,7 +68,7 @@ use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::InstanceDef; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; -use rustc_middle::ty::{GeneratorArgs, GenericArgsRef}; +use rustc_middle::ty::{CoroutineArgs, GenericArgsRef}; use rustc_mir_dataflow::impls::{ MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, }; @@ -196,19 +196,19 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx const SELF_ARG: Local = Local::from_u32(1); -/// Generator has not been resumed yet. -const UNRESUMED: usize = GeneratorArgs::UNRESUMED; -/// Generator has returned / is completed. -const RETURNED: usize = GeneratorArgs::RETURNED; -/// Generator has panicked and is poisoned. -const POISONED: usize = GeneratorArgs::POISONED; +/// Coroutine has not been resumed yet. +const UNRESUMED: usize = CoroutineArgs::UNRESUMED; +/// Coroutine has returned / is completed. +const RETURNED: usize = CoroutineArgs::RETURNED; +/// Coroutine has panicked and is poisoned. +const POISONED: usize = CoroutineArgs::POISONED; -/// Number of variants to reserve in generator state. Corresponds to -/// `UNRESUMED` (beginning of a generator) and `RETURNED`/`POISONED` -/// (end of a generator) states. +/// Number of variants to reserve in coroutine state. Corresponds to +/// `UNRESUMED` (beginning of a coroutine) and `RETURNED`/`POISONED` +/// (end of a coroutine) states. const RESERVED_VARIANTS: usize = 3; -/// A `yield` point in the generator. +/// A `yield` point in the coroutine. struct SuspensionPoint<'tcx> { /// State discriminant used when suspending or resuming at this point. state: usize, @@ -216,7 +216,7 @@ struct SuspensionPoint<'tcx> { resume: BasicBlock, /// Where to move the resume argument after resumption. resume_arg: Place<'tcx>, - /// Which block to jump to if the generator is dropped in this state. + /// Which block to jump to if the coroutine is dropped in this state. drop: Option, /// Set of locals that have live storage while at this suspension point. storage_liveness: GrowableBitSet, @@ -228,10 +228,10 @@ struct TransformVisitor<'tcx> { state_adt_ref: AdtDef<'tcx>, state_args: GenericArgsRef<'tcx>, - // The type of the discriminant in the generator struct + // The type of the discriminant in the coroutine struct discr_ty: Ty<'tcx>, - // Mapping from Local to (type of local, generator struct index) + // Mapping from Local to (type of local, coroutine struct index) // FIXME(eddyb) This should use `IndexVec>`. remap: FxHashMap, VariantIdx, FieldIdx)>, @@ -249,9 +249,9 @@ struct TransformVisitor<'tcx> { } impl<'tcx> TransformVisitor<'tcx> { - // Make a `GeneratorState` or `Poll` variant assignment. + // Make a `CoroutineState` or `Poll` variant assignment. // - // `core::ops::GeneratorState` only has single element tuple variants, + // `core::ops::CoroutineState` only has single element tuple variants, // so we can just write to the downcasted first field and then set the // discriminant to the appropriate variant. fn make_state( @@ -262,8 +262,8 @@ impl<'tcx> TransformVisitor<'tcx> { statements: &mut Vec>, ) { let idx = VariantIdx::new(match (is_return, self.is_async_kind) { - (true, false) => 1, // GeneratorState::Complete - (false, false) => 0, // GeneratorState::Yielded + (true, false) => 1, // CoroutineState::Complete + (false, false) => 0, // CoroutineState::Yielded (true, true) => 0, // Poll::Ready (false, true) => 1, // Poll::Pending }); @@ -285,7 +285,7 @@ impl<'tcx> TransformVisitor<'tcx> { return; } - // else: `Poll::Ready(x)`, `GeneratorState::Yielded(x)` or `GeneratorState::Complete(x)` + // else: `Poll::Ready(x)`, `CoroutineState::Yielded(x)` or `CoroutineState::Complete(x)` assert_eq!(self.state_adt_ref.variant(idx).fields.len(), 1); statements.push(Statement { @@ -297,7 +297,7 @@ impl<'tcx> TransformVisitor<'tcx> { }); } - // Create a Place referencing a generator struct field + // Create a Place referencing a coroutine struct field fn make_field(&self, variant_index: VariantIdx, idx: FieldIdx, ty: Ty<'tcx>) -> Place<'tcx> { let self_place = Place::from(SELF_ARG); let base = self.tcx.mk_place_downcast_unnamed(self_place, variant_index); @@ -349,7 +349,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { _context: PlaceContext, _location: Location, ) { - // Replace an Local in the remap with a generator struct access + // Replace an Local in the remap with a coroutine struct access if let Some(&(ty, variant_index, idx)) = self.remap.get(&place.local) { replace_base(place, self.make_field(variant_index, idx, ty), self.tcx); } @@ -413,7 +413,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { } } -fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { +fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let gen_ty = body.local_decls.raw[1].ty; let ref_gen_ty = Ty::new_ref( @@ -422,14 +422,14 @@ fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut }, ); - // Replace the by value generator argument + // Replace the by value coroutine argument body.local_decls.raw[1].ty = ref_gen_ty; - // Add a deref to accesses of the generator state + // Add a deref to accesses of the coroutine state DerefArgVisitor { tcx }.visit_body(body); } -fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { +fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let ref_gen_ty = body.local_decls.raw[1].ty; let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span)); @@ -437,10 +437,10 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body let args = tcx.mk_args(&[ref_gen_ty.into()]); let pin_ref_gen_ty = Ty::new_adt(tcx, pin_adt_ref, args); - // Replace the by ref generator argument + // Replace the by ref coroutine argument body.local_decls.raw[1].ty = pin_ref_gen_ty; - // Add the Pin field access to accesses of the generator state + // Add the Pin field access to accesses of the coroutine state PinArgVisitor { ref_gen_ty, tcx }.visit_body(body); } @@ -465,7 +465,7 @@ fn replace_local<'tcx>( new_local } -/// Transforms the `body` of the generator applying the following transforms: +/// Transforms the `body` of the coroutine applying the following transforms: /// /// - Eliminates all the `get_context` calls that async lowering created. /// - Replace all `Local` `ResumeTy` types with `&mut Context<'_>` (`context_mut_ref`). @@ -485,7 +485,7 @@ fn replace_local<'tcx>( /// /// The async lowering step and the type / lifetime inference / checking are /// still using the `ResumeTy` indirection for the time being, and that indirection -/// is removed here. After this transform, the generator body only knows about `&mut Context<'_>`. +/// is removed here. After this transform, the coroutine body only knows about `&mut Context<'_>`. fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let context_mut_ref = Ty::new_task_context(tcx); @@ -565,10 +565,10 @@ fn replace_resume_ty_local<'tcx>( struct LivenessInfo { /// Which locals are live across any suspension point. - saved_locals: GeneratorSavedLocals, + saved_locals: CoroutineSavedLocals, /// The set of saved locals live at each suspension point. - live_locals_at_suspension_points: Vec>, + live_locals_at_suspension_points: Vec>, /// Parallel vec to the above with SourceInfo for each yield terminator. source_info_at_suspension_points: Vec, @@ -576,7 +576,7 @@ struct LivenessInfo { /// For every saved local, the set of other saved locals that are /// storage-live at the same time as this local. We cannot overlap locals in /// the layout which have conflicting storage. - storage_conflicts: BitMatrix, + storage_conflicts: BitMatrix, /// For every suspending block, the locals which are storage-live across /// that suspension point. @@ -601,7 +601,7 @@ fn locals_live_across_suspend_points<'tcx>( // Calculate the MIR locals which have been previously // borrowed (even if they are still active). let borrowed_locals_results = - MaybeBorrowedLocals.into_engine(tcx, body_ref).pass_name("generator").iterate_to_fixpoint(); + MaybeBorrowedLocals.into_engine(tcx, body_ref).pass_name("coroutine").iterate_to_fixpoint(); let mut borrowed_locals_cursor = borrowed_locals_results.cloned_results_cursor(body_ref); @@ -616,7 +616,7 @@ fn locals_live_across_suspend_points<'tcx>( // Calculate the liveness of MIR locals ignoring borrows. let mut liveness = MaybeLiveLocals .into_engine(tcx, body_ref) - .pass_name("generator") + .pass_name("coroutine") .iterate_to_fixpoint() .into_results_cursor(body_ref); @@ -635,8 +635,8 @@ fn locals_live_across_suspend_points<'tcx>( if !movable { // The `liveness` variable contains the liveness of MIR locals ignoring borrows. - // This is correct for movable generators since borrows cannot live across - // suspension points. However for immovable generators we need to account for + // This is correct for movable coroutines since borrows cannot live across + // suspension points. However for immovable coroutines we need to account for // borrows, so we conservatively assume that all borrowed locals are live until // we find a StorageDead statement referencing the locals. // To do this we just union our `liveness` result with `borrowed_locals`, which @@ -659,7 +659,7 @@ fn locals_live_across_suspend_points<'tcx>( requires_storage_cursor.seek_before_primary_effect(loc); live_locals.intersect(requires_storage_cursor.get()); - // The generator argument is ignored. + // The coroutine argument is ignored. live_locals.remove(SELF_ARG); debug!("loc = {:?}, live_locals = {:?}", loc, live_locals); @@ -674,7 +674,7 @@ fn locals_live_across_suspend_points<'tcx>( } debug!("live_locals_anywhere = {:?}", live_locals_at_any_suspension_point); - let saved_locals = GeneratorSavedLocals(live_locals_at_any_suspension_point); + let saved_locals = CoroutineSavedLocals(live_locals_at_any_suspension_point); // Renumber our liveness_map bitsets to include only the locals we are // saving. @@ -701,21 +701,21 @@ fn locals_live_across_suspend_points<'tcx>( /// The set of `Local`s that must be saved across yield points. /// -/// `GeneratorSavedLocal` is indexed in terms of the elements in this set; -/// i.e. `GeneratorSavedLocal::new(1)` corresponds to the second local +/// `CoroutineSavedLocal` is indexed in terms of the elements in this set; +/// i.e. `CoroutineSavedLocal::new(1)` corresponds to the second local /// included in this set. -struct GeneratorSavedLocals(BitSet); +struct CoroutineSavedLocals(BitSet); -impl GeneratorSavedLocals { - /// Returns an iterator over each `GeneratorSavedLocal` along with the `Local` it corresponds +impl CoroutineSavedLocals { + /// Returns an iterator over each `CoroutineSavedLocal` along with the `Local` it corresponds /// to. - fn iter_enumerated(&self) -> impl '_ + Iterator { - self.iter().enumerate().map(|(i, l)| (GeneratorSavedLocal::from(i), l)) + fn iter_enumerated(&self) -> impl '_ + Iterator { + self.iter().enumerate().map(|(i, l)| (CoroutineSavedLocal::from(i), l)) } /// Transforms a `BitSet` that contains only locals saved across yield points to the - /// equivalent `BitSet`. - fn renumber_bitset(&self, input: &BitSet) -> BitSet { + /// equivalent `BitSet`. + fn renumber_bitset(&self, input: &BitSet) -> BitSet { assert!(self.superset(&input), "{:?} not a superset of {:?}", self.0, input); let mut out = BitSet::new_empty(self.count()); for (saved_local, local) in self.iter_enumerated() { @@ -726,17 +726,17 @@ impl GeneratorSavedLocals { out } - fn get(&self, local: Local) -> Option { + fn get(&self, local: Local) -> Option { if !self.contains(local) { return None; } let idx = self.iter().take_while(|&l| l < local).count(); - Some(GeneratorSavedLocal::new(idx)) + Some(CoroutineSavedLocal::new(idx)) } } -impl ops::Deref for GeneratorSavedLocals { +impl ops::Deref for CoroutineSavedLocals { type Target = BitSet; fn deref(&self) -> &Self::Target { @@ -747,13 +747,13 @@ impl ops::Deref for GeneratorSavedLocals { /// For every saved local, looks for which locals are StorageLive at the same /// time. Generates a bitset for every local of all the other locals that may be /// StorageLive simultaneously with that local. This is used in the layout -/// computation; see `GeneratorLayout` for more. +/// computation; see `CoroutineLayout` for more. fn compute_storage_conflicts<'mir, 'tcx>( body: &'mir Body<'tcx>, - saved_locals: &GeneratorSavedLocals, + saved_locals: &CoroutineSavedLocals, always_live_locals: BitSet, mut requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'_, 'mir, 'tcx>>, -) -> BitMatrix { +) -> BitMatrix { assert_eq!(body.local_decls.len(), saved_locals.domain_size()); debug!("compute_storage_conflicts({:?})", body.span); @@ -775,7 +775,7 @@ fn compute_storage_conflicts<'mir, 'tcx>( let local_conflicts = visitor.local_conflicts; - // Compress the matrix using only stored locals (Local -> GeneratorSavedLocal). + // Compress the matrix using only stored locals (Local -> CoroutineSavedLocal). // // NOTE: Today we store a full conflict bitset for every local. Technically // this is twice as many bits as we need, since the relation is symmetric. @@ -801,9 +801,9 @@ fn compute_storage_conflicts<'mir, 'tcx>( struct StorageConflictVisitor<'mir, 'tcx, 's> { body: &'mir Body<'tcx>, - saved_locals: &'s GeneratorSavedLocals, + saved_locals: &'s CoroutineSavedLocals, // FIXME(tmandry): Consider using sparse bitsets here once we have good - // benchmarks for generators. + // benchmarks for coroutines. local_conflicts: BitMatrix, } @@ -858,7 +858,7 @@ fn compute_layout<'tcx>( body: &Body<'tcx>, ) -> ( FxHashMap, VariantIdx, FieldIdx)>, - GeneratorLayout<'tcx>, + CoroutineLayout<'tcx>, IndexVec>>, ) { let LivenessInfo { @@ -870,10 +870,10 @@ fn compute_layout<'tcx>( } = liveness; // Gather live local types and their indices. - let mut locals = IndexVec::::new(); - let mut tys = IndexVec::::new(); + let mut locals = IndexVec::::new(); + let mut tys = IndexVec::::new(); for (saved_local, local) in saved_locals.iter_enumerated() { - debug!("generator saved local {:?} => {:?}", saved_local, local); + debug!("coroutine saved local {:?} => {:?}", saved_local, local); locals.push(local); let decl = &body.local_decls[local]; @@ -895,7 +895,7 @@ fn compute_layout<'tcx>( _ => false, }; let decl = - GeneratorSavedTy { ty: decl.ty, source_info: decl.source_info, ignore_for_traits }; + CoroutineSavedTy { ty: decl.ty, source_info: decl.source_info, ignore_for_traits }; debug!(?decl); tys.push(decl); @@ -914,9 +914,9 @@ fn compute_layout<'tcx>( .copied() .collect(); - // Build the generator variant field list. - // Create a map from local indices to generator struct indices. - let mut variant_fields: IndexVec> = + // Build the coroutine variant field list. + // Create a map from local indices to coroutine struct indices. + let mut variant_fields: IndexVec> = iter::repeat(IndexVec::new()).take(RESERVED_VARIANTS).collect(); let mut remap = FxHashMap::default(); for (suspension_point_idx, live_locals) in live_locals_at_suspension_points.iter().enumerate() { @@ -926,7 +926,7 @@ fn compute_layout<'tcx>( fields.push(saved_local); // Note that if a field is included in multiple variants, we will // just use the first one here. That's fine; fields do not move - // around inside generators, so it doesn't matter which variant + // around inside coroutines, so it doesn't matter which variant // index we access them by. let idx = FieldIdx::from_usize(idx); remap.entry(locals[saved_local]).or_insert((tys[saved_local].ty, variant_index, idx)); @@ -934,8 +934,8 @@ fn compute_layout<'tcx>( variant_fields.push(fields); variant_source_info.push(source_info_at_suspension_points[suspension_point_idx]); } - debug!("generator variant_fields = {:?}", variant_fields); - debug!("generator storage_conflicts = {:#?}", storage_conflicts); + debug!("coroutine variant_fields = {:?}", variant_fields); + debug!("coroutine storage_conflicts = {:#?}", storage_conflicts); let mut field_names = IndexVec::from_elem(None, &tys); for var in &body.var_debug_info { @@ -947,7 +947,7 @@ fn compute_layout<'tcx>( field_names.get_or_insert_with(saved_local, || var.name); } - let layout = GeneratorLayout { + let layout = CoroutineLayout { field_tys: tys, field_names, variant_fields, @@ -959,7 +959,7 @@ fn compute_layout<'tcx>( (remap, layout, storage_liveness) } -/// Replaces the entry point of `body` with a block that switches on the generator discriminant and +/// Replaces the entry point of `body` with a block that switches on the coroutine discriminant and /// dispatches to blocks according to `cases`. /// /// After this function, the former entry point of the function will be bb1. @@ -992,14 +992,14 @@ fn insert_switch<'tcx>( } } -fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { +fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { use crate::shim::DropShimElaborator; use rustc_middle::mir::patch::MirPatch; use rustc_mir_dataflow::elaborate_drops::{elaborate_drop, Unwind}; - // Note that `elaborate_drops` only drops the upvars of a generator, and + // Note that `elaborate_drops` only drops the upvars of a coroutine, and // this is ok because `open_drop` can only be reached within that own - // generator's resume function. + // coroutine's resume function. let def_id = body.source.def_id(); let param_env = tcx.param_env(def_id); @@ -1047,7 +1047,7 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { elaborator.patch.apply(body); } -fn create_generator_drop_shim<'tcx>( +fn create_coroutine_drop_shim<'tcx>( tcx: TyCtxt<'tcx>, transform: &TransformVisitor<'tcx>, gen_ty: Ty<'tcx>, @@ -1070,7 +1070,7 @@ fn create_generator_drop_shim<'tcx>( for block in body.basic_blocks_mut() { let kind = &mut block.terminator_mut().kind; - if let TerminatorKind::GeneratorDrop = *kind { + if let TerminatorKind::CoroutineDrop = *kind { *kind = TerminatorKind::Return; } } @@ -1078,9 +1078,9 @@ fn create_generator_drop_shim<'tcx>( // Replace the return variable body.local_decls[RETURN_PLACE] = LocalDecl::with_source_info(Ty::new_unit(tcx), source_info); - make_generator_state_argument_indirect(tcx, &mut body); + make_coroutine_state_argument_indirect(tcx, &mut body); - // Change the generator argument from &mut to *mut + // Change the coroutine argument from &mut to *mut body.local_decls[SELF_ARG] = LocalDecl::with_source_info( Ty::new_ptr(tcx, ty::TypeAndMut { ty: gen_ty, mutbl: hir::Mutability::Mut }), source_info, @@ -1104,10 +1104,10 @@ fn create_generator_drop_shim<'tcx>( None, ); - // Temporary change MirSource to generator's instance so that dump_mir produces more sensible + // Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible // filename. body.source.instance = gen_instance; - dump_mir(tcx, false, "generator_drop", &0, &body, |_, _| Ok(())); + dump_mir(tcx, false, "coroutine_drop", &0, &body, |_, _| Ok(())); body.source.instance = drop_instance; body @@ -1182,7 +1182,7 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool { | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {} @@ -1191,7 +1191,7 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool { TerminatorKind::UnwindResume => {} TerminatorKind::Yield { .. } => { - unreachable!("`can_unwind` called before generator transform") + unreachable!("`can_unwind` called before coroutine transform") } // These may unwind. @@ -1206,7 +1206,7 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool { false } -fn create_generator_resume_function<'tcx>( +fn create_coroutine_resume_function<'tcx>( tcx: TyCtxt<'tcx>, transform: TransformVisitor<'tcx>, body: &mut Body<'tcx>, @@ -1214,7 +1214,7 @@ fn create_generator_resume_function<'tcx>( ) { let can_unwind = can_unwind(tcx, body); - // Poison the generator when it unwinds + // Poison the coroutine when it unwinds if can_unwind { let source_info = SourceInfo::outermost(body.span); let poison_block = body.basic_blocks_mut().push(BasicBlockData { @@ -1253,26 +1253,26 @@ fn create_generator_resume_function<'tcx>( cases.insert(0, (UNRESUMED, START_BLOCK)); // Panic when resumed on the returned or poisoned state - let generator_kind = body.generator_kind().unwrap(); + let coroutine_kind = body.coroutine_kind().unwrap(); if can_unwind { cases.insert( 1, - (POISONED, insert_panic_block(tcx, body, ResumedAfterPanic(generator_kind))), + (POISONED, insert_panic_block(tcx, body, ResumedAfterPanic(coroutine_kind))), ); } if can_return { cases.insert( 1, - (RETURNED, insert_panic_block(tcx, body, ResumedAfterReturn(generator_kind))), + (RETURNED, insert_panic_block(tcx, body, ResumedAfterReturn(coroutine_kind))), ); } insert_switch(body, cases, &transform, TerminatorKind::Unreachable); - make_generator_state_argument_indirect(tcx, body); - make_generator_state_argument_pinned(tcx, body); + make_coroutine_state_argument_indirect(tcx, body); + make_coroutine_state_argument_pinned(tcx, body); // Make sure we remove dead blocks to remove // unrelated code from the drop part of the function @@ -1280,7 +1280,7 @@ fn create_generator_resume_function<'tcx>( pm::run_passes_no_validate(tcx, body, &[&abort_unwinding_calls::AbortUnwindingCalls], None); - dump_mir(tcx, false, "generator_resume", &0, body, |_, _| Ok(())); + dump_mir(tcx, false, "coroutine_resume", &0, body, |_, _| Ok(())); } fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock { @@ -1294,7 +1294,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock { }; let source_info = SourceInfo::outermost(body.span); - // Create a block to destroy an unresumed generators. This can only destroy upvars. + // Create a block to destroy an unresumed coroutines. This can only destroy upvars. body.basic_blocks_mut().push(BasicBlockData { statements: Vec::new(), terminator: Some(Terminator { source_info, kind: term }), @@ -1302,7 +1302,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock { }) } -/// An operation that can be performed on a generator. +/// An operation that can be performed on a coroutine. #[derive(PartialEq, Copy, Clone)] enum Operation { Resume, @@ -1381,64 +1381,64 @@ fn create_cases<'tcx>( } #[instrument(level = "debug", skip(tcx), ret)] -pub(crate) fn mir_generator_witnesses<'tcx>( +pub(crate) fn mir_coroutine_witnesses<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, -) -> Option> { +) -> Option> { let (body, _) = tcx.mir_promoted(def_id); let body = body.borrow(); let body = &*body; - // The first argument is the generator type passed by value + // The first argument is the coroutine type passed by value let gen_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty; // Get the interior types and args which typeck computed let movable = match *gen_ty.kind() { - ty::Generator(_, _, movability) => movability == hir::Movability::Movable, + ty::Coroutine(_, _, movability) => movability == hir::Movability::Movable, ty::Error(_) => return None, - _ => span_bug!(body.span, "unexpected generator type {}", gen_ty), + _ => span_bug!(body.span, "unexpected coroutine type {}", gen_ty), }; - // When first entering the generator, move the resume argument into its new local. + // When first entering the coroutine, move the resume argument into its new local. let always_live_locals = always_storage_live_locals(&body); let liveness_info = locals_live_across_suspend_points(tcx, body, &always_live_locals, movable); // Extract locals which are live across suspension point into `layout` - // `remap` gives a mapping from local indices onto generator struct indices + // `remap` gives a mapping from local indices onto coroutine struct indices // `storage_liveness` tells us which locals have live storage at suspension points - let (_, generator_layout, _) = compute_layout(liveness_info, body); + let (_, coroutine_layout, _) = compute_layout(liveness_info, body); - check_suspend_tys(tcx, &generator_layout, &body); + check_suspend_tys(tcx, &coroutine_layout, &body); - Some(generator_layout) + Some(coroutine_layout) } impl<'tcx> MirPass<'tcx> for StateTransform { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let Some(yield_ty) = body.yield_ty() else { - // This only applies to generators + // This only applies to coroutines return; }; - assert!(body.generator_drop().is_none()); + assert!(body.coroutine_drop().is_none()); - // The first argument is the generator type passed by value + // The first argument is the coroutine type passed by value let gen_ty = body.local_decls.raw[1].ty; // Get the discriminant type and args which typeck computed let (discr_ty, movable) = match *gen_ty.kind() { - ty::Generator(_, args, movability) => { - let args = args.as_generator(); + ty::Coroutine(_, args, movability) => { + let args = args.as_coroutine(); (args.discr_ty(tcx), movability == hir::Movability::Movable) } _ => { - tcx.sess.delay_span_bug(body.span, format!("unexpected generator type {gen_ty}")); + tcx.sess.delay_span_bug(body.span, format!("unexpected coroutine type {gen_ty}")); return; } }; - let is_async_kind = matches!(body.generator_kind(), Some(GeneratorKind::Async(_))); + let is_async_kind = matches!(body.coroutine_kind(), Some(CoroutineKind::Async(_))); let (state_adt_ref, state_args) = if is_async_kind { // Compute Poll let poll_did = tcx.require_lang_item(LangItem::Poll, None); @@ -1446,8 +1446,8 @@ impl<'tcx> MirPass<'tcx> for StateTransform { let poll_args = tcx.mk_args(&[body.return_ty().into()]); (poll_adt_ref, poll_args) } else { - // Compute GeneratorState - let state_did = tcx.require_lang_item(LangItem::GeneratorState, None); + // Compute CoroutineState + let state_did = tcx.require_lang_item(LangItem::CoroutineState, None); let state_adt_ref = tcx.adt_def(state_did); let state_args = tcx.mk_args(&[yield_ty.into(), body.return_ty().into()]); (state_adt_ref, state_args) @@ -1465,8 +1465,8 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // We also replace the resume argument and insert an `Assign`. // This is needed because the resume argument `_2` might be live across a `yield`, in which - // case there is no `Assign` to it that the transform can turn into a store to the generator - // state. After the yield the slot in the generator state would then be uninitialized. + // case there is no `Assign` to it that the transform can turn into a store to the coroutine + // state. After the yield the slot in the coroutine state would then be uninitialized. let resume_local = Local::new(2); let resume_ty = if is_async_kind { Ty::new_task_context(tcx) @@ -1475,7 +1475,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { }; let new_resume_local = replace_local(resume_local, resume_ty, body, tcx); - // When first entering the generator, move the resume argument into its new local. + // When first entering the coroutine, move the resume argument into its new local. let source_info = SourceInfo::outermost(body.span); let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements; stmts.insert( @@ -1495,7 +1495,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { locals_live_across_suspend_points(tcx, body, &always_live_locals, movable); if tcx.sess.opts.unstable_opts.validate_mir { - let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias { + let mut vis = EnsureCoroutineFieldAssignmentsNeverAlias { assigned_local: None, saved_locals: &liveness_info.saved_locals, storage_conflicts: &liveness_info.storage_conflicts, @@ -1505,16 +1505,16 @@ impl<'tcx> MirPass<'tcx> for StateTransform { } // Extract locals which are live across suspension point into `layout` - // `remap` gives a mapping from local indices onto generator struct indices + // `remap` gives a mapping from local indices onto coroutine struct indices // `storage_liveness` tells us which locals have live storage at suspension points let (remap, layout, storage_liveness) = compute_layout(liveness_info, body); let can_return = can_return(tcx, body, tcx.param_env(body.source.def_id())); - // Run the transformation which converts Places from Local to generator struct + // Run the transformation which converts Places from Local to coroutine struct // accesses for locals in `remap`. - // It also rewrites `return x` and `yield y` as writing a new generator state and returning - // either GeneratorState::Complete(x) and GeneratorState::Yielded(y), + // It also rewrites `return x` and `yield y` as writing a new coroutine state and returning + // either CoroutineState::Complete(x) and CoroutineState::Yielded(y), // or Poll::Ready(x) and Poll::Pending respectively depending on `is_async_kind`. let mut transform = TransformVisitor { tcx, @@ -1541,30 +1541,30 @@ impl<'tcx> MirPass<'tcx> for StateTransform { var.argument_index = None; } - body.generator.as_mut().unwrap().yield_ty = None; - body.generator.as_mut().unwrap().generator_layout = Some(layout); + body.coroutine.as_mut().unwrap().yield_ty = None; + body.coroutine.as_mut().unwrap().coroutine_layout = Some(layout); - // Insert `drop(generator_struct)` which is used to drop upvars for generators in + // Insert `drop(coroutine_struct)` which is used to drop upvars for coroutines in // the unresumed state. - // This is expanded to a drop ladder in `elaborate_generator_drops`. + // This is expanded to a drop ladder in `elaborate_coroutine_drops`. let drop_clean = insert_clean_drop(body); - dump_mir(tcx, false, "generator_pre-elab", &0, body, |_, _| Ok(())); + dump_mir(tcx, false, "coroutine_pre-elab", &0, body, |_, _| Ok(())); - // Expand `drop(generator_struct)` to a drop ladder which destroys upvars. + // Expand `drop(coroutine_struct)` to a drop ladder which destroys upvars. // If any upvars are moved out of, drop elaboration will handle upvar destruction. // However we need to also elaborate the code generated by `insert_clean_drop`. - elaborate_generator_drops(tcx, body); + elaborate_coroutine_drops(tcx, body); - dump_mir(tcx, false, "generator_post-transform", &0, body, |_, _| Ok(())); + dump_mir(tcx, false, "coroutine_post-transform", &0, body, |_, _| Ok(())); - // Create a copy of our MIR and use it to create the drop shim for the generator - let drop_shim = create_generator_drop_shim(tcx, &transform, gen_ty, body, drop_clean); + // Create a copy of our MIR and use it to create the drop shim for the coroutine + let drop_shim = create_coroutine_drop_shim(tcx, &transform, gen_ty, body, drop_clean); - body.generator.as_mut().unwrap().generator_drop = Some(drop_shim); + body.coroutine.as_mut().unwrap().coroutine_drop = Some(drop_shim); - // Create the Generator::resume / Future::poll function - create_generator_resume_function(tcx, transform, body, can_return); + // Create the Coroutine::resume / Future::poll function + create_coroutine_resume_function(tcx, transform, body, can_return); // Run derefer to fix Derefs that are not in the first place deref_finder(tcx, body); @@ -1572,25 +1572,25 @@ impl<'tcx> MirPass<'tcx> for StateTransform { } /// Looks for any assignments between locals (e.g., `_4 = _5`) that will both be converted to fields -/// in the generator state machine but whose storage is not marked as conflicting +/// in the coroutine state machine but whose storage is not marked as conflicting /// /// Validation needs to happen immediately *before* `TransformVisitor` is invoked, not after. /// /// This condition would arise when the assignment is the last use of `_5` but the initial /// definition of `_4` if we weren't extra careful to mark all locals used inside a statement as -/// conflicting. Non-conflicting generator saved locals may be stored at the same location within -/// the generator state machine, which would result in ill-formed MIR: the left-hand and right-hand +/// conflicting. Non-conflicting coroutine saved locals may be stored at the same location within +/// the coroutine state machine, which would result in ill-formed MIR: the left-hand and right-hand /// sides of an assignment may not alias. This caused a miscompilation in [#73137]. /// /// [#73137]: https://github.com/rust-lang/rust/issues/73137 -struct EnsureGeneratorFieldAssignmentsNeverAlias<'a> { - saved_locals: &'a GeneratorSavedLocals, - storage_conflicts: &'a BitMatrix, - assigned_local: Option, +struct EnsureCoroutineFieldAssignmentsNeverAlias<'a> { + saved_locals: &'a CoroutineSavedLocals, + storage_conflicts: &'a BitMatrix, + assigned_local: Option, } -impl EnsureGeneratorFieldAssignmentsNeverAlias<'_> { - fn saved_local_for_direct_place(&self, place: Place<'_>) -> Option { +impl EnsureCoroutineFieldAssignmentsNeverAlias<'_> { + fn saved_local_for_direct_place(&self, place: Place<'_>) -> Option { if place.is_indirect() { return None; } @@ -1609,7 +1609,7 @@ impl EnsureGeneratorFieldAssignmentsNeverAlias<'_> { } } -impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> { +impl<'tcx> Visitor<'tcx> for EnsureCoroutineFieldAssignmentsNeverAlias<'_> { fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) { let Some(lhs) = self.assigned_local else { // This visitor only invokes `visit_place` for the right-hand side of an assignment @@ -1624,7 +1624,7 @@ impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> { if !self.storage_conflicts.contains(lhs, rhs) { bug!( - "Assignment between generator saved locals whose storage is not \ + "Assignment between coroutine saved locals whose storage is not \ marked as conflicting: {:?}: {:?} = {:?}", location, lhs, @@ -1691,14 +1691,14 @@ impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> { | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } | TerminatorKind::Assert { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {} } } } -fn check_suspend_tys<'tcx>(tcx: TyCtxt<'tcx>, layout: &GeneratorLayout<'tcx>, body: &Body<'tcx>) { +fn check_suspend_tys<'tcx>(tcx: TyCtxt<'tcx>, layout: &CoroutineLayout<'tcx>, body: &Body<'tcx>) { let mut linted_tys = FxHashSet::default(); // We want a user-facing param-env. diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 9a7adaada09fc..6bab62aa85409 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -147,7 +147,7 @@ impl CoverageGraph { | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } | TerminatorKind::Call { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Assert { .. } | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index f1a0f762041c7..3f7ba5725104a 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -93,7 +93,7 @@ impl CoverageSpan { ) -> Self { let is_closure = match statement.kind { StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => { - matches!(kind, AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _)) + matches!(kind, AggregateKind::Closure(_, _) | AggregateKind::Coroutine(_, _, _)) } _ => false, }; diff --git a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs index 4c20997e6332d..02e2cf6b05e3e 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs @@ -160,7 +160,7 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option { | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Yield { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseUnwind { .. } | TerminatorKind::InlineAsm { .. } => { Some(terminator.source_info.span) diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index 99b070c018e37..15502adfb5aad 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -114,7 +114,7 @@ //! approach that only works for some classes of CFGs: //! - rustc now has a powerful dataflow analysis framework that can handle forwards and backwards //! analyses efficiently. -//! - Layout optimizations for generators have been added to improve code generation for +//! - Layout optimizations for coroutines have been added to improve code generation for //! async/await, which are very similar in spirit to what this optimization does. //! //! Also, rustc now has a simple NRVO pass (see `nrvo.rs`), which handles a subset of the cases that @@ -655,7 +655,7 @@ impl WriteInfo { // `Drop`s create a `&mut` and so are not considered } TerminatorKind::Yield { .. } - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => { bug!("{:?} not found in this MIR phase", terminator) diff --git a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs index d202860840c25..26fcfad828777 100644 --- a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs +++ b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs @@ -58,7 +58,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool { let body_abi = match body_ty.kind() { ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), ty::Closure(..) => Abi::RustCall, - ty::Generator(..) => Abi::Rust, + ty::Coroutine(..) => Abi::Rust, _ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty), }; let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi); diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index c710e460dcb1b..eece7c3e83412 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -383,7 +383,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { AggregateKind::Array(..) | AggregateKind::Tuple | AggregateKind::Closure(..) - | AggregateKind::Generator(..) => FIRST_VARIANT, + | AggregateKind::Coroutine(..) => FIRST_VARIANT, AggregateKind::Adt(_, variant_index, _, _, None) => variant_index, // Do not track unions. AggregateKind::Adt(_, _, _, _, Some(_)) => return None, diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 8f578b696944a..757b2aeca7b50 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -79,10 +79,10 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { if body.source.promoted.is_some() { return false; } - // Avoid inlining into generators, since their `optimized_mir` is used for layout computation, + // Avoid inlining into coroutines, since their `optimized_mir` is used for layout computation, // which can create a cycle, even when no attempt is made to inline the function in the other // direction. - if body.generator.is_some() { + if body.coroutine.is_some() { return false; } @@ -1014,7 +1014,7 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> { } match terminator.kind { - TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => bug!(), + TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => bug!(), TerminatorKind::Goto { ref mut target } => { *target = self.map_block(*target); } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index d579420ecb835..6c0aa51795bdb 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -61,6 +61,7 @@ mod const_goto; mod const_prop; mod const_prop_lint; mod copy_prop; +mod coroutine; mod coverage; mod cross_crate_inline; mod ctfe_limit; @@ -77,7 +78,6 @@ mod elaborate_drops; mod errors; mod ffi_unwind_calls; mod function_item_references; -mod generator; mod gvn; pub mod inline; mod instsimplify; @@ -132,7 +132,7 @@ pub fn provide(providers: &mut Providers) { mir_promoted, mir_drops_elaborated_and_const_checked, mir_for_ctfe, - mir_generator_witnesses: generator::mir_generator_witnesses, + mir_coroutine_witnesses: coroutine::mir_coroutine_witnesses, optimized_mir, is_mir_available, is_ctfe_mir_available: |tcx, did| is_mir_available(tcx, did), @@ -375,8 +375,8 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> { /// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't /// end up missing the source MIR due to stealing happening. fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal> { - if let DefKind::Generator = tcx.def_kind(def) { - tcx.ensure_with_value().mir_generator_witnesses(def); + if let DefKind::Coroutine = tcx.def_kind(def) { + tcx.ensure_with_value().mir_coroutine_witnesses(def); } let mir_borrowck = tcx.mir_borrowck(def); @@ -509,7 +509,7 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late, // but before optimizations begin. &elaborate_box_derefs::ElaborateBoxDerefs, - &generator::StateTransform, + &coroutine::StateTransform, &add_retag::AddRetag, &Lint(const_prop_lint::ConstPropLint), ]; diff --git a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs index 8c48a667786b1..54892442c87b2 100644 --- a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -69,7 +69,7 @@ impl RemoveNoopLandingPads { | TerminatorKind::FalseUnwind { .. } => { terminator.successors().all(|succ| nop_landing_pads.contains(succ)) } - TerminatorKind::GeneratorDrop + TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } | TerminatorKind::Return | TerminatorKind::UnwindTerminate(_) diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs index b4784b69f7f60..5aa3c3cfe4dde 100644 --- a/compiler/rustc_mir_transform/src/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -13,8 +13,8 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts { } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - // Avoid query cycles (generators require optimized MIR for layout). - if tcx.type_of(body.source.def_id()).instantiate_identity().is_generator() { + // Avoid query cycles (coroutines require optimized MIR for layout). + if tcx.type_of(body.source.def_id()).instantiate_identity().is_coroutine() { return; } let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); diff --git a/compiler/rustc_mir_transform/src/separate_const_switch.rs b/compiler/rustc_mir_transform/src/separate_const_switch.rs index e1e4acccccd36..907cfe7581a8d 100644 --- a/compiler/rustc_mir_transform/src/separate_const_switch.rs +++ b/compiler/rustc_mir_transform/src/separate_const_switch.rs @@ -118,7 +118,7 @@ pub fn separate_const_switch(body: &mut Body<'_>) -> usize { | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::InlineAsm { .. } - | TerminatorKind::GeneratorDrop => { + | TerminatorKind::CoroutineDrop => { continue 'predec_iter; } } @@ -169,7 +169,7 @@ pub fn separate_const_switch(body: &mut Body<'_>) -> usize { | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable - | TerminatorKind::GeneratorDrop + | TerminatorKind::CoroutineDrop | TerminatorKind::Assert { .. } | TerminatorKind::FalseUnwind { .. } | TerminatorKind::Drop { .. } diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index e9895d97dfefa..2400cfa21fba8 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -4,7 +4,7 @@ use rustc_hir::lang_items::LangItem; use rustc_middle::mir::*; use rustc_middle::query::Providers; use rustc_middle::ty::GenericArgs; -use rustc_middle::ty::{self, EarlyBinder, GeneratorArgs, Ty, TyCtxt}; +use rustc_middle::ty::{self, CoroutineArgs, EarlyBinder, Ty, TyCtxt}; use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT}; use rustc_index::{Idx, IndexVec}; @@ -67,10 +67,10 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' } ty::InstanceDef::DropGlue(def_id, ty) => { - // FIXME(#91576): Drop shims for generators aren't subject to the MIR passes at the end + // FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end // of this function. Is this intentional? - if let Some(ty::Generator(gen_def_id, args, _)) = ty.map(Ty::kind) { - let body = tcx.optimized_mir(*gen_def_id).generator_drop().unwrap(); + if let Some(ty::Coroutine(gen_def_id, args, _)) = ty.map(Ty::kind) { + let body = tcx.optimized_mir(*gen_def_id).coroutine_drop().unwrap(); let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args); debug!("make_shim({:?}) = {:?}", instance, body); @@ -171,7 +171,7 @@ fn local_decls_for_sig<'tcx>( fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) -> Body<'tcx> { debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty); - assert!(!matches!(ty, Some(ty) if ty.is_generator())); + assert!(!matches!(ty, Some(ty) if ty.is_coroutine())); let args = if let Some(ty) = ty { tcx.mk_args(&[ty.into()]) @@ -392,8 +392,8 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - _ if is_copy => builder.copy_shim(), ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()), ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()), - ty::Generator(gen_def_id, args, hir::Movability::Movable) => { - builder.generator_shim(dest, src, *gen_def_id, args.as_generator()) + ty::Coroutine(gen_def_id, args, hir::Movability::Movable) => { + builder.coroutine_shim(dest, src, *gen_def_id, args.as_coroutine()) } _ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty), }; @@ -593,12 +593,12 @@ impl<'tcx> CloneShimBuilder<'tcx> { let _final_cleanup_block = self.clone_fields(dest, src, target, unwind, tys); } - fn generator_shim( + fn coroutine_shim( &mut self, dest: Place<'tcx>, src: Place<'tcx>, gen_def_id: DefId, - args: GeneratorArgs<'tcx>, + args: CoroutineArgs<'tcx>, ) { self.block(vec![], TerminatorKind::Goto { target: self.block_index_offset(3) }, false); let unwind = self.block(vec![], TerminatorKind::UnwindResume, true); diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index c21b1724cbb67..427cc1e192413 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -20,8 +20,8 @@ impl<'tcx> MirPass<'tcx> for ScalarReplacementOfAggregates { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); - // Avoid query cycles (generators require optimized MIR for layout). - if tcx.type_of(body.source.def_id()).instantiate_identity().is_generator() { + // Avoid query cycles (coroutines require optimized MIR for layout). + if tcx.type_of(body.source.def_id()).instantiate_identity().is_coroutine() { return; } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index eb1c7db026e19..82fee7c8dfe58 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -855,7 +855,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { | mir::TerminatorKind::UnwindResume | mir::TerminatorKind::Return | mir::TerminatorKind::Unreachable => {} - mir::TerminatorKind::GeneratorDrop + mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } | mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => bug!(), diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 6c206a6bac8bd..a3b35eab46581 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -131,7 +131,7 @@ fn mark_used_by_default_parameters<'tcx>( unused_parameters: &mut UnusedGenericParams, ) { match tcx.def_kind(def_id) { - DefKind::Closure | DefKind::Generator => { + DefKind::Closure | DefKind::Coroutine => { for param in &generics.params { debug!(?param, "(closure/gen)"); unused_parameters.mark_used(param.index); @@ -227,7 +227,7 @@ struct MarkUsedGenericParams<'a, 'tcx> { impl<'a, 'tcx> MarkUsedGenericParams<'a, 'tcx> { /// Invoke `unused_generic_params` on a body contained within the current item (e.g. - /// a closure, generator or constant). + /// a closure, coroutine or constant). #[instrument(level = "debug", skip(self, def_id, args))] fn visit_child_body(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) { let instance = ty::InstanceDef::Item(def_id); @@ -248,8 +248,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) { if local == Local::from_usize(1) { let def_kind = self.tcx.def_kind(self.def_id); - if matches!(def_kind, DefKind::Closure | DefKind::Generator) { - // Skip visiting the closure/generator that is currently being processed. This only + if matches!(def_kind, DefKind::Closure | DefKind::Coroutine) { + // Skip visiting the closure/coroutine that is currently being processed. This only // happens because the first argument to the closure is a reference to itself and // that will call `visit_args`, resulting in each generic parameter captured being // considered used by default. @@ -319,14 +319,14 @@ impl<'a, 'tcx> TypeVisitor> for MarkUsedGenericParams<'a, 'tcx> { } match *ty.kind() { - ty::Closure(def_id, args) | ty::Generator(def_id, args, ..) => { + ty::Closure(def_id, args) | ty::Coroutine(def_id, args, ..) => { debug!(?def_id); - // Avoid cycle errors with generators. + // Avoid cycle errors with coroutines. if def_id == self.def_id { return ControlFlow::Continue(()); } - // Consider any generic parameters used by any closures/generators as used in the + // Consider any generic parameters used by any closures/coroutines as used in the // parent. self.visit_child_body(def_id, args); ControlFlow::Continue(()) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 75e3393aa9658..9f8361a4b1ee2 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -39,7 +39,7 @@ use rustc_errors::{ use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; -use rustc_span::{Span, SpanSnippetError, Symbol, DUMMY_SP}; +use rustc_span::{BytePos, Span, SpanSnippetError, Symbol, DUMMY_SP}; use std::mem::take; use std::ops::{Deref, DerefMut}; use thin_vec::{thin_vec, ThinVec}; @@ -648,6 +648,26 @@ impl<'a> Parser<'a> { ); } + if let token::DocComment(kind, style, _) = self.token.kind { + // We have something like `expr //!val` where the user likely meant `expr // !val` + let pos = self.token.span.lo() + BytePos(2); + let span = self.token.span.with_lo(pos).with_hi(pos); + err.span_suggestion_verbose( + span, + format!( + "add a space before {} to write a regular comment", + match (kind, style) { + (token::CommentKind::Line, ast::AttrStyle::Inner) => "`!`", + (token::CommentKind::Block, ast::AttrStyle::Inner) => "`!`", + (token::CommentKind::Line, ast::AttrStyle::Outer) => "the last `/`", + (token::CommentKind::Block, ast::AttrStyle::Outer) => "the last `*`", + }, + ), + " ".to_string(), + Applicability::MachineApplicable, + ); + } + // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens // there are unclosed angle brackets if self.unmatched_angle_bracket_count > 0 diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 44cb90227e7e3..5157106f4e269 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1848,7 +1848,7 @@ impl<'a> Parser<'a> { let lo = self.prev_token.span; let kind = ExprKind::Yield(self.parse_expr_opt()?); let span = lo.to(self.prev_token.span); - self.sess.gated_spans.gate(sym::generators, span); + self.sess.gated_spans.gate(sym::coroutines, span); let expr = self.mk_expr(span, kind); self.maybe_recover_from_bad_qpath(expr) } diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index e2f59cb207189..8e3c45686948d 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -632,23 +632,6 @@ impl<'a> Parser<'a> { // Recover from parser, skip type error to avoid extra errors. Ok(true) => true, Err(mut e) => { - if let TokenKind::DocComment(..) = self.token.kind - && let Ok(snippet) = self.span_to_snippet(self.token.span) - { - let sp = self.token.span; - let marker = &snippet[..3]; - let (comment_marker, doc_comment_marker) = marker.split_at(2); - - e.span_suggestion( - sp.with_hi(sp.lo() + BytePos(marker.len() as u32)), - format!( - "add a space before `{doc_comment_marker}` to use a regular comment", - ), - format!("{comment_marker} {doc_comment_marker}"), - Applicability::MaybeIncorrect, - ); - } - if self.recover_colon_as_semi() { // recover_colon_as_semi has already emitted a nicer error. e.delay_as_bug(); diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 7e83724391836..2aec4ea7ef134 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -149,7 +149,7 @@ impl<'tcx> LanguageItemCollector<'tcx> { // Now check whether the lang_item has the expected number of generic // arguments. Generally speaking, binary and indexing operations have // one (for the RHS/index), unary operations have none, the closure - // traits have one for the argument list, generators have one for the + // traits have one for the argument list, coroutines have one for the // resume argument, and ordering/equality relations have one for the RHS // Some other types like Box and various functions like drop_in_place // have minimum requirements. diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 1fe44b2b87727..d068fe62473cd 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -706,7 +706,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // // When computing the liveness for captured variables we take into // account how variable is captured (ByRef vs ByValue) and what is the - // closure kind (Generator / FnOnce vs Fn / FnMut). + // closure kind (Coroutine / FnOnce vs Fn / FnMut). // // Variables captured by reference are assumed to be used on the exit // from the closure. @@ -752,7 +752,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { ty::ClosureKind::FnMut => {} ty::ClosureKind::FnOnce => return succ, }, - ty::Generator(..) => return succ, + ty::Coroutine(..) => return succ, _ => { span_bug!( body.value.span, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 5599c6100a54d..f2d6a0dff9c38 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -188,7 +188,7 @@ where | ty::Foreign(def_id) | ty::FnDef(def_id, ..) | ty::Closure(def_id, ..) - | ty::Generator(def_id, ..) => { + | ty::Coroutine(def_id, ..) => { self.def_id_visitor.visit_def_id(def_id, "type", &ty)?; if V::SHALLOW { return ControlFlow::Continue(()); @@ -294,7 +294,7 @@ where | ty::Param(..) | ty::Bound(..) | ty::Error(_) - | ty::GeneratorWitness(..) => {} + | ty::CoroutineWitness(..) => {} ty::Placeholder(..) | ty::Infer(..) => { bug!("unexpected type: {:?}", ty) } @@ -666,7 +666,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { | DefKind::GlobalAsm | DefKind::Impl { .. } | DefKind::Closure - | DefKind::Generator => (), + | DefKind::Coroutine => (), } } } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index a18109574feb5..0407db528af68 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -981,7 +981,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { | DefKind::GlobalAsm | DefKind::Closure | DefKind::Impl { .. } - | DefKind::Generator, + | DefKind::Coroutine, _, ) | Res::Local(..) diff --git a/compiler/rustc_session/src/code_stats.rs b/compiler/rustc_session/src/code_stats.rs index df81e1f8305ea..f792b8f2cdd5c 100644 --- a/compiler/rustc_session/src/code_stats.rs +++ b/compiler/rustc_session/src/code_stats.rs @@ -24,7 +24,7 @@ pub enum SizeKind { pub enum FieldKind { AdtField, Upvar, - GeneratorLocal, + CoroutineLocal, } impl std::fmt::Display for FieldKind { @@ -32,7 +32,7 @@ impl std::fmt::Display for FieldKind { match self { FieldKind::AdtField => write!(w, "field"), FieldKind::Upvar => write!(w, "upvar"), - FieldKind::GeneratorLocal => write!(w, "local"), + FieldKind::CoroutineLocal => write!(w, "local"), } } } @@ -52,7 +52,7 @@ pub enum DataTypeKind { Union, Enum, Closure, - Generator, + Coroutine, } #[derive(PartialEq, Eq, Hash, Debug)] @@ -105,9 +105,9 @@ impl CodeStats { // Sort variants so the largest ones are shown first. A stable sort is // used here so that source code order is preserved for all variants // that have the same size. - // Except for Generators, whose variants are already sorted according to - // their yield points in `variant_info_for_generator`. - if kind != DataTypeKind::Generator { + // Except for Coroutines, whose variants are already sorted according to + // their yield points in `variant_info_for_coroutine`. + if kind != DataTypeKind::Coroutine { variants.sort_by_key(|info| cmp::Reverse(info.size)); } let info = TypeSizeInfo { @@ -160,7 +160,7 @@ impl CodeStats { let struct_like = match kind { DataTypeKind::Struct | DataTypeKind::Closure => true, - DataTypeKind::Enum | DataTypeKind::Union | DataTypeKind::Generator => false, + DataTypeKind::Enum | DataTypeKind::Union | DataTypeKind::Coroutine => false, }; for (i, variant_info) in variants.into_iter().enumerate() { let VariantInfo { ref name, kind: _, align: _, size, ref fields } = *variant_info; diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index 5ea805e5739b5..61227e5d38fdd 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -59,8 +59,8 @@ impl<'tcx> Tables<'tcx> { stable_mir::ty::ClosureDef(self.create_def_id(did)) } - pub fn generator_def(&mut self, did: DefId) -> stable_mir::ty::GeneratorDef { - stable_mir::ty::GeneratorDef(self.create_def_id(did)) + pub fn coroutine_def(&mut self, did: DefId) -> stable_mir::ty::CoroutineDef { + stable_mir::ty::CoroutineDef(self.create_def_id(did)) } pub fn alias_def(&mut self, did: DefId) -> stable_mir::ty::AliasDef { diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 94dc15b4767c1..8a1b6b6bfe9ea 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -768,11 +768,11 @@ impl<'tcx> Stable<'tcx> for mir::AssertMessage<'tcx> { AssertKind::RemainderByZero(op) => { stable_mir::mir::AssertMessage::RemainderByZero(op.stable(tables)) } - AssertKind::ResumedAfterReturn(generator) => { - stable_mir::mir::AssertMessage::ResumedAfterReturn(generator.stable(tables)) + AssertKind::ResumedAfterReturn(coroutine) => { + stable_mir::mir::AssertMessage::ResumedAfterReturn(coroutine.stable(tables)) } - AssertKind::ResumedAfterPanic(generator) => { - stable_mir::mir::AssertMessage::ResumedAfterPanic(generator.stable(tables)) + AssertKind::ResumedAfterPanic(coroutine) => { + stable_mir::mir::AssertMessage::ResumedAfterPanic(coroutine.stable(tables)) } AssertKind::MisalignedPointerDereference { required, found } => { stable_mir::mir::AssertMessage::MisalignedPointerDereference { @@ -849,9 +849,9 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { generic_arg.stable(tables), ) } - mir::AggregateKind::Generator(def_id, generic_arg, movability) => { - stable_mir::mir::AggregateKind::Generator( - tables.generator_def(*def_id), + mir::AggregateKind::Coroutine(def_id, generic_arg, movability) => { + stable_mir::mir::AggregateKind::Coroutine( + tables.coroutine_def(*def_id), generic_arg.stable(tables), movability.stable(tables), ) @@ -860,20 +860,20 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { } } -impl<'tcx> Stable<'tcx> for rustc_hir::GeneratorKind { - type T = stable_mir::mir::GeneratorKind; +impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind { + type T = stable_mir::mir::CoroutineKind; fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { - use rustc_hir::{AsyncGeneratorKind, GeneratorKind}; + use rustc_hir::{AsyncCoroutineKind, CoroutineKind}; match self { - GeneratorKind::Async(async_gen) => { + CoroutineKind::Async(async_gen) => { let async_gen = match async_gen { - AsyncGeneratorKind::Block => stable_mir::mir::AsyncGeneratorKind::Block, - AsyncGeneratorKind::Closure => stable_mir::mir::AsyncGeneratorKind::Closure, - AsyncGeneratorKind::Fn => stable_mir::mir::AsyncGeneratorKind::Fn, + AsyncCoroutineKind::Block => stable_mir::mir::AsyncCoroutineKind::Block, + AsyncCoroutineKind::Closure => stable_mir::mir::AsyncCoroutineKind::Closure, + AsyncCoroutineKind::Fn => stable_mir::mir::AsyncCoroutineKind::Fn, }; - stable_mir::mir::GeneratorKind::Async(async_gen) + stable_mir::mir::CoroutineKind::Async(async_gen) } - GeneratorKind::Gen => stable_mir::mir::GeneratorKind::Gen, + CoroutineKind::Coroutine => stable_mir::mir::CoroutineKind::Coroutine, } } } @@ -976,7 +976,7 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> { unwind: unwind.stable(tables), }, mir::TerminatorKind::Yield { .. } - | mir::TerminatorKind::GeneratorDrop + | mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => unreachable!(), } @@ -1231,8 +1231,8 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { tables.closure_def(*def_id), generic_args.stable(tables), )), - ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator( - tables.generator_def(*def_id), + ty::Coroutine(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Coroutine( + tables.coroutine_def(*def_id), generic_args.stable(tables), movability.stable(tables), )), @@ -1247,7 +1247,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { ty::Bound(debruijn_idx, bound_ty) => { TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables)) } - ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) | ty::Error(_) => { + ty::Placeholder(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => { unreachable!(); } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index be8c65862dc2e..5b58cf8b6d629 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -591,6 +591,10 @@ symbols! { core_panic_2015_macro, core_panic_2021_macro, core_panic_macro, + coroutine, + coroutine_clone, + coroutine_state, + coroutines, cosf32, cosf64, count, @@ -815,9 +819,7 @@ symbols! { ge, gen_future, gen_kill, - generator, generator_clone, - generator_state, generators, generic_arg_infer, generic_assert, diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 5290da9a25b90..5f22b89ea492f 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -214,7 +214,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { ty::FnDef(def_id, args) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Closure(def_id, args) - | ty::Generator(def_id, args, _) => self.print_def_path(def_id, args), + | ty::Coroutine(def_id, args, _) => self.print_def_path(def_id, args), // The `pretty_print_type` formatting of array size depends on // -Zverbose flag, so we cannot reuse it here. @@ -284,7 +284,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { // Similar to `pretty_path_qualified`, but for the other // types that are printed as paths (see `print_type` above). match self_ty.kind() { - ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Generator(..) + ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Coroutine(..) if trait_ref.is_none() => { self.print_type(self_ty) diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 6ade2d777c741..7b4ab67a24dfa 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -238,7 +238,7 @@ fn compute_symbol_name<'tcx>( // and we want to be sure to avoid any symbol conflicts here. let is_globally_shared_function = matches!( tcx.def_kind(instance.def_id()), - DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator | DefKind::Ctor(..) + DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine | DefKind::Ctor(..) ) && matches!( MonoItem::Fn(instance).instantiation_mode(tcx), InstantiationMode::GloballyShared { may_conflict: true } diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 6ad3e7155e825..5ce188488ce59 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -639,7 +639,7 @@ fn encode_ty<'tcx>( typeid.push_str(&s); } - ty::Generator(def_id, args, ..) => { + ty::Coroutine(def_id, args, ..) => { // u[IE], where is , // as vendor extended type. let mut s = String::new(); @@ -648,7 +648,7 @@ fn encode_ty<'tcx>( // Encode parent args only s.push_str(&encode_args( tcx, - tcx.mk_args(args.as_generator().parent_args()), + tcx.mk_args(args.as_coroutine().parent_args()), dict, options, )); @@ -719,7 +719,7 @@ fn encode_ty<'tcx>( ty::Alias(..) | ty::Bound(..) | ty::Error(..) - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::Infer(..) | ty::Placeholder(..) => { bug!("encode_ty: unexpected `{:?}`", ty.kind()); @@ -778,7 +778,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio | ty::Str | ty::Never | ty::Foreign(..) - | ty::GeneratorWitness(..) => {} + | ty::CoroutineWitness(..) => {} ty::Bool => { if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) { @@ -892,8 +892,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio ty = Ty::new_closure(tcx, *def_id, transform_args(tcx, args, options)); } - ty::Generator(def_id, args, movability) => { - ty = Ty::new_generator(tcx, *def_id, transform_args(tcx, args, options), *movability); + ty::Coroutine(def_id, args, movability) => { + ty = Ty::new_coroutine(tcx, *def_id, transform_args(tcx, args, options), *movability); } ty::Ref(region, ty0, ..) => { diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 99c5d0164399b..89b8b1518b077 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -427,7 +427,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { | ty::FnDef(def_id, args) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Closure(def_id, args) - | ty::Generator(def_id, args, _) => { + | ty::Coroutine(def_id, args, _) => { self = self.print_def_path(def_id, args)?; } ty::Foreign(def_id) => { @@ -476,7 +476,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { ty::Alias(ty::Inherent, _) => bug!("symbol_names: unexpected inherent projection"), ty::Alias(ty::Weak, _) => bug!("symbol_names: unexpected weak projection"), - ty::GeneratorWitness(..) => bug!("symbol_names: unexpected `GeneratorWitness`"), + ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"), } // Only cache types that do not refer to an enclosing diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index 23d2c0c4ea095..0c214ca875382 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -191,18 +191,18 @@ pub(super) trait GoalKind<'tcx>: goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx>; - /// A generator (that comes from an `async` desugaring) is known to implement - /// `Future`, where `O` is given by the generator's return type + /// A coroutine (that comes from an `async` desugaring) is known to implement + /// `Future`, where `O` is given by the coroutine's return type /// that was computed during type-checking. fn consider_builtin_future_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx>; - /// A generator (that doesn't come from an `async` desugaring) is known to - /// implement `Generator`, given the resume, yield, - /// and return types of the generator computed during type-checking. - fn consider_builtin_generator_candidate( + /// A coroutine (that doesn't come from an `async` desugaring) is known to + /// implement `Coroutine`, given the resume, yield, + /// and return types of the coroutine computed during type-checking. + fn consider_builtin_coroutine_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx>; @@ -410,7 +410,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { | ty::FnPtr(_) | ty::Dynamic(_, _, _) | ty::Closure(_, _) - | ty::Generator(_, _, _) + | ty::Coroutine(_, _, _) | ty::Never | ty::Tuple(_) => { let simp = @@ -467,9 +467,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ty::Alias(_, _) | ty::Placeholder(..) | ty::Error(_) => (), // FIXME: These should ideally not exist as a self type. It would be nice for - // the builtin auto trait impls of generators to instead directly recurse + // the builtin auto trait impls of coroutines to instead directly recurse // into the witness. - ty::GeneratorWitness(..) => (), + ty::CoroutineWitness(..) => (), // These variants should not exist as a self type. ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) @@ -553,7 +553,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { } else if lang_items.future_trait() == Some(trait_def_id) { G::consider_builtin_future_candidate(self, goal) } else if lang_items.gen_trait() == Some(trait_def_id) { - G::consider_builtin_generator_candidate(self, goal) + G::consider_builtin_coroutine_candidate(self, goal) } else if lang_items.discriminant_kind_trait() == Some(trait_def_id) { G::consider_builtin_discriminant_kind_candidate(self, goal) } else if lang_items.destruct_trait() == Some(trait_def_id) { @@ -620,8 +620,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { | ty::FnPtr(_) | ty::Dynamic(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Param(_) @@ -776,8 +776,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { | ty::FnPtr(_) | ty::Alias(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Param(_) diff --git a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs index 26c68acddffef..d655a4106b861 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs @@ -12,7 +12,7 @@ use crate::solve::EvalCtxt; // Calculates the constituent types of a type for `auto trait` purposes. // -// For types with an "existential" binder, i.e. generator witnesses, we also +// For types with an "existential" binder, i.e. coroutine witnesses, we also // instantiate the binder with placeholders eagerly. pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>( ecx: &EvalCtxt<'_, 'tcx>, @@ -56,14 +56,14 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>( ty::Closure(_, ref args) => Ok(vec![args.as_closure().tupled_upvars_ty()]), - ty::Generator(_, ref args, _) => { - let generator_args = args.as_generator(); - Ok(vec![generator_args.tupled_upvars_ty(), generator_args.witness()]) + ty::Coroutine(_, ref args, _) => { + let coroutine_args = args.as_coroutine(); + Ok(vec![coroutine_args.tupled_upvars_ty(), coroutine_args.witness()]) } - ty::GeneratorWitness(def_id, args) => Ok(ecx + ty::CoroutineWitness(def_id, args) => Ok(ecx .tcx() - .generator_hidden_types(def_id) + .coroutine_hidden_types(def_id) .map(|bty| { ecx.instantiate_binder_with_placeholders(replace_erased_lifetimes_with_bound_vars( tcx, @@ -122,8 +122,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>( | ty::RawPtr(..) | ty::Char | ty::Ref(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Array(..) | ty::Closure(..) | ty::Never @@ -174,7 +174,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( ty::Dynamic(..) | ty::Str | ty::Slice(_) - | ty::Generator(_, _, Movability::Static) + | ty::Coroutine(_, _, Movability::Static) | ty::Foreign(..) | ty::Ref(_, _, Mutability::Mut) | ty::Adt(_, _) @@ -191,18 +191,18 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]), - ty::Generator(_, args, Movability::Movable) => { - if ecx.tcx().features().generator_clone { - let generator = args.as_generator(); - Ok(vec![generator.tupled_upvars_ty(), generator.witness()]) + ty::Coroutine(_, args, Movability::Movable) => { + if ecx.tcx().features().coroutine_clone { + let coroutine = args.as_coroutine(); + Ok(vec![coroutine.tupled_upvars_ty(), coroutine.witness()]) } else { Err(NoSolution) } } - ty::GeneratorWitness(def_id, args) => Ok(ecx + ty::CoroutineWitness(def_id, args) => Ok(ecx .tcx() - .generator_hidden_types(def_id) + .coroutine_hidden_types(def_id) .map(|bty| { ecx.instantiate_binder_with_placeholders(replace_erased_lifetimes_with_bound_vars( ecx.tcx(), @@ -275,8 +275,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<'tcx>( | ty::RawPtr(_) | ty::Ref(_, _, _) | ty::Dynamic(_, _, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Alias(_, _) diff --git a/compiler/rustc_trait_selection/src/solve/canonicalize.rs b/compiler/rustc_trait_selection/src/solve/canonicalize.rs index aa92b924ef2e5..19f0c9fe826d5 100644 --- a/compiler/rustc_trait_selection/src/solve/canonicalize.rs +++ b/compiler/rustc_trait_selection/src/solve/canonicalize.rs @@ -329,8 +329,8 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { | ty::FnPtr(_) | ty::Dynamic(_, _, _) | ty::Closure(_, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Alias(_, _) diff --git a/compiler/rustc_trait_selection/src/solve/project_goals/mod.rs b/compiler/rustc_trait_selection/src/solve/project_goals/mod.rs index 73c8d0c85ddaf..4950a444ffb50 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals/mod.rs @@ -392,8 +392,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { | ty::FnPtr(..) | ty::Closure(..) | ty::Infer(ty::IntVar(..) | ty::FloatVar(..)) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Foreign(..) => tcx.types.unit, @@ -459,17 +459,17 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { let self_ty = goal.predicate.self_ty(); - let ty::Generator(def_id, args, _) = *self_ty.kind() else { + let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { return Err(NoSolution); }; - // Generators are not futures unless they come from `async` desugaring + // Coroutines are not futures unless they come from `async` desugaring let tcx = ecx.tcx(); - if !tcx.generator_is_async(def_id) { + if !tcx.coroutine_is_async(def_id) { return Err(NoSolution); } - let term = args.as_generator().return_ty().into(); + let term = args.as_coroutine().return_ty().into(); Self::consider_implied_clause( ecx, @@ -480,35 +480,35 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { } .to_predicate(tcx), // Technically, we need to check that the future type is Sized, - // but that's already proven by the generator being WF. + // but that's already proven by the coroutine being WF. [], ) } - fn consider_builtin_generator_candidate( + fn consider_builtin_coroutine_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { let self_ty = goal.predicate.self_ty(); - let ty::Generator(def_id, args, _) = *self_ty.kind() else { + let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { return Err(NoSolution); }; - // `async`-desugared generators do not implement the generator trait + // `async`-desugared coroutines do not implement the coroutine trait let tcx = ecx.tcx(); - if tcx.generator_is_async(def_id) { + if tcx.coroutine_is_async(def_id) { return Err(NoSolution); } - let generator = args.as_generator(); + let coroutine = args.as_coroutine(); let name = tcx.associated_item(goal.predicate.def_id()).name; let term = if name == sym::Return { - generator.return_ty().into() + coroutine.return_ty().into() } else if name == sym::Yield { - generator.yield_ty().into() + coroutine.yield_ty().into() } else { - bug!("unexpected associated item `<{self_ty} as Generator>::{name}`") + bug!("unexpected associated item `<{self_ty} as Coroutine>::{name}`") }; Self::consider_implied_clause( @@ -518,13 +518,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { projection_ty: ty::AliasTy::new( ecx.tcx(), goal.predicate.def_id(), - [self_ty, generator.resume_ty()], + [self_ty, coroutine.resume_ty()], ), term, } .to_predicate(tcx), // Technically, we need to check that the future type is Sized, - // but that's already proven by the generator being WF. + // but that's already proven by the coroutine being WF. [], ) } @@ -561,8 +561,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { | ty::FnPtr(..) | ty::Closure(..) | ty::Infer(ty::IntVar(..) | ty::FloatVar(..)) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Foreign(..) | ty::Adt(_, _) diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index d87e05ad02f36..fa91a125b6acc 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -319,23 +319,23 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { return Err(NoSolution); } - let ty::Generator(def_id, _, _) = *goal.predicate.self_ty().kind() else { + let ty::Coroutine(def_id, _, _) = *goal.predicate.self_ty().kind() else { return Err(NoSolution); }; - // Generators are not futures unless they come from `async` desugaring + // Coroutines are not futures unless they come from `async` desugaring let tcx = ecx.tcx(); - if !tcx.generator_is_async(def_id) { + if !tcx.coroutine_is_async(def_id) { return Err(NoSolution); } - // Async generator unconditionally implement `Future` + // Async coroutine unconditionally implement `Future` // Technically, we need to check that the future output type is Sized, - // but that's already proven by the generator being WF. + // but that's already proven by the coroutine being WF. ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } - fn consider_builtin_generator_candidate( + fn consider_builtin_coroutine_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { @@ -344,24 +344,24 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { } let self_ty = goal.predicate.self_ty(); - let ty::Generator(def_id, args, _) = *self_ty.kind() else { + let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { return Err(NoSolution); }; - // `async`-desugared generators do not implement the generator trait + // `async`-desugared coroutines do not implement the coroutine trait let tcx = ecx.tcx(); - if tcx.generator_is_async(def_id) { + if tcx.coroutine_is_async(def_id) { return Err(NoSolution); } - let generator = args.as_generator(); + let coroutine = args.as_coroutine(); Self::consider_implied_clause( ecx, goal, - ty::TraitRef::new(tcx, goal.predicate.def_id(), [self_ty, generator.resume_ty()]) + ty::TraitRef::new(tcx, goal.predicate.def_id(), [self_ty, coroutine.resume_ty()]) .to_predicate(tcx), - // Technically, we need to check that the generator types are Sized, - // but that's already proven by the generator being WF. + // Technically, we need to check that the coroutine types are Sized, + // but that's already proven by the coroutine being WF. [], ) } @@ -844,10 +844,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ty::Infer(_) | ty::Bound(_, _) => bug!("unexpected type `{self_ty}`"), - // Generators have one special built-in candidate, `Unpin`, which + // Coroutines have one special built-in candidate, `Unpin`, which // takes precedence over the structural auto trait candidate being // assembled. - ty::Generator(_, _, movability) + ty::Coroutine(_, _, movability) if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() => { match movability { @@ -879,8 +879,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { | ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Adt(_, _) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index acab4498a0985..29b0c7189f937 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -817,7 +817,7 @@ where } } ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), - ty::Closure(did, ..) | ty::Generator(did, ..) => { + ty::Closure(did, ..) | ty::Coroutine(did, ..) => { if self.def_id_is_local(did) { ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) } else { @@ -827,7 +827,7 @@ where // This should only be created when checking whether we have to check whether some // auto trait impl applies. There will never be multiple impls, so we can just // act as if it were a local type here. - ty::GeneratorWitness(..) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), + ty::CoroutineWitness(..) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), ty::Alias(ty::Opaque, ..) => { // This merits some explanation. // Normally, opaque types are not involved when performing diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 9c9b78f415238..016c44c20f65a 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -102,7 +102,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let node = hir.find(hir_id)?; match &node { hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) => { - self.describe_generator(*body_id).or_else(|| { + self.describe_coroutine(*body_id).or_else(|| { Some(match sig.header { hir::FnHeader { asyncness: hir::IsAsync::Async(_), .. } => { "an async function" @@ -114,11 +114,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(body_id)), .. - }) => self.describe_generator(*body_id).or_else(|| Some("a trait method")), + }) => self.describe_coroutine(*body_id).or_else(|| Some("a trait method")), hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(sig, body_id), .. - }) => self.describe_generator(*body_id).or_else(|| { + }) => self.describe_coroutine(*body_id).or_else(|| { Some(match sig.header { hir::FnHeader { asyncness: hir::IsAsync::Async(_), .. } => "an async method", _ => "a method", @@ -127,7 +127,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(hir::Closure { body, movability, .. }), .. - }) => self.describe_generator(*body).or_else(|| { + }) => self.describe_coroutine(*body).or_else(|| { Some(if movability.is_some() { "an async closure" } else { "a closure" }) }), hir::Node::Expr(hir::Expr { .. }) => { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 66529b67c17b3..86328cb78abbb 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -22,7 +22,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::is_range_literal; use rustc_hir::lang_items::LangItem; -use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node}; +use rustc_hir::{AsyncCoroutineKind, CoroutineKind, Node}; use rustc_hir::{Expr, HirId}; use rustc_infer::infer::error_reporting::TypeErrCtxt; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; @@ -47,37 +47,37 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths}; #[derive(Debug)] -pub enum GeneratorInteriorOrUpvar { +pub enum CoroutineInteriorOrUpvar { // span of interior type Interior(Span, Option<(Span, Option)>), // span of upvar Upvar(Span), } -// This type provides a uniform interface to retrieve data on generators, whether it originated from +// This type provides a uniform interface to retrieve data on coroutines, whether it originated from // the local crate being compiled or from a foreign crate. #[derive(Debug)] -struct GeneratorData<'tcx, 'a>(&'a TypeckResults<'tcx>); +struct CoroutineData<'tcx, 'a>(&'a TypeckResults<'tcx>); -impl<'tcx, 'a> GeneratorData<'tcx, 'a> { - /// Try to get information about variables captured by the generator that matches a type we are +impl<'tcx, 'a> CoroutineData<'tcx, 'a> { + /// Try to get information about variables captured by the coroutine that matches a type we are /// looking for with `ty_matches` function. We uses it to find upvar which causes a failure to /// meet an obligation fn try_get_upvar_span( &self, infer_context: &InferCtxt<'tcx>, - generator_did: DefId, + coroutine_did: DefId, ty_matches: F, - ) -> Option + ) -> Option where F: Fn(ty::Binder<'tcx, Ty<'tcx>>) -> bool, { - infer_context.tcx.upvars_mentioned(generator_did).and_then(|upvars| { + infer_context.tcx.upvars_mentioned(coroutine_did).and_then(|upvars| { upvars.iter().find_map(|(upvar_id, upvar)| { let upvar_ty = self.0.node_type(*upvar_id); let upvar_ty = infer_context.resolve_vars_if_possible(upvar_ty); ty_matches(ty::Binder::dummy(upvar_ty)) - .then(|| GeneratorInteriorOrUpvar::Upvar(upvar.span)) + .then(|| CoroutineInteriorOrUpvar::Upvar(upvar.span)) }) }) } @@ -244,9 +244,9 @@ pub trait TypeErrCtxtExt<'tcx> { fn note_obligation_cause_for_async_await( &self, err: &mut Diagnostic, - interior_or_upvar_span: GeneratorInteriorOrUpvar, + interior_or_upvar_span: CoroutineInteriorOrUpvar, is_async: bool, - outer_generator: Option, + outer_coroutine: Option, trait_pred: ty::TraitPredicate<'tcx>, target_ty: Ty<'tcx>, obligation: &PredicateObligation<'tcx>, @@ -1982,7 +1982,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let argument_kind = match expected.skip_binder().self_ty().kind() { ty::Closure(..) => "closure", - ty::Generator(..) => "generator", + ty::Coroutine(..) => "coroutine", _ => "function", }; let mut err = struct_span_err!( @@ -2144,33 +2144,33 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let hir = self.tcx.hir(); // Attempt to detect an async-await error by looking at the obligation causes, looking - // for a generator to be present. + // for a coroutine to be present. // // When a future does not implement a trait because of a captured type in one of the - // generators somewhere in the call stack, then the result is a chain of obligations. + // coroutines somewhere in the call stack, then the result is a chain of obligations. // // Given an `async fn` A that calls an `async fn` B which captures a non-send type and that // future is passed as an argument to a function C which requires a `Send` type, then the // chain looks something like this: // - // - `BuiltinDerivedObligation` with a generator witness (B) - // - `BuiltinDerivedObligation` with a generator (B) + // - `BuiltinDerivedObligation` with a coroutine witness (B) + // - `BuiltinDerivedObligation` with a coroutine (B) // - `BuiltinDerivedObligation` with `impl std::future::Future` (B) - // - `BuiltinDerivedObligation` with a generator witness (A) - // - `BuiltinDerivedObligation` with a generator (A) + // - `BuiltinDerivedObligation` with a coroutine witness (A) + // - `BuiltinDerivedObligation` with a coroutine (A) // - `BuiltinDerivedObligation` with `impl std::future::Future` (A) // - `BindingObligation` with `impl_send` (Send requirement) // - // The first obligation in the chain is the most useful and has the generator that captured - // the type. The last generator (`outer_generator` below) has information about where the - // bound was introduced. At least one generator should be present for this diagnostic to be + // The first obligation in the chain is the most useful and has the coroutine that captured + // the type. The last coroutine (`outer_coroutine` below) has information about where the + // bound was introduced. At least one coroutine should be present for this diagnostic to be // modified. let (mut trait_ref, mut target_ty) = match obligation.predicate.kind().skip_binder() { ty::PredicateKind::Clause(ty::ClauseKind::Trait(p)) => (Some(p), Some(p.self_ty())), _ => (None, None), }; - let mut generator = None; - let mut outer_generator = None; + let mut coroutine = None; + let mut outer_coroutine = None; let mut next_code = Some(obligation.cause.code()); let mut seen_upvar_tys_infer_tuple = false; @@ -2190,18 +2190,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); match *ty.kind() { - ty::Generator(did, ..) | ty::GeneratorWitness(did, _) => { - generator = generator.or(Some(did)); - outer_generator = Some(did); + ty::Coroutine(did, ..) | ty::CoroutineWitness(did, _) => { + coroutine = coroutine.or(Some(did)); + outer_coroutine = Some(did); } ty::Tuple(_) if !seen_upvar_tys_infer_tuple => { // By introducing a tuple of upvar types into the chain of obligations - // of a generator, the first non-generator item is now the tuple itself, + // of a coroutine, the first non-coroutine item is now the tuple itself, // we shall ignore this. seen_upvar_tys_infer_tuple = true; } - _ if generator.is_none() => { + _ if coroutine.is_none() => { trait_ref = Some(cause.derived.parent_trait_pred.skip_binder()); target_ty = Some(ty); } @@ -2219,18 +2219,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); match *ty.kind() { - ty::Generator(did, ..) | ty::GeneratorWitness(did, ..) => { - generator = generator.or(Some(did)); - outer_generator = Some(did); + ty::Coroutine(did, ..) | ty::CoroutineWitness(did, ..) => { + coroutine = coroutine.or(Some(did)); + outer_coroutine = Some(did); } ty::Tuple(_) if !seen_upvar_tys_infer_tuple => { // By introducing a tuple of upvar types into the chain of obligations - // of a generator, the first non-generator item is now the tuple itself, + // of a coroutine, the first non-coroutine item is now the tuple itself, // we shall ignore this. seen_upvar_tys_infer_tuple = true; } - _ if generator.is_none() => { + _ if coroutine.is_none() => { trait_ref = Some(derived_obligation.parent_trait_pred.skip_binder()); target_ty = Some(ty); } @@ -2243,48 +2243,48 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - // Only continue if a generator was found. - debug!(?generator, ?trait_ref, ?target_ty); - let (Some(generator_did), Some(trait_ref), Some(target_ty)) = - (generator, trait_ref, target_ty) + // Only continue if a coroutine was found. + debug!(?coroutine, ?trait_ref, ?target_ty); + let (Some(coroutine_did), Some(trait_ref), Some(target_ty)) = + (coroutine, trait_ref, target_ty) else { return false; }; - let span = self.tcx.def_span(generator_did); + let span = self.tcx.def_span(coroutine_did); - let generator_did_root = self.tcx.typeck_root_def_id(generator_did); + let coroutine_did_root = self.tcx.typeck_root_def_id(coroutine_did); debug!( - ?generator_did, - ?generator_did_root, + ?coroutine_did, + ?coroutine_did_root, typeck_results.hir_owner = ?self.typeck_results.as_ref().map(|t| t.hir_owner), ?span, ); - let generator_body = generator_did + let coroutine_body = coroutine_did .as_local() .and_then(|def_id| hir.maybe_body_owned_by(def_id)) .map(|body_id| hir.body(body_id)); let mut visitor = AwaitsVisitor::default(); - if let Some(body) = generator_body { + if let Some(body) = coroutine_body { visitor.visit_body(body); } debug!(awaits = ?visitor.awaits); - // Look for a type inside the generator interior that matches the target type to get + // Look for a type inside the coroutine interior that matches the target type to get // a span. let target_ty_erased = self.tcx.erase_regions(target_ty); let ty_matches = |ty| -> bool { // Careful: the regions for types that appear in the - // generator interior are not generally known, so we + // coroutine interior are not generally known, so we // want to erase them when comparing (and anyway, // `Send` and other bounds are generally unaffected by // the choice of region). When erasing regions, we // also have to erase late-bound regions. This is - // because the types that appear in the generator + // because the types that appear in the coroutine // interior generally contain "bound regions" to // represent regions that are part of the suspended - // generator frame. Bound regions are preserved by + // coroutine frame. Bound regions are preserved by // `erase_regions` and so we must also call // `erase_late_bound_regions`. let ty_erased = self.tcx.erase_late_bound_regions(ty); @@ -2294,44 +2294,44 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { eq }; - // Get the typeck results from the infcx if the generator is the function we are currently + // Get the typeck results from the infcx if the coroutine is the function we are currently // type-checking; otherwise, get them by performing a query. This is needed to avoid - // cycles. If we can't use resolved types because the generator comes from another crate, + // cycles. If we can't use resolved types because the coroutine comes from another crate, // we still provide a targeted error but without all the relevant spans. - let generator_data = match &self.typeck_results { - Some(t) if t.hir_owner.to_def_id() == generator_did_root => GeneratorData(&t), - _ if generator_did.is_local() => { - GeneratorData(self.tcx.typeck(generator_did.expect_local())) + let coroutine_data = match &self.typeck_results { + Some(t) if t.hir_owner.to_def_id() == coroutine_did_root => CoroutineData(&t), + _ if coroutine_did.is_local() => { + CoroutineData(self.tcx.typeck(coroutine_did.expect_local())) } _ => return false, }; - let generator_within_in_progress_typeck = match &self.typeck_results { - Some(t) => t.hir_owner.to_def_id() == generator_did_root, + let coroutine_within_in_progress_typeck = match &self.typeck_results { + Some(t) => t.hir_owner.to_def_id() == coroutine_did_root, _ => false, }; let mut interior_or_upvar_span = None; - let from_awaited_ty = generator_data.get_from_await_ty(visitor, hir, ty_matches); + let from_awaited_ty = coroutine_data.get_from_await_ty(visitor, hir, ty_matches); debug!(?from_awaited_ty); // Avoid disclosing internal information to downstream crates. - if generator_did.is_local() + if coroutine_did.is_local() // Try to avoid cycles. - && !generator_within_in_progress_typeck - && let Some(generator_info) = self.tcx.mir_generator_witnesses(generator_did) + && !coroutine_within_in_progress_typeck + && let Some(coroutine_info) = self.tcx.mir_coroutine_witnesses(coroutine_did) { - debug!(?generator_info); + debug!(?coroutine_info); 'find_source: for (variant, source_info) in - generator_info.variant_fields.iter().zip(&generator_info.variant_source_info) + coroutine_info.variant_fields.iter().zip(&coroutine_info.variant_source_info) { debug!(?variant); for &local in variant { - let decl = &generator_info.field_tys[local]; + let decl = &coroutine_info.field_tys[local]; debug!(?decl); if ty_matches(ty::Binder::dummy(decl.ty)) && !decl.ignore_for_traits { - interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior( + interior_or_upvar_span = Some(CoroutineInteriorOrUpvar::Interior( decl.source_info.span, Some((source_info.span, from_awaited_ty)), )); @@ -2343,21 +2343,21 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if interior_or_upvar_span.is_none() { interior_or_upvar_span = - generator_data.try_get_upvar_span(&self, generator_did, ty_matches); + coroutine_data.try_get_upvar_span(&self, coroutine_did, ty_matches); } - if interior_or_upvar_span.is_none() && !generator_did.is_local() { - interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(span, None)); + if interior_or_upvar_span.is_none() && !coroutine_did.is_local() { + interior_or_upvar_span = Some(CoroutineInteriorOrUpvar::Interior(span, None)); } debug!(?interior_or_upvar_span); if let Some(interior_or_upvar_span) = interior_or_upvar_span { - let is_async = self.tcx.generator_is_async(generator_did); + let is_async = self.tcx.coroutine_is_async(coroutine_did); self.note_obligation_cause_for_async_await( err, interior_or_upvar_span, is_async, - outer_generator, + outer_coroutine, trait_ref, target_ty, obligation, @@ -2375,9 +2375,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn note_obligation_cause_for_async_await( &self, err: &mut Diagnostic, - interior_or_upvar_span: GeneratorInteriorOrUpvar, + interior_or_upvar_span: CoroutineInteriorOrUpvar, is_async: bool, - outer_generator: Option, + outer_coroutine: Option, trait_pred: ty::TraitPredicate<'tcx>, target_ty: Ty<'tcx>, obligation: &PredicateObligation<'tcx>, @@ -2387,7 +2387,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let (await_or_yield, an_await_or_yield) = if is_async { ("await", "an await") } else { ("yield", "a yield") }; - let future_or_generator = if is_async { "future" } else { "generator" }; + let future_or_coroutine = if is_async { "future" } else { "coroutine" }; // Special case the primary error message when send or sync is the trait that was // not implemented. @@ -2400,34 +2400,34 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.clear_code(); err.set_primary_message(format!( - "{future_or_generator} cannot be {trait_verb} between threads safely" + "{future_or_coroutine} cannot be {trait_verb} between threads safely" )); let original_span = err.span.primary_span().unwrap(); let mut span = MultiSpan::from_span(original_span); - let message = outer_generator - .and_then(|generator_did| { - Some(match self.tcx.generator_kind(generator_did).unwrap() { - GeneratorKind::Gen => format!("generator is not {trait_name}"), - GeneratorKind::Async(AsyncGeneratorKind::Fn) => self + let message = outer_coroutine + .and_then(|coroutine_did| { + Some(match self.tcx.coroutine_kind(coroutine_did).unwrap() { + CoroutineKind::Coroutine => format!("coroutine is not {trait_name}"), + CoroutineKind::Async(AsyncCoroutineKind::Fn) => self .tcx - .parent(generator_did) + .parent(coroutine_did) .as_local() .map(|parent_did| hir.local_def_id_to_hir_id(parent_did)) .and_then(|parent_hir_id| hir.opt_name(parent_hir_id)) .map(|name| { format!("future returned by `{name}` is not {trait_name}") })?, - GeneratorKind::Async(AsyncGeneratorKind::Block) => { + CoroutineKind::Async(AsyncCoroutineKind::Block) => { format!("future created by async block is not {trait_name}") } - GeneratorKind::Async(AsyncGeneratorKind::Closure) => { + CoroutineKind::Async(AsyncCoroutineKind::Closure) => { format!("future created by async closure is not {trait_name}") } }) }) - .unwrap_or_else(|| format!("{future_or_generator} is not {trait_name}")); + .unwrap_or_else(|| format!("{future_or_coroutine} is not {trait_name}")); span.push_span_label(original_span, message); err.set_span(span); @@ -2471,11 +2471,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); err.span_note( span, - format!("{future_or_generator} {trait_explanation} as this value is used across {an_await_or_yield}"), + format!("{future_or_coroutine} {trait_explanation} as this value is used across {an_await_or_yield}"), ); }; match interior_or_upvar_span { - GeneratorInteriorOrUpvar::Interior(interior_span, interior_extra_info) => { + CoroutineInteriorOrUpvar::Interior(interior_span, interior_extra_info) => { if let Some((yield_span, from_awaited_ty)) = interior_extra_info { if let Some(await_span) = from_awaited_ty { // The type causing this obligation is one being awaited at await_span. @@ -2498,7 +2498,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } } - GeneratorInteriorOrUpvar::Upvar(upvar_span) => { + CoroutineInteriorOrUpvar::Upvar(upvar_span) => { // `Some((ref_ty, is_mut))` if `target_ty` is `&T` or `&mut T` and fails to impl `Send` let non_send = match target_ty.kind() { ty::Ref(_, ref_ty, mutability) => match self.evaluate_obligation(&obligation) { @@ -2810,7 +2810,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.note("the return type of a function must have a statically known size"); } ObligationCauseCode::SizedYieldType => { - err.note("the yield type of a generator must have a statically known size"); + err.note("the yield type of a coroutine must have a statically known size"); } ObligationCauseCode::AssignmentLhsSized => { err.note("the left-hand-side of an assignment must have a statically known size"); @@ -2880,10 +2880,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.span_label(span, "this closure captures all values by move"); } } - ObligationCauseCode::SizedGeneratorInterior(generator_def_id) => { - let what = match self.tcx.generator_kind(generator_def_id) { - None | Some(hir::GeneratorKind::Gen) => "yield", - Some(hir::GeneratorKind::Async(..)) => "await", + ObligationCauseCode::SizedCoroutineInterior(coroutine_def_id) => { + let what = match self.tcx.coroutine_kind(coroutine_def_id) { + None | Some(hir::CoroutineKind::Coroutine) => "yield", + Some(hir::CoroutineKind::Async(..)) => "await", }; err.note(format!( "all values live across `{what}` must have a statically known size" @@ -2905,7 +2905,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { return; } - // If the obligation for a tuple is set directly by a Generator or Closure, + // If the obligation for a tuple is set directly by a Coroutine or Closure, // then the tuple must be the one containing capture types. let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) { false @@ -2915,7 +2915,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); let nested_ty = parent_trait_ref.skip_binder().self_ty(); - matches!(nested_ty.kind(), ty::Generator(..)) + matches!(nested_ty.kind(), ty::Coroutine(..)) || matches!(nested_ty.kind(), ty::Closure(..)) } else { false @@ -2935,7 +2935,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { }, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { // If the previous type is async fn, this is the future generated by the body of an async function. - // Avoid printing it twice (it was already printed in the `ty::Generator` arm below). + // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below). let is_future = tcx.ty_is_opaque_future(ty); debug!( ?obligated_types, @@ -2944,8 +2944,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); if is_future && obligated_types.last().is_some_and(|ty| match ty.kind() { - ty::Generator(last_def_id, ..) => { - tcx.generator_is_async(*last_def_id) + ty::Coroutine(last_def_id, ..) => { + tcx.coroutine_is_async(*last_def_id) } _ => false, }) @@ -2954,7 +2954,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } err.span_note(self.tcx.def_span(def_id), msg) } - ty::GeneratorWitness(def_id, args) => { + ty::CoroutineWitness(def_id, args) => { use std::fmt::Write; // FIXME: this is kind of an unusual format for rustc, can we make it more clear? @@ -2962,17 +2962,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // FIXME: only print types which don't meet the trait requirement let mut msg = "required because it captures the following types: ".to_owned(); - for bty in tcx.generator_hidden_types(*def_id) { + for bty in tcx.coroutine_hidden_types(*def_id) { let ty = bty.instantiate(tcx, args); write!(msg, "`{ty}`, ").unwrap(); } err.note(msg.trim_end_matches(", ").to_string()) } - ty::Generator(def_id, _, _) => { + ty::Coroutine(def_id, _, _) => { let sp = self.tcx.def_span(def_id); - // Special-case this to say "async block" instead of `[static generator]`. - let kind = tcx.generator_kind(def_id).unwrap().descr(); + // Special-case this to say "async block" instead of `[static coroutine]`. + let kind = tcx.coroutine_kind(def_id).unwrap().descr(); err.span_note( sp, with_forced_trimmed_paths!(format!( @@ -3271,7 +3271,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ) { if let Some(body_id) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id) { let body = self.tcx.hir().body(body_id); - if let Some(hir::GeneratorKind::Async(_)) = body.generator_kind { + if let Some(hir::CoroutineKind::Async(_)) = body.coroutine_kind { let future_trait = self.tcx.require_lang_item(LangItem::Future, None); let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty()); @@ -4332,7 +4332,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> { fn visit_body(&mut self, body: &'v hir::Body<'v>) { assert!(!self.in_block_tail); - if body.generator_kind().is_none() { + if body.coroutine_kind().is_none() { if let hir::ExprKind::Block(block, None) = body.value.kind { if block.expr.is_some() { self.in_block_tail = true; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 640bd3fad7ca5..b382474213ea1 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1036,7 +1036,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> { ignoring_lifetimes: bool, ) -> Option; - fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str>; + fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str>; fn find_similar_impl_candidates( &self, @@ -1564,9 +1564,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::Alias(ty::Weak, ..) => Some(15), ty::Never => Some(16), ty::Adt(..) => Some(17), - ty::Generator(..) => Some(18), + ty::Coroutine(..) => Some(18), ty::Foreign(..) => Some(19), - ty::GeneratorWitness(..) => Some(20), + ty::CoroutineWitness(..) => Some(20), ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) | ty::Error(_) => None, } } @@ -1613,12 +1613,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> { - self.tcx.hir().body(body_id).generator_kind.map(|gen_kind| match gen_kind { - hir::GeneratorKind::Gen => "a generator", - hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) => "an async block", - hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn) => "an async function", - hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure) => "an async closure", + fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> { + self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind { + hir::CoroutineKind::Coroutine => "a coroutine", + hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) => "an async block", + hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn) => "an async function", + hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure) => "an async closure", }) } @@ -3098,7 +3098,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { }; let found_did = match *found_trait_ty.kind() { - ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) | ty::Generator(did, ..) => { + ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => { Some(did) } ty::Adt(def, _) => Some(def.did()), diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index b923926d28dfb..c3f56ae2756c6 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1811,8 +1811,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( | ty::FnPtr(..) | ty::Dynamic(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(..) // Integers and floats always have `u8` as their discriminant. @@ -1860,8 +1860,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( | ty::FnPtr(..) | ty::Dynamic(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never // Extern types have unit metadata, according to RFC 2850 | ty::Foreign(_) @@ -2003,7 +2003,7 @@ fn confirm_select_candidate<'cx, 'tcx>( let trait_def_id = obligation.predicate.trait_def_id(selcx.tcx()); let lang_items = selcx.tcx().lang_items(); if lang_items.gen_trait() == Some(trait_def_id) { - confirm_generator_candidate(selcx, obligation, data) + confirm_coroutine_candidate(selcx, obligation, data) } else if lang_items.future_trait() == Some(trait_def_id) { confirm_future_candidate(selcx, obligation, data) } else if selcx.tcx().fn_trait_kind_from_def_id(trait_def_id).is_some() { @@ -2030,17 +2030,17 @@ fn confirm_select_candidate<'cx, 'tcx>( } } -fn confirm_generator_candidate<'cx, 'tcx>( +fn confirm_coroutine_candidate<'cx, 'tcx>( selcx: &mut SelectionContext<'cx, 'tcx>, obligation: &ProjectionTyObligation<'tcx>, nested: Vec>, ) -> Progress<'tcx> { - let ty::Generator(_, args, _) = + let ty::Coroutine(_, args, _) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind() else { unreachable!() }; - let gen_sig = args.as_generator().poly_sig(); + let gen_sig = args.as_coroutine().poly_sig(); let Normalized { value: gen_sig, obligations } = normalize_with_depth( selcx, obligation.param_env, @@ -2049,13 +2049,13 @@ fn confirm_generator_candidate<'cx, 'tcx>( gen_sig, ); - debug!(?obligation, ?gen_sig, ?obligations, "confirm_generator_candidate"); + debug!(?obligation, ?gen_sig, ?obligations, "confirm_coroutine_candidate"); let tcx = selcx.tcx(); - let gen_def_id = tcx.require_lang_item(LangItem::Generator, None); + let gen_def_id = tcx.require_lang_item(LangItem::Coroutine, None); - let predicate = super::util::generator_trait_ref_and_outputs( + let predicate = super::util::coroutine_trait_ref_and_outputs( tcx, gen_def_id, obligation.predicate.self_ty(), @@ -2087,12 +2087,12 @@ fn confirm_future_candidate<'cx, 'tcx>( obligation: &ProjectionTyObligation<'tcx>, nested: Vec>, ) -> Progress<'tcx> { - let ty::Generator(_, args, _) = + let ty::Coroutine(_, args, _) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind() else { unreachable!() }; - let gen_sig = args.as_generator().poly_sig(); + let gen_sig = args.as_coroutine().poly_sig(); let Normalized { value: gen_sig, obligations } = normalize_with_depth( selcx, obligation.param_env, diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 86ea7a2bf8392..0783eec6fe8c0 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -35,7 +35,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { | ty::FnDef(..) | ty::FnPtr(_) | ty::Char - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::RawPtr(_) | ty::Ref(..) | ty::Str @@ -72,7 +72,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { | ty::Placeholder(..) | ty::Infer(_) | ty::Bound(..) - | ty::Generator(..) => false, + | ty::Coroutine(..) => false, } } @@ -217,7 +217,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>( | ty::Ref(..) | ty::FnDef(..) | ty::FnPtr(_) - | ty::GeneratorWitness(..) => { + | ty::CoroutineWitness(..) => { // these types never have a destructor } @@ -255,22 +255,22 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>( })? } - ty::Generator(_, args, _movability) => { + ty::Coroutine(_, args, _movability) => { // rust-lang/rust#49918: types can be constructed, stored - // in the interior, and sit idle when generator yields + // in the interior, and sit idle when coroutine yields // (and is subsequently dropped). // // It would be nice to descend into interior of a - // generator to determine what effects dropping it might + // coroutine to determine what effects dropping it might // have (by looking at any drop effects associated with // its interior). // // However, the interior's representation uses things like - // GeneratorWitness that explicitly assume they are not + // CoroutineWitness that explicitly assume they are not // traversed in such a manner. So instead, we will - // simplify things for now by treating all generators as + // simplify things for now by treating all coroutines as // if they were like trait objects, where its upvars must - // all be alive for the generator's (potential) + // all be alive for the coroutine's (potential) // destructor. // // In particular, skipping over `_interior` is safe @@ -279,20 +279,20 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>( // derived from lifetimes attached to the upvars and resume // argument, and we *do* incorporate those here. - if !args.as_generator().is_valid() { + if !args.as_coroutine().is_valid() { // By the time this code runs, all type variables ought to // be fully resolved. tcx.sess.delay_span_bug( span, - format!("upvar_tys for generator not found. Expected capture information for generator {ty}",), + format!("upvar_tys for coroutine not found. Expected capture information for coroutine {ty}",), ); return Err(NoSolution); } constraints .outlives - .extend(args.as_generator().upvar_tys().iter().map(ty::GenericArg::from)); - constraints.outlives.push(args.as_generator().resume_ty().into()); + .extend(args.as_coroutine().upvar_tys().iter().map(ty::GenericArg::from)); + constraints.outlives.push(args.as_coroutine().resume_ty().into()); } ty::Adt(def, args) => { diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index f785211c54861..349741a698c9a 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -231,7 +231,7 @@ impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> let args = data.args.try_fold_with(self)?; let recursion_limit = self.interner().recursion_limit(); if !recursion_limit.value_within_limit(self.anon_depth) { - // A closure or generator may have itself as in its upvars. + // A closure or coroutine may have itself as in its upvars. // This should be checked handled by the recursion check for opaque // types, but we may end up here before that check can happen. // In that case, we delay a bug to mark the trip, and continue without diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index a8001577bcd5c..ee50a36be55b1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -111,7 +111,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } if lang_items.gen_trait() == Some(def_id) { - self.assemble_generator_candidates(obligation, &mut candidates); + self.assemble_coroutine_candidates(obligation, &mut candidates); } else if lang_items.future_trait() == Some(def_id) { self.assemble_future_candidates(obligation, &mut candidates); } @@ -201,25 +201,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Ok(()) } - fn assemble_generator_candidates( + fn assemble_coroutine_candidates( &mut self, obligation: &PolyTraitObligation<'tcx>, candidates: &mut SelectionCandidateSet<'tcx>, ) { - // Okay to skip binder because the args on generator types never + // Okay to skip binder because the args on coroutine types never // touch bound regions, they just capture the in-scope // type/region parameters. let self_ty = obligation.self_ty().skip_binder(); match self_ty.kind() { - // async constructs get lowered to a special kind of generator that - // should *not* `impl Generator`. - ty::Generator(did, ..) if !self.tcx().generator_is_async(*did) => { - debug!(?self_ty, ?obligation, "assemble_generator_candidates",); + // async constructs get lowered to a special kind of coroutine that + // should *not* `impl Coroutine`. + ty::Coroutine(did, ..) if !self.tcx().coroutine_is_async(*did) => { + debug!(?self_ty, ?obligation, "assemble_coroutine_candidates",); - candidates.vec.push(GeneratorCandidate); + candidates.vec.push(CoroutineCandidate); } ty::Infer(ty::TyVar(_)) => { - debug!("assemble_generator_candidates: ambiguous self-type"); + debug!("assemble_coroutine_candidates: ambiguous self-type"); candidates.ambiguous = true; } _ => {} @@ -232,10 +232,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { candidates: &mut SelectionCandidateSet<'tcx>, ) { let self_ty = obligation.self_ty().skip_binder(); - if let ty::Generator(did, ..) = self_ty.kind() { - // async constructs get lowered to a special kind of generator that + if let ty::Coroutine(did, ..) = self_ty.kind() { + // async constructs get lowered to a special kind of coroutine that // should directly `impl Future`. - if self.tcx().generator_is_async(*did) { + if self.tcx().coroutine_is_async(*did) { debug!(?self_ty, ?obligation, "assemble_future_candidates",); candidates.vec.push(FutureCandidate); @@ -435,8 +435,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::RawPtr(_) | ty::Ref(_, _, _) | ty::Closure(_, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) | ty::Error(_) => return true, @@ -513,16 +513,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // The auto impl might apply; we don't know. candidates.ambiguous = true; } - ty::Generator(_, _, movability) + ty::Coroutine(_, _, movability) if self.tcx().lang_items().unpin_trait() == Some(def_id) => { match movability { hir::Movability::Static => { - // Immovable generators are never `Unpin`, so + // Immovable coroutines are never `Unpin`, so // suppress the normal auto-impl candidate for it. } hir::Movability::Movable => { - // Movable generators are always `Unpin`, so add an + // Movable coroutines are always `Unpin`, so add an // unconditional builtin candidate. candidates.vec.push(BuiltinCandidate { has_nested: false }); } @@ -570,10 +570,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::FnDef(..) | ty::FnPtr(_) | ty::Closure(_, _) - | ty::Generator(..) + | ty::Coroutine(..) | ty::Never | ty::Tuple(_) - | ty::GeneratorWitness(..) => { + | ty::CoroutineWitness(..) => { // Only consider auto impls if there are no manual impls for the root of `self_ty`. // // For example, we only consider auto candidates for `&i32: Auto` if no explicit impl @@ -947,9 +947,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Array(..) | ty::Slice(_) | ty::Closure(..) - | ty::Generator(..) + | ty::Coroutine(..) | ty::Tuple(_) - | ty::GeneratorWitness(..) => { + | ty::CoroutineWitness(..) => { // These are built-in, and cannot have a custom `impl const Destruct`. candidates.vec.push(ConstDestructCandidate(None)); } @@ -1021,8 +1021,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::FnPtr(_) | ty::Dynamic(_, _, _) | ty::Closure(_, _) - | ty::Generator(_, _, _) - | ty::GeneratorWitness(..) + | ty::Coroutine(_, _, _) + | ty::CoroutineWitness(..) | ty::Never | ty::Alias(..) | ty::Param(_) @@ -1082,8 +1082,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Placeholder(..) | ty::Dynamic(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(..) | ty::Alias(..) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 08ee9c73bf8aa..fce439f21fa29 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -83,9 +83,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure) } - GeneratorCandidate => { - let vtable_generator = self.confirm_generator_candidate(obligation)?; - ImplSource::Builtin(BuiltinImplSource::Misc, vtable_generator) + CoroutineCandidate => { + let vtable_coroutine = self.confirm_coroutine_candidate(obligation)?; + ImplSource::Builtin(BuiltinImplSource::Misc, vtable_coroutine) } FutureCandidate => { @@ -711,23 +711,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { trait_obligations } - fn confirm_generator_candidate( + fn confirm_coroutine_candidate( &mut self, obligation: &PolyTraitObligation<'tcx>, ) -> Result>, SelectionError<'tcx>> { - // Okay to skip binder because the args on generator types never + // Okay to skip binder because the args on coroutine types never // touch bound regions, they just capture the in-scope // type/region parameters. let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); - let ty::Generator(generator_def_id, args, _) = *self_ty.kind() else { + let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else { bug!("closure candidate for non-closure {:?}", obligation); }; - debug!(?obligation, ?generator_def_id, ?args, "confirm_generator_candidate"); + debug!(?obligation, ?coroutine_def_id, ?args, "confirm_coroutine_candidate"); - let gen_sig = args.as_generator().poly_sig(); + let gen_sig = args.as_coroutine().poly_sig(); - // NOTE: The self-type is a generator type and hence is + // NOTE: The self-type is a coroutine type and hence is // in fact unparameterized (or at least does not reference any // regions bound in the obligation). let self_ty = obligation @@ -736,7 +736,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .no_bound_vars() .expect("unboxed closure type should not capture bound vars from the predicate"); - let trait_ref = super::util::generator_trait_ref_and_outputs( + let trait_ref = super::util::coroutine_trait_ref_and_outputs( self.tcx(), obligation.predicate.def_id(), self_ty, @@ -745,7 +745,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map_bound(|(trait_ref, ..)| trait_ref); let nested = self.confirm_poly_trait_refs(obligation, trait_ref)?; - debug!(?trait_ref, ?nested, "generator candidate obligations"); + debug!(?trait_ref, ?nested, "coroutine candidate obligations"); Ok(nested) } @@ -754,17 +754,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &mut self, obligation: &PolyTraitObligation<'tcx>, ) -> Result>, SelectionError<'tcx>> { - // Okay to skip binder because the args on generator types never + // Okay to skip binder because the args on coroutine types never // touch bound regions, they just capture the in-scope // type/region parameters. let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); - let ty::Generator(generator_def_id, args, _) = *self_ty.kind() else { + let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else { bug!("closure candidate for non-closure {:?}", obligation); }; - debug!(?obligation, ?generator_def_id, ?args, "confirm_future_candidate"); + debug!(?obligation, ?coroutine_def_id, ?args, "confirm_future_candidate"); - let gen_sig = args.as_generator().poly_sig(); + let gen_sig = args.as_coroutine().poly_sig(); let trait_ref = super::util::future_trait_ref_and_outputs( self.tcx(), @@ -1234,13 +1234,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Closure(_, args) => { stack.push(args.as_closure().tupled_upvars_ty()); } - ty::Generator(_, args, _) => { - let generator = args.as_generator(); - stack.extend([generator.tupled_upvars_ty(), generator.witness()]); + ty::Coroutine(_, args, _) => { + let coroutine = args.as_coroutine(); + stack.extend([coroutine.tupled_upvars_ty(), coroutine.witness()]); } - ty::GeneratorWitness(def_id, args) => { + ty::CoroutineWitness(def_id, args) => { let tcx = self.tcx(); - stack.extend(tcx.generator_hidden_types(def_id).map(|bty| { + stack.extend(tcx.coroutine_hidden_types(def_id).map(|bty| { let ty = bty.instantiate(tcx, args); debug_assert!(!ty.has_late_bound_regions()); ty diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 940ceca50d2d4..67cb39bc00459 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1886,7 +1886,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ImplCandidate(..) | AutoImplCandidate | ClosureCandidate { .. } - | GeneratorCandidate + | CoroutineCandidate | FutureCandidate | FnPointerCandidate { .. } | BuiltinObjectCandidate @@ -1914,7 +1914,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ImplCandidate(_) | AutoImplCandidate | ClosureCandidate { .. } - | GeneratorCandidate + | CoroutineCandidate | FutureCandidate | FnPointerCandidate { .. } | BuiltinObjectCandidate @@ -1948,7 +1948,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ImplCandidate(..) | AutoImplCandidate | ClosureCandidate { .. } - | GeneratorCandidate + | CoroutineCandidate | FutureCandidate | FnPointerCandidate { .. } | BuiltinObjectCandidate @@ -1962,7 +1962,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ImplCandidate(..) | AutoImplCandidate | ClosureCandidate { .. } - | GeneratorCandidate + | CoroutineCandidate | FutureCandidate | FnPointerCandidate { .. } | BuiltinObjectCandidate @@ -2068,7 +2068,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ( ImplCandidate(_) | ClosureCandidate { .. } - | GeneratorCandidate + | CoroutineCandidate | FutureCandidate | FnPointerCandidate { .. } | BuiltinObjectCandidate @@ -2078,7 +2078,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | TraitAliasCandidate, ImplCandidate(_) | ClosureCandidate { .. } - | GeneratorCandidate + | CoroutineCandidate | FutureCandidate | FnPointerCandidate { .. } | BuiltinObjectCandidate @@ -2112,8 +2112,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ty::RawPtr(..) | ty::Char | ty::Ref(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Array(..) | ty::Closure(..) | ty::Never @@ -2180,7 +2180,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ty::Dynamic(..) | ty::Str | ty::Slice(..) - | ty::Generator(_, _, hir::Movability::Static) + | ty::Coroutine(_, _, hir::Movability::Static) | ty::Foreign(..) | ty::Ref(_, _, hir::Mutability::Mut) => None, @@ -2189,21 +2189,21 @@ impl<'tcx> SelectionContext<'_, 'tcx> { Where(obligation.predicate.rebind(tys.iter().collect())) } - ty::Generator(_, args, hir::Movability::Movable) => { - if self.tcx().features().generator_clone { + ty::Coroutine(_, args, hir::Movability::Movable) => { + if self.tcx().features().coroutine_clone { let resolved_upvars = - self.infcx.shallow_resolve(args.as_generator().tupled_upvars_ty()); + self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty()); let resolved_witness = - self.infcx.shallow_resolve(args.as_generator().witness()); + self.infcx.shallow_resolve(args.as_coroutine().witness()); if resolved_upvars.is_ty_var() || resolved_witness.is_ty_var() { // Not yet resolved. Ambiguous } else { let all = args - .as_generator() + .as_coroutine() .upvar_tys() .iter() - .chain([args.as_generator().witness()]) + .chain([args.as_coroutine().witness()]) .collect::>(); Where(obligation.predicate.rebind(all)) } @@ -2212,8 +2212,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } } - ty::GeneratorWitness(def_id, ref args) => { - let hidden_types = bind_generator_hidden_types_above( + ty::CoroutineWitness(def_id, ref args) => { + let hidden_types = bind_coroutine_hidden_types_above( self.infcx, def_id, args, @@ -2311,14 +2311,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> { t.rebind(vec![ty]) } - ty::Generator(_, ref args, _) => { - let ty = self.infcx.shallow_resolve(args.as_generator().tupled_upvars_ty()); - let witness = args.as_generator().witness(); + ty::Coroutine(_, ref args, _) => { + let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty()); + let witness = args.as_coroutine().witness(); t.rebind([ty].into_iter().chain(iter::once(witness)).collect()) } - ty::GeneratorWitness(def_id, ref args) => { - bind_generator_hidden_types_above(self.infcx, def_id, args, t.bound_vars()) + ty::CoroutineWitness(def_id, ref args) => { + bind_coroutine_hidden_types_above(self.infcx, def_id, args, t.bound_vars()) } // For `PhantomData`, we pass `T`. @@ -3054,12 +3054,12 @@ pub enum ProjectionMatchesProjection { No, } -/// Replace all regions inside the generator interior with late bound regions. +/// Replace all regions inside the coroutine interior with late bound regions. /// Note that each region slot in the types gets a new fresh late bound region, which means that /// none of the regions inside relate to any other, even if typeck had previously found constraints /// that would cause them to be related. #[instrument(level = "trace", skip(infcx), ret)] -fn bind_generator_hidden_types_above<'tcx>( +fn bind_coroutine_hidden_types_above<'tcx>( infcx: &InferCtxt<'tcx>, def_id: DefId, args: ty::GenericArgsRef<'tcx>, @@ -3074,7 +3074,7 @@ fn bind_generator_hidden_types_above<'tcx>( let mut counter = num_bound_variables; let hidden_types: Vec<_> = tcx - .generator_hidden_types(def_id) + .coroutine_hidden_types(def_id) // Deduplicate tys to avoid repeated work. .filter(|bty| seen_tys.insert(*bty)) .map(|mut bty| { diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index fc9b424369a78..5960415a88da2 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -79,7 +79,7 @@ impl<'tcx> TypeVisitor> for Search<'tcx> { ty::Closure(..) => { return ControlFlow::Break(ty); } - ty::Generator(..) | ty::GeneratorWitness(..) => { + ty::Coroutine(..) | ty::CoroutineWitness(..) => { return ControlFlow::Break(ty); } ty::FnDef(..) => { diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 4ef2027d7e83f..47ed4e20edceb 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -275,7 +275,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>( sig.map_bound(|sig| (trait_ref, sig.output())) } -pub fn generator_trait_ref_and_outputs<'tcx>( +pub fn coroutine_trait_ref_and_outputs<'tcx>( tcx: TyCtxt<'tcx>, fn_trait_def_id: DefId, self_ty: Ty<'tcx>, diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index e7e4ee983fb10..fe5b625e4836d 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -600,7 +600,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { | ty::Float(..) | ty::Error(_) | ty::Str - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Param(_) | ty::Bound(..) @@ -672,14 +672,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { } } - ty::Generator(did, args, ..) => { - // Walk ALL the types in the generator: this will + ty::Coroutine(did, args, ..) => { + // Walk ALL the types in the coroutine: this will // include the upvar types as well as the yield // type. Note that this is mildly distinct from // the closure case, where we have to be careful // about the signature of the closure. We don't // have the problem of implied bounds here since - // generators don't take arguments. + // coroutines don't take arguments. let obligations = self.nominal_obligations(did, args); self.out.extend(obligations); } diff --git a/compiler/rustc_ty_utils/messages.ftl b/compiler/rustc_ty_utils/messages.ftl index c416aa52a24a4..ae795ef2214b8 100644 --- a/compiler/rustc_ty_utils/messages.ftl +++ b/compiler/rustc_ty_utils/messages.ftl @@ -60,6 +60,6 @@ ty_utils_tuple_not_supported = tuple construction is not supported in generic co ty_utils_unexpected_fnptr_associated_item = `FnPtr` trait with unexpected associated item -ty_utils_yield_not_supported = generator control flow is not allowed in generic constants +ty_utils_yield_not_supported = coroutine control flow is not allowed in generic constants ty_utils_zero_length_simd_type = monomorphising SIMD type `{$ty}` of zero length diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index b118ddaab2b8d..fcf6626bbf05e 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -97,8 +97,8 @@ fn fn_sig_for_fn_abi<'tcx>( bound_vars, ) } - ty::Generator(did, args, _) => { - let sig = args.as_generator().poly_sig(); + ty::Coroutine(did, args, _) => { + let sig = args.as_coroutine().poly_sig(); let bound_vars = tcx.mk_bound_variable_kinds_from_iter( sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), @@ -116,11 +116,11 @@ fn fn_sig_for_fn_abi<'tcx>( let env_ty = Ty::new_adt(tcx, pin_adt_ref, pin_args); let sig = sig.skip_binder(); - // The `FnSig` and the `ret_ty` here is for a generators main - // `Generator::resume(...) -> GeneratorState` function in case we - // have an ordinary generator, or the `Future::poll(...) -> Poll` - // function in case this is a special generator backing an async construct. - let (resume_ty, ret_ty) = if tcx.generator_is_async(did) { + // The `FnSig` and the `ret_ty` here is for a coroutines main + // `Coroutine::resume(...) -> CoroutineState` function in case we + // have an ordinary coroutine, or the `Future::poll(...) -> Poll` + // function in case this is a special coroutine backing an async construct. + let (resume_ty, ret_ty) = if tcx.coroutine_is_async(did) { // The signature should be `Future::poll(_, &mut Context<'_>) -> Poll` let poll_did = tcx.require_lang_item(LangItem::Poll, None); let poll_adt_ref = tcx.adt_def(poll_did); @@ -143,8 +143,8 @@ fn fn_sig_for_fn_abi<'tcx>( (context_mut_ref, ret_ty) } else { - // The signature should be `Generator::resume(_, Resume) -> GeneratorState` - let state_did = tcx.require_lang_item(LangItem::GeneratorState, None); + // The signature should be `Coroutine::resume(_, Resume) -> CoroutineState` + let state_did = tcx.require_lang_item(LangItem::CoroutineState, None); let state_adt_ref = tcx.adt_def(state_did); let state_args = tcx.mk_args(&[sig.yield_ty.into(), sig.return_ty.into()]); let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_args); diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 0ca7d43f6d53e..5c34df1ed5027 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -157,7 +157,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' | DefKind::LifetimeParam | DefKind::GlobalAsm | DefKind::Closure - | DefKind::Generator => ty::List::empty(), + | DefKind::Coroutine => ty::List::empty(), } } diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 2fbf87800bb02..0e9d79c15c3e0 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -38,7 +38,7 @@ fn resolve_instance<'tcx>( debug!(" => nontrivial drop glue"); match *ty.kind() { ty::Closure(..) - | ty::Generator(..) + | ty::Coroutine(..) | ty::Tuple(..) | ty::Adt(..) | ty::Dynamic(..) @@ -212,8 +212,8 @@ fn resolve_associated_item<'tcx>( let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env); match self_ty.kind() { _ if is_copy => (), - ty::Generator(..) - | ty::GeneratorWitness(..) + ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Closure(..) | ty::Tuple(..) => {} _ => return Ok(None), @@ -246,12 +246,12 @@ fn resolve_associated_item<'tcx>( }) } } else if Some(trait_ref.def_id) == lang_items.future_trait() { - let ty::Generator(generator_def_id, args, _) = *rcvr_args.type_at(0).kind() else { + let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { bug!() }; if Some(trait_item_id) == tcx.lang_items().future_poll_fn() { // `Future::poll` is generated by the compiler. - Some(Instance { def: ty::InstanceDef::Item(generator_def_id), args: args }) + Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args: args }) } else { // All other methods are default methods of the `Future` trait. // (this assumes that `ImplSource::Builtin` is only used for methods on `Future`) @@ -259,21 +259,21 @@ fn resolve_associated_item<'tcx>( Some(Instance::new(trait_item_id, rcvr_args)) } } else if Some(trait_ref.def_id) == lang_items.gen_trait() { - let ty::Generator(generator_def_id, args, _) = *rcvr_args.type_at(0).kind() else { + let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { bug!() }; if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::resume { - // For compiler developers who'd like to add new items to `Generator`, + // For compiler developers who'd like to add new items to `Coroutine`, // you either need to generate a shim body, or perhaps return // `InstanceDef::Item` pointing to a trait default method body if // it is given a default implementation by the trait. span_bug!( - tcx.def_span(generator_def_id), - "no definition for `{trait_ref}::{}` for built-in generator type", + tcx.def_span(coroutine_def_id), + "no definition for `{trait_ref}::{}` for built-in coroutine type", tcx.item_name(trait_item_id) ) } - Some(Instance { def: ty::InstanceDef::Item(generator_def_id), args }) + Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args }) } else if tcx.fn_trait_kind_from_def_id(trait_ref.def_id).is_some() { // FIXME: This doesn't check for malformed libcore that defines, e.g., // `trait Fn { fn call_once(&self) { .. } }`. This is mostly for extension diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index cc6c8478785ce..283862b5e1cc6 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -2,7 +2,7 @@ use hir::def_id::DefId; use rustc_hir as hir; use rustc_index::bit_set::BitSet; use rustc_index::{IndexSlice, IndexVec}; -use rustc_middle::mir::{GeneratorLayout, GeneratorSavedLocal}; +use rustc_middle::mir::{CoroutineLayout, CoroutineSavedLocal}; use rustc_middle::query::Providers; use rustc_middle::ty::layout::{ IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES, @@ -314,7 +314,7 @@ fn layout_of_uncached<'tcx>( tcx.mk_layout(unit) } - ty::Generator(def_id, args, _) => generator_layout(cx, ty, def_id, args)?, + ty::Coroutine(def_id, args, _) => coroutine_layout(cx, ty, def_id, args)?, ty::Closure(_, ref args) => { let tys = args.as_closure().upvar_tys(); @@ -575,7 +575,7 @@ fn layout_of_uncached<'tcx>( return Err(error(cx, LayoutError::Unknown(ty))); } - ty::Bound(..) | ty::GeneratorWitness(..) | ty::Infer(_) | ty::Error(_) => { + ty::Bound(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => { bug!("Layout::compute: unexpected type `{}`", ty) } @@ -585,7 +585,7 @@ fn layout_of_uncached<'tcx>( }) } -/// Overlap eligibility and variant assignment for each GeneratorSavedLocal. +/// Overlap eligibility and variant assignment for each CoroutineSavedLocal. #[derive(Clone, Debug, PartialEq)] enum SavedLocalEligibility { Unassigned, @@ -593,7 +593,7 @@ enum SavedLocalEligibility { Ineligible(Option), } -// When laying out generators, we divide our saved local fields into two +// When laying out coroutines, we divide our saved local fields into two // categories: overlap-eligible and overlap-ineligible. // // Those fields which are ineligible for overlap go in a "prefix" at the @@ -613,16 +613,16 @@ enum SavedLocalEligibility { // of any variant. /// Compute the eligibility and assignment of each local. -fn generator_saved_local_eligibility( - info: &GeneratorLayout<'_>, -) -> (BitSet, IndexVec) { +fn coroutine_saved_local_eligibility( + info: &CoroutineLayout<'_>, +) -> (BitSet, IndexVec) { use SavedLocalEligibility::*; - let mut assignments: IndexVec = + let mut assignments: IndexVec = IndexVec::from_elem(Unassigned, &info.field_tys); // The saved locals not eligible for overlap. These will get - // "promoted" to the prefix of our generator. + // "promoted" to the prefix of our coroutine. let mut ineligible_locals = BitSet::new_empty(info.field_tys.len()); // Figure out which of our saved locals are fields in only @@ -660,7 +660,7 @@ fn generator_saved_local_eligibility( for local_b in info.storage_conflicts.iter(local_a) { // local_a and local_b are storage live at the same time, therefore they - // cannot overlap in the generator layout. The only way to guarantee + // cannot overlap in the coroutine layout. The only way to guarantee // this is if they are in the same variant, or one is ineligible // (which means it is stored in every variant). if ineligible_locals.contains(local_b) || assignments[local_a] == assignments[local_b] { @@ -705,13 +705,13 @@ fn generator_saved_local_eligibility( assignments[local] = Ineligible(Some(FieldIdx::from_usize(idx))); } } - debug!("generator saved local assignments: {:?}", assignments); + debug!("coroutine saved local assignments: {:?}", assignments); (ineligible_locals, assignments) } -/// Compute the full generator layout. -fn generator_layout<'tcx>( +/// Compute the full coroutine layout. +fn coroutine_layout<'tcx>( cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, ty: Ty<'tcx>, def_id: hir::def_id::DefId, @@ -721,15 +721,15 @@ fn generator_layout<'tcx>( let tcx = cx.tcx; let subst_field = |ty: Ty<'tcx>| EarlyBinder::bind(ty).instantiate(tcx, args); - let Some(info) = tcx.generator_layout(def_id) else { + let Some(info) = tcx.coroutine_layout(def_id) else { return Err(error(cx, LayoutError::Unknown(ty))); }; - let (ineligible_locals, assignments) = generator_saved_local_eligibility(&info); + let (ineligible_locals, assignments) = coroutine_saved_local_eligibility(&info); // Build a prefix layout, including "promoting" all ineligible // locals as part of the prefix. We compute the layout of all of // these fields at once to get optimal packing. - let tag_index = args.as_generator().prefix_tys().len(); + let tag_index = args.as_coroutine().prefix_tys().len(); // `info.variant_fields` already accounts for the reserved variants, so no need to add them. let max_discr = (info.variant_fields.len() - 1) as u128; @@ -746,7 +746,7 @@ fn generator_layout<'tcx>( .map(|ty| Ty::new_maybe_uninit(tcx, ty)) .map(|ty| Ok(cx.layout_of(ty)?.layout)); let prefix_layouts = args - .as_generator() + .as_coroutine() .prefix_tys() .iter() .map(|ty| Ok(cx.layout_of(ty)?.layout)) @@ -766,7 +766,7 @@ fn generator_layout<'tcx>( // Split the prefix layout into the "outer" fields (upvars and // discriminant) and the "promoted" fields. Promoted fields will // get included in each variant that requested them in - // GeneratorLayout. + // CoroutineLayout. debug!("prefix = {:#?}", prefix); let (outer_fields, promoted_offsets, promoted_memory_index) = match prefix.fields { FieldsShape::Arbitrary { mut offsets, memory_index } => { @@ -833,7 +833,7 @@ fn generator_layout<'tcx>( }; // Now, stitch the promoted and variant-only fields back together in - // the order they are mentioned by our GeneratorLayout. + // the order they are mentioned by our CoroutineLayout. // Because we only use some subset (that can differ between variants) // of the promoted fields, we can't just pick those elements of the // `promoted_memory_index` (as we'd end up with gaps). @@ -907,7 +907,7 @@ fn generator_layout<'tcx>( max_repr_align: None, unadjusted_abi_align: align.abi, }); - debug!("generator layout ({:?}): {:#?}", ty, layout); + debug!("coroutine layout ({:?}): {:#?}", ty, layout); Ok(layout) } @@ -956,12 +956,12 @@ fn record_layout_for_printing_outlined<'tcx>( record(adt_kind.into(), adt_packed, opt_discr_size, variant_infos); } - ty::Generator(def_id, args, _) => { - debug!("print-type-size t: `{:?}` record generator", layout.ty); - // Generators always have a begin/poisoned/end state with additional suspend points + ty::Coroutine(def_id, args, _) => { + debug!("print-type-size t: `{:?}` record coroutine", layout.ty); + // Coroutines always have a begin/poisoned/end state with additional suspend points let (variant_infos, opt_discr_size) = - variant_info_for_generator(cx, layout, def_id, args); - record(DataTypeKind::Generator, false, opt_discr_size, variant_infos); + variant_info_for_coroutine(cx, layout, def_id, args); + record(DataTypeKind::Coroutine, false, opt_discr_size, variant_infos); } ty::Closure(..) => { @@ -1046,7 +1046,7 @@ fn variant_info_for_adt<'tcx>( } } -fn variant_info_for_generator<'tcx>( +fn variant_info_for_coroutine<'tcx>( cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: TyAndLayout<'tcx>, def_id: DefId, @@ -1056,12 +1056,12 @@ fn variant_info_for_generator<'tcx>( return (vec![], None); }; - let generator = cx.tcx.optimized_mir(def_id).generator_layout().unwrap(); + let coroutine = cx.tcx.optimized_mir(def_id).coroutine_layout().unwrap(); let upvar_names = cx.tcx.closure_saved_names_of_captured_variables(def_id); let mut upvars_size = Size::ZERO; let upvar_fields: Vec<_> = args - .as_generator() + .as_coroutine() .upvar_tys() .iter() .zip(upvar_names) @@ -1080,7 +1080,7 @@ fn variant_info_for_generator<'tcx>( }) .collect(); - let mut variant_infos: Vec<_> = generator + let mut variant_infos: Vec<_> = coroutine .variant_fields .iter_enumerated() .map(|(variant_idx, variant_def)| { @@ -1095,9 +1095,9 @@ fn variant_info_for_generator<'tcx>( // The struct is as large as the last field's end variant_size = variant_size.max(offset + field_layout.size); FieldInfo { - kind: FieldKind::GeneratorLocal, - name: generator.field_names[*local].unwrap_or(Symbol::intern(&format!( - ".generator_field{}", + kind: FieldKind::CoroutineLocal, + name: coroutine.field_names[*local].unwrap_or(Symbol::intern(&format!( + ".coroutine_field{}", local.as_usize() ))), offset: offset.bytes(), @@ -1115,8 +1115,8 @@ fn variant_info_for_generator<'tcx>( // This `if` deserves some explanation. // - // The layout code has a choice of where to place the discriminant of this generator. - // If the discriminant of the generator is placed early in the layout (before the + // The layout code has a choice of where to place the discriminant of this coroutine. + // If the discriminant of the coroutine is placed early in the layout (before the // variant's own fields), then it'll implicitly be counted towards the size of the // variant, since we use the maximum offset to calculate size. // (side-note: I know this is a bit problematic given upvars placement, etc). @@ -1136,7 +1136,7 @@ fn variant_info_for_generator<'tcx>( } VariantInfo { - name: Some(Symbol::intern(&ty::GeneratorArgs::variant_name(variant_idx))), + name: Some(Symbol::intern(&ty::CoroutineArgs::variant_name(variant_idx))), kind: SizeKind::Exact, size: variant_size.bytes(), align: variant_layout.align.abi.bytes(), @@ -1147,7 +1147,7 @@ fn variant_info_for_generator<'tcx>( // The first three variants are hardcoded to be `UNRESUMED`, `RETURNED` and `POISONED`. // We will move the `RETURNED` and `POISONED` elements to the end so we - // are left with a sorting order according to the generators yield points: + // are left with a sorting order according to the coroutines yield points: // First `Unresumed`, then the `SuspendN` followed by `Returned` and `Panicked` (POISONED). let end_states = variant_infos.drain(1..=2); let end_states: Vec<_> = end_states.collect(); diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 6dcbc4470e607..0812730474123 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -130,10 +130,10 @@ where for component in components { match *component.kind() { - // The information required to determine whether a generator has drop is + // The information required to determine whether a coroutine has drop is // computed on MIR, while this very method is used to build MIR. - // To avoid cycles, we consider that generators always require drop. - ty::Generator(..) => { + // To avoid cycles, we consider that coroutines always require drop. + ty::Coroutine(..) => { return Some(Err(AlwaysRequiresDrop)); } @@ -191,7 +191,7 @@ where | ty::FnPtr(..) | ty::Tuple(_) | ty::Bound(..) - | ty::GeneratorWitness(..) + | ty::CoroutineWitness(..) | ty::Never | ty::Infer(_) | ty::Error(_) => { diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 06a30677d2005..0010570e7b348 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -322,8 +322,8 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ | DefKind::LifetimeParam | DefKind::GlobalAsm | DefKind::Impl { .. } => {} - // Closures and generators are type checked with their parent, so there is no difference here. - DefKind::Closure | DefKind::Generator | DefKind::InlineConst => { + // Closures and coroutines are type checked with their parent, so there is no difference here. + DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst => { return tcx.opaque_types_defined_by(tcx.local_parent(item)); } } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index e1ec159921ec0..abf3e108ed484 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -14,13 +14,13 @@ fn sized_constraint_for_ty<'tcx>( adtdef: ty::AdtDef<'tcx>, ty: Ty<'tcx>, ) -> Vec> { - use rustc_type_ir::sty::TyKind::*; + use rustc_type_ir::TyKind::*; let result = match ty.kind() { Bool | Char | Int(..) | Uint(..) | Float(..) | RawPtr(..) | Ref(..) | FnDef(..) - | FnPtr(_) | Array(..) | Closure(..) | Generator(..) | Never => vec![], + | FnPtr(_) | Array(..) | Closure(..) | Coroutine(..) | Never => vec![], - Str | Dynamic(..) | Slice(_) | Foreign(..) | Error(_) | GeneratorWitness(..) => { + Str | Dynamic(..) | Slice(_) | Foreign(..) | Error(_) | CoroutineWitness(..) => { // these are never sized - return the target type vec![ty] } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs new file mode 100644 index 0000000000000..f84841c9f6455 --- /dev/null +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -0,0 +1,258 @@ +use rustc_data_structures::stable_hasher::HashStable; +use rustc_serialize::{Decodable, Decoder, Encodable}; +use std::cmp::Ordering; +use std::fmt; +use std::hash; + +use crate::{ + DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, OptWithInfcx, + TyDecoder, TyEncoder, +}; + +use self::ConstKind::*; + +/// Represents a constant in Rust. +// #[derive(derive_more::From)] +pub enum ConstKind { + /// A const generic parameter. + Param(I::ParamConst), + + /// Infer the value of the const. + Infer(I::InferConst), + + /// Bound const variable, used only when preparing a trait query. + Bound(DebruijnIndex, I::BoundConst), + + /// A placeholder const - universally quantified higher-ranked const. + Placeholder(I::PlaceholderConst), + + /// An unnormalized const item such as an anon const or assoc const or free const item. + /// Right now anything other than anon consts does not actually work properly but this + /// should + Unevaluated(I::AliasConst), + + /// Used to hold computed value. + Value(I::ValueConst), + + /// A placeholder for a const which could not be computed; this is + /// propagated to avoid useless error messages. + Error(I::ErrorGuaranteed), + + /// Unevaluated non-const-item, used by `feature(generic_const_exprs)` to represent + /// const arguments such as `N + 1` or `foo(N)` + Expr(I::ExprConst), +} + +const fn const_kind_discriminant(value: &ConstKind) -> usize { + match value { + Param(_) => 0, + Infer(_) => 1, + Bound(_, _) => 2, + Placeholder(_) => 3, + Unevaluated(_) => 4, + Value(_) => 5, + Error(_) => 6, + Expr(_) => 7, + } +} + +impl hash::Hash for ConstKind { + fn hash(&self, state: &mut H) { + const_kind_discriminant(self).hash(state); + match self { + Param(p) => p.hash(state), + Infer(i) => i.hash(state), + Bound(d, b) => { + d.hash(state); + b.hash(state); + } + Placeholder(p) => p.hash(state), + Unevaluated(u) => u.hash(state), + Value(v) => v.hash(state), + Error(e) => e.hash(state), + Expr(e) => e.hash(state), + } + } +} + +impl HashStable for ConstKind +where + I::ParamConst: HashStable, + I::InferConst: HashStable, + I::BoundConst: HashStable, + I::PlaceholderConst: HashStable, + I::AliasConst: HashStable, + I::ValueConst: HashStable, + I::ErrorGuaranteed: HashStable, + I::ExprConst: HashStable, +{ + fn hash_stable( + &self, + hcx: &mut CTX, + hasher: &mut rustc_data_structures::stable_hasher::StableHasher, + ) { + const_kind_discriminant(self).hash_stable(hcx, hasher); + match self { + Param(p) => p.hash_stable(hcx, hasher), + Infer(i) => i.hash_stable(hcx, hasher), + Bound(d, b) => { + d.hash_stable(hcx, hasher); + b.hash_stable(hcx, hasher); + } + Placeholder(p) => p.hash_stable(hcx, hasher), + Unevaluated(u) => u.hash_stable(hcx, hasher), + Value(v) => v.hash_stable(hcx, hasher), + Error(e) => e.hash_stable(hcx, hasher), + Expr(e) => e.hash_stable(hcx, hasher), + } + } +} + +impl> Decodable for ConstKind +where + I::ParamConst: Decodable, + I::InferConst: Decodable, + I::BoundConst: Decodable, + I::PlaceholderConst: Decodable, + I::AliasConst: Decodable, + I::ValueConst: Decodable, + I::ErrorGuaranteed: Decodable, + I::ExprConst: Decodable, +{ + fn decode(d: &mut D) -> Self { + match Decoder::read_usize(d) { + 0 => Param(Decodable::decode(d)), + 1 => Infer(Decodable::decode(d)), + 2 => Bound(Decodable::decode(d), Decodable::decode(d)), + 3 => Placeholder(Decodable::decode(d)), + 4 => Unevaluated(Decodable::decode(d)), + 5 => Value(Decodable::decode(d)), + 6 => Error(Decodable::decode(d)), + 7 => Expr(Decodable::decode(d)), + _ => panic!( + "{}", + format!( + "invalid enum variant tag while decoding `{}`, expected 0..{}", + "ConstKind", 8, + ) + ), + } + } +} + +impl> Encodable for ConstKind +where + I::ParamConst: Encodable, + I::InferConst: Encodable, + I::BoundConst: Encodable, + I::PlaceholderConst: Encodable, + I::AliasConst: Encodable, + I::ValueConst: Encodable, + I::ErrorGuaranteed: Encodable, + I::ExprConst: Encodable, +{ + fn encode(&self, e: &mut E) { + let disc = const_kind_discriminant(self); + match self { + Param(p) => e.emit_enum_variant(disc, |e| p.encode(e)), + Infer(i) => e.emit_enum_variant(disc, |e| i.encode(e)), + Bound(d, b) => e.emit_enum_variant(disc, |e| { + d.encode(e); + b.encode(e); + }), + Placeholder(p) => e.emit_enum_variant(disc, |e| p.encode(e)), + Unevaluated(u) => e.emit_enum_variant(disc, |e| u.encode(e)), + Value(v) => e.emit_enum_variant(disc, |e| v.encode(e)), + Error(er) => e.emit_enum_variant(disc, |e| er.encode(e)), + Expr(ex) => e.emit_enum_variant(disc, |e| ex.encode(e)), + } + } +} + +impl PartialOrd for ConstKind { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for ConstKind { + fn cmp(&self, other: &Self) -> Ordering { + const_kind_discriminant(self) + .cmp(&const_kind_discriminant(other)) + .then_with(|| match (self, other) { + (Param(p1), Param(p2)) => p1.cmp(p2), + (Infer(i1), Infer(i2)) => i1.cmp(i2), + (Bound(d1, b1), Bound(d2, b2)) => d1.cmp(d2).then_with(|| b1.cmp(b2)), + (Placeholder(p1), Placeholder(p2)) => p1.cmp(p2), + (Unevaluated(u1), Unevaluated(u2)) => u1.cmp(u2), + (Value(v1), Value(v2)) => v1.cmp(v2), + (Error(e1), Error(e2)) => e1.cmp(e2), + (Expr(e1), Expr(e2)) => e1.cmp(e2), + _ => { + debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}"); + Ordering::Equal + } + }) + } +} + +impl PartialEq for ConstKind { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Param(l0), Param(r0)) => l0 == r0, + (Infer(l0), Infer(r0)) => l0 == r0, + (Bound(l0, l1), Bound(r0, r1)) => l0 == r0 && l1 == r1, + (Placeholder(l0), Placeholder(r0)) => l0 == r0, + (Unevaluated(l0), Unevaluated(r0)) => l0 == r0, + (Value(l0), Value(r0)) => l0 == r0, + (Error(l0), Error(r0)) => l0 == r0, + (Expr(l0), Expr(r0)) => l0 == r0, + _ => false, + } + } +} + +impl Eq for ConstKind {} + +impl Clone for ConstKind { + fn clone(&self) -> Self { + match self { + Param(arg0) => Param(arg0.clone()), + Infer(arg0) => Infer(arg0.clone()), + Bound(arg0, arg1) => Bound(arg0.clone(), arg1.clone()), + Placeholder(arg0) => Placeholder(arg0.clone()), + Unevaluated(arg0) => Unevaluated(arg0.clone()), + Value(arg0) => Value(arg0.clone()), + Error(arg0) => Error(arg0.clone()), + Expr(arg0) => Expr(arg0.clone()), + } + } +} + +impl fmt::Debug for ConstKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + OptWithInfcx::new_no_ctx(self).fmt(f) + } +} + +impl DebugWithInfcx for ConstKind { + fn fmt>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut core::fmt::Formatter<'_>, + ) -> core::fmt::Result { + use ConstKind::*; + + match this.data { + Param(param) => write!(f, "{param:?}"), + Infer(var) => write!(f, "{:?}", &this.wrap(var)), + Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var.clone()), + Placeholder(placeholder) => write!(f, "{placeholder:?}"), + Unevaluated(uv) => { + write!(f, "{:?}", &this.wrap(uv)) + } + Value(valtree) => write!(f, "{valtree:?}"), + Error(_) => write!(f, "{{const error}}"), + Expr(expr) => write!(f, "{:?}", &this.wrap(expr)), + } + } +} diff --git a/compiler/rustc_type_ir/src/debug.rs b/compiler/rustc_type_ir/src/debug.rs new file mode 100644 index 0000000000000..7c6a784690073 --- /dev/null +++ b/compiler/rustc_type_ir/src/debug.rs @@ -0,0 +1,117 @@ +use crate::{Interner, UniverseIndex}; + +use core::fmt; +use std::marker::PhantomData; + +pub trait InferCtxtLike { + fn universe_of_ty(&self, ty: I::InferTy) -> Option; + + fn universe_of_lt(&self, lt: I::InferRegion) -> Option; + + fn universe_of_ct(&self, ct: I::InferConst) -> Option; +} + +impl InferCtxtLike for core::convert::Infallible { + fn universe_of_ty(&self, _ty: ::InferTy) -> Option { + match *self {} + } + + fn universe_of_ct(&self, _ct: ::InferConst) -> Option { + match *self {} + } + + fn universe_of_lt(&self, _lt: ::InferRegion) -> Option { + match *self {} + } +} + +pub trait DebugWithInfcx: fmt::Debug { + fn fmt>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result; +} + +impl + ?Sized> DebugWithInfcx for &'_ T { + fn fmt>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + >::fmt(this.map(|&data| data), f) + } +} + +impl> DebugWithInfcx for [T] { + fn fmt>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + match f.alternate() { + true => { + write!(f, "[\n")?; + for element in this.data.iter() { + write!(f, "{:?},\n", &this.wrap(element))?; + } + write!(f, "]") + } + false => { + write!(f, "[")?; + if this.data.len() > 0 { + for element in &this.data[..(this.data.len() - 1)] { + write!(f, "{:?}, ", &this.wrap(element))?; + } + if let Some(element) = this.data.last() { + write!(f, "{:?}", &this.wrap(element))?; + } + } + write!(f, "]") + } + } + } +} + +pub struct OptWithInfcx<'a, I: Interner, InfCtx: InferCtxtLike, T> { + pub data: T, + pub infcx: Option<&'a InfCtx>, + _interner: PhantomData, +} + +impl, T: Copy> Copy for OptWithInfcx<'_, I, InfCtx, T> {} + +impl, T: Clone> Clone for OptWithInfcx<'_, I, InfCtx, T> { + fn clone(&self) -> Self { + Self { data: self.data.clone(), infcx: self.infcx, _interner: self._interner } + } +} + +impl<'a, I: Interner, T> OptWithInfcx<'a, I, core::convert::Infallible, T> { + pub fn new_no_ctx(data: T) -> Self { + Self { data, infcx: None, _interner: PhantomData } + } +} + +impl<'a, I: Interner, InfCtx: InferCtxtLike, T> OptWithInfcx<'a, I, InfCtx, T> { + pub fn new(data: T, infcx: &'a InfCtx) -> Self { + Self { data, infcx: Some(infcx), _interner: PhantomData } + } + + pub fn wrap(self, u: U) -> OptWithInfcx<'a, I, InfCtx, U> { + OptWithInfcx { data: u, infcx: self.infcx, _interner: PhantomData } + } + + pub fn map(self, f: impl FnOnce(T) -> U) -> OptWithInfcx<'a, I, InfCtx, U> { + OptWithInfcx { data: f(self.data), infcx: self.infcx, _interner: PhantomData } + } + + pub fn as_ref(&self) -> OptWithInfcx<'a, I, InfCtx, &T> { + OptWithInfcx { data: &self.data, infcx: self.infcx, _interner: PhantomData } + } +} + +impl, T: DebugWithInfcx> fmt::Debug + for OptWithInfcx<'_, I, InfCtx, T> +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + DebugWithInfcx::fmt(self.as_ref(), f) + } +} diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs new file mode 100644 index 0000000000000..2acb903c217a1 --- /dev/null +++ b/compiler/rustc_type_ir/src/flags.rs @@ -0,0 +1,119 @@ +bitflags! { + /// Flags that we track on types. These flags are propagated upwards + /// through the type during type construction, so that we can quickly check + /// whether the type has various kinds of types in it without recursing + /// over the type itself. + pub struct TypeFlags: u32 { + // Does this have parameters? Used to determine whether substitution is + // required. + /// Does this have `Param`? + const HAS_TY_PARAM = 1 << 0; + /// Does this have `ReEarlyBound`? + const HAS_RE_PARAM = 1 << 1; + /// Does this have `ConstKind::Param`? + const HAS_CT_PARAM = 1 << 2; + + const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits + | TypeFlags::HAS_RE_PARAM.bits + | TypeFlags::HAS_CT_PARAM.bits; + + /// Does this have `Infer`? + const HAS_TY_INFER = 1 << 3; + /// Does this have `ReVar`? + const HAS_RE_INFER = 1 << 4; + /// Does this have `ConstKind::Infer`? + const HAS_CT_INFER = 1 << 5; + + /// Does this have inference variables? Used to determine whether + /// inference is required. + const HAS_INFER = TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_RE_INFER.bits + | TypeFlags::HAS_CT_INFER.bits; + + /// Does this have `Placeholder`? + const HAS_TY_PLACEHOLDER = 1 << 6; + /// Does this have `RePlaceholder`? + const HAS_RE_PLACEHOLDER = 1 << 7; + /// Does this have `ConstKind::Placeholder`? + const HAS_CT_PLACEHOLDER = 1 << 8; + + /// Does this have placeholders? + const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits + | TypeFlags::HAS_RE_PLACEHOLDER.bits + | TypeFlags::HAS_CT_PLACEHOLDER.bits; + + /// `true` if there are "names" of regions and so forth + /// that are local to a particular fn/inferctxt + const HAS_FREE_LOCAL_REGIONS = 1 << 9; + + /// `true` if there are "names" of types and regions and so forth + /// that are local to a particular fn + const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits + | TypeFlags::HAS_CT_PARAM.bits + | TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_CT_INFER.bits + | TypeFlags::HAS_TY_PLACEHOLDER.bits + | TypeFlags::HAS_CT_PLACEHOLDER.bits + // We consider 'freshened' types and constants + // to depend on a particular fn. + // The freshening process throws away information, + // which can make things unsuitable for use in a global + // cache. Note that there is no 'fresh lifetime' flag - + // freshening replaces all lifetimes with `ReErased`, + // which is different from how types/const are freshened. + | TypeFlags::HAS_TY_FRESH.bits + | TypeFlags::HAS_CT_FRESH.bits + | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits + | TypeFlags::HAS_RE_ERASED.bits; + + /// Does this have `Projection`? + const HAS_TY_PROJECTION = 1 << 10; + /// Does this have `Inherent`? + const HAS_TY_INHERENT = 1 << 11; + /// Does this have `Opaque`? + const HAS_TY_OPAQUE = 1 << 12; + /// Does this have `ConstKind::Unevaluated`? + const HAS_CT_PROJECTION = 1 << 13; + + /// Could this type be normalized further? + const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits + | TypeFlags::HAS_TY_OPAQUE.bits + | TypeFlags::HAS_TY_INHERENT.bits + | TypeFlags::HAS_CT_PROJECTION.bits; + + /// Is an error type/const reachable? + const HAS_ERROR = 1 << 14; + + /// Does this have any region that "appears free" in the type? + /// Basically anything but `ReLateBound` and `ReErased`. + const HAS_FREE_REGIONS = 1 << 15; + + /// Does this have any `ReLateBound` regions? + const HAS_RE_LATE_BOUND = 1 << 16; + /// Does this have any `Bound` types? + const HAS_TY_LATE_BOUND = 1 << 17; + /// Does this have any `ConstKind::Bound` consts? + const HAS_CT_LATE_BOUND = 1 << 18; + /// Does this have any bound variables? + /// Used to check if a global bound is safe to evaluate. + const HAS_LATE_BOUND = TypeFlags::HAS_RE_LATE_BOUND.bits + | TypeFlags::HAS_TY_LATE_BOUND.bits + | TypeFlags::HAS_CT_LATE_BOUND.bits; + + /// Does this have any `ReErased` regions? + const HAS_RE_ERASED = 1 << 19; + + /// Does this value have parameters/placeholders/inference variables which could be + /// replaced later, in a way that would change the results of `impl` specialization? + const STILL_FURTHER_SPECIALIZABLE = 1 << 20; + + /// Does this value have `InferTy::FreshTy/FreshIntTy/FreshFloatTy`? + const HAS_TY_FRESH = 1 << 21; + + /// Does this value have `InferConst::Fresh`? + const HAS_CT_FRESH = 1 << 22; + + /// Does this have `Generator` or `GeneratorWitness`? + const HAS_TY_GENERATOR = 1 << 23; + } +} diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index e7a6831f5ee35..fc56400df1614 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -44,6 +44,11 @@ //! - ty.super_fold_with(folder) //! - u.fold_with(folder) //! ``` + +use rustc_data_structures::sync::Lrc; +use rustc_index::{Idx, IndexVec}; +use std::mem; + use crate::{visit::TypeVisitable, Interner}; /// This trait is implemented for every type that can be folded, @@ -242,3 +247,101 @@ where Ok(self.fold_predicate(p)) } } + +/////////////////////////////////////////////////////////////////////////// +// Traversal implementations. + +impl, U: TypeFoldable> TypeFoldable for (T, U) { + fn try_fold_with>(self, folder: &mut F) -> Result<(T, U), F::Error> { + Ok((self.0.try_fold_with(folder)?, self.1.try_fold_with(folder)?)) + } +} + +impl, B: TypeFoldable, C: TypeFoldable> TypeFoldable + for (A, B, C) +{ + fn try_fold_with>( + self, + folder: &mut F, + ) -> Result<(A, B, C), F::Error> { + Ok(( + self.0.try_fold_with(folder)?, + self.1.try_fold_with(folder)?, + self.2.try_fold_with(folder)?, + )) + } +} + +impl> TypeFoldable for Option { + fn try_fold_with>(self, folder: &mut F) -> Result { + Ok(match self { + Some(v) => Some(v.try_fold_with(folder)?), + None => None, + }) + } +} + +impl, E: TypeFoldable> TypeFoldable for Result { + fn try_fold_with>(self, folder: &mut F) -> Result { + Ok(match self { + Ok(v) => Ok(v.try_fold_with(folder)?), + Err(e) => Err(e.try_fold_with(folder)?), + }) + } +} + +impl> TypeFoldable for Lrc { + fn try_fold_with>(mut self, folder: &mut F) -> Result { + // We merely want to replace the contained `T`, if at all possible, + // so that we don't needlessly allocate a new `Lrc` or indeed clone + // the contained type. + unsafe { + // First step is to ensure that we have a unique reference to + // the contained type, which `Lrc::make_mut` will accomplish (by + // allocating a new `Lrc` and cloning the `T` only if required). + // This is done *before* casting to `Lrc>` so that + // panicking during `make_mut` does not leak the `T`. + Lrc::make_mut(&mut self); + + // Casting to `Lrc>` is safe because `ManuallyDrop` + // is `repr(transparent)`. + let ptr = Lrc::into_raw(self).cast::>(); + let mut unique = Lrc::from_raw(ptr); + + // Call to `Lrc::make_mut` above guarantees that `unique` is the + // sole reference to the contained value, so we can avoid doing + // a checked `get_mut` here. + let slot = Lrc::get_mut_unchecked(&mut unique); + + // Semantically move the contained type out from `unique`, fold + // it, then move the folded value back into `unique`. Should + // folding fail, `ManuallyDrop` ensures that the "moved-out" + // value is not re-dropped. + let owned = mem::ManuallyDrop::take(slot); + let folded = owned.try_fold_with(folder)?; + *slot = mem::ManuallyDrop::new(folded); + + // Cast back to `Lrc`. + Ok(Lrc::from_raw(Lrc::into_raw(unique).cast())) + } + } +} + +impl> TypeFoldable for Box { + fn try_fold_with>(mut self, folder: &mut F) -> Result { + *self = (*self).try_fold_with(folder)?; + Ok(self) + } +} + +impl> TypeFoldable for Vec { + fn try_fold_with>(self, folder: &mut F) -> Result { + self.into_iter().map(|t| t.try_fold_with(folder)).collect() + } +} + +impl, Ix: Idx> TypeFoldable for IndexVec { + fn try_fold_with>(self, folder: &mut F) -> Result { + self.raw.try_fold_with(folder).map(IndexVec::from_raw) + } +} diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs new file mode 100644 index 0000000000000..60e4c58799358 --- /dev/null +++ b/compiler/rustc_type_ir/src/interner.rs @@ -0,0 +1,155 @@ +use smallvec::SmallVec; +use std::fmt::Debug; +use std::hash::Hash; + +use crate::{DebugWithInfcx, Mutability}; + +pub trait Interner: Sized { + type DefId: Clone + Debug + Hash + Ord; + type AdtDef: Clone + Debug + Hash + Ord; + + type GenericArgs: Clone + + DebugWithInfcx + + Hash + + Ord + + IntoIterator; + type GenericArg: Clone + DebugWithInfcx + Hash + Ord; + + type Binder; + + // Predicates + type Predicate; + type PredicateKind: Clone + Debug + Hash + PartialEq + Eq; + + type TypeAndMut: Clone + Debug + Hash + Ord; + + // Kinds of tys + type Ty: Clone + DebugWithInfcx + Hash + Ord; + type Tys: Clone + Debug + Hash + Ord + IntoIterator; + type AliasTy: Clone + DebugWithInfcx + Hash + Ord; + type ParamTy: Clone + Debug + Hash + Ord; + type BoundTy: Clone + Debug + Hash + Ord; + type PlaceholderTy: Clone + Debug + Hash + Ord; + type InferTy: Clone + DebugWithInfcx + Hash + Ord; + + // Things stored inside of tys + type ErrorGuaranteed: Clone + Debug + Hash + Ord; + type BoundExistentialPredicates: Clone + DebugWithInfcx + Hash + Ord; + type PolyFnSig: Clone + DebugWithInfcx + Hash + Ord; + type AllocId: Clone + Debug + Hash + Ord; + + // Kinds of consts + type Const: Clone + DebugWithInfcx + Hash + Ord; + type InferConst: Clone + DebugWithInfcx + Hash + Ord; + type AliasConst: Clone + DebugWithInfcx + Hash + Ord; + type PlaceholderConst: Clone + Debug + Hash + Ord; + type ParamConst: Clone + Debug + Hash + Ord; + type BoundConst: Clone + Debug + Hash + Ord; + type ValueConst: Clone + Debug + Hash + Ord; + type ExprConst: Clone + DebugWithInfcx + Hash + Ord; + + // Kinds of regions + type Region: Clone + DebugWithInfcx + Hash + Ord; + type EarlyBoundRegion: Clone + Debug + Hash + Ord; + type BoundRegion: Clone + Debug + Hash + Ord; + type FreeRegion: Clone + Debug + Hash + Ord; + type InferRegion: Clone + DebugWithInfcx + Hash + Ord; + type PlaceholderRegion: Clone + Debug + Hash + Ord; + + fn ty_and_mut_to_parts(ty_and_mut: Self::TypeAndMut) -> (Self::Ty, Mutability); +} + +/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter` +/// that produces `T` items. You could combine them with +/// `f(&iter.collect::>())`, but this requires allocating memory for the +/// `Vec`. +/// +/// This trait allows for faster implementations, intended for cases where the +/// number of items produced by the iterator is small. There is a blanket impl +/// for `T` items, but there is also a fallible impl for `Result` items. +pub trait CollectAndApply: Sized { + type Output; + + /// Produce a result of type `Self::Output` from `iter`. The result will + /// typically be produced by applying `f` on the elements produced by + /// `iter`, though this may not happen in some impls, e.g. if an error + /// occurred during iteration. + fn collect_and_apply(iter: I, f: F) -> Self::Output + where + I: Iterator, + F: FnOnce(&[T]) -> R; +} + +/// The blanket impl that always collects all elements and applies `f`. +impl CollectAndApply for T { + type Output = R; + + /// Equivalent to `f(&iter.collect::>())`. + fn collect_and_apply(mut iter: I, f: F) -> R + where + I: Iterator, + F: FnOnce(&[T]) -> R, + { + // This code is hot enough that it's worth specializing for the most + // common length lists, to avoid the overhead of `SmallVec` creation. + // Lengths 0, 1, and 2 typically account for ~95% of cases. If + // `size_hint` is incorrect a panic will occur via an `unwrap` or an + // `assert`. + match iter.size_hint() { + (0, Some(0)) => { + assert!(iter.next().is_none()); + f(&[]) + } + (1, Some(1)) => { + let t0 = iter.next().unwrap(); + assert!(iter.next().is_none()); + f(&[t0]) + } + (2, Some(2)) => { + let t0 = iter.next().unwrap(); + let t1 = iter.next().unwrap(); + assert!(iter.next().is_none()); + f(&[t0, t1]) + } + _ => f(&iter.collect::>()), + } + } +} + +/// A fallible impl that will fail, without calling `f`, if there are any +/// errors during collection. +impl CollectAndApply for Result { + type Output = Result; + + /// Equivalent to `Ok(f(&iter.collect::>>()?))`. + fn collect_and_apply(mut iter: I, f: F) -> Result + where + I: Iterator>, + F: FnOnce(&[T]) -> R, + { + // This code is hot enough that it's worth specializing for the most + // common length lists, to avoid the overhead of `SmallVec` creation. + // Lengths 0, 1, and 2 typically account for ~95% of cases. If + // `size_hint` is incorrect a panic will occur via an `unwrap` or an + // `assert`, unless a failure happens first, in which case the result + // will be an error anyway. + Ok(match iter.size_hint() { + (0, Some(0)) => { + assert!(iter.next().is_none()); + f(&[]) + } + (1, Some(1)) => { + let t0 = iter.next().unwrap()?; + assert!(iter.next().is_none()); + f(&[t0]) + } + (2, Some(2)) => { + let t0 = iter.next().unwrap()?; + let t1 = iter.next().unwrap()?; + assert!(iter.next().is_none()); + f(&[t0, t1]) + } + _ => f(&iter.collect::, _>>()?), + }) + } +} diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 0a35e8d3a90c2..d4ca9da96e4ed 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -15,302 +15,35 @@ extern crate bitflags; #[macro_use] extern crate rustc_macros; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use rustc_data_structures::unify::{EqUnifyValue, UnifyKey}; -use smallvec::SmallVec; use std::fmt; -use std::fmt::Debug; use std::hash::Hash; -use std::mem::discriminant; pub mod codec; pub mod fold; -pub mod sty; pub mod ty_info; +pub mod ty_kind; pub mod visit; #[macro_use] mod macros; -mod structural_impls; +mod const_kind; +mod debug; +mod flags; +mod interner; +mod region_kind; pub use codec::*; -pub use structural_impls::{DebugWithInfcx, InferCtxtLike, OptWithInfcx}; -pub use sty::*; +pub use const_kind::*; +pub use debug::{DebugWithInfcx, InferCtxtLike, OptWithInfcx}; +pub use flags::*; +pub use interner::*; +pub use region_kind::*; pub use ty_info::*; +pub use ty_kind::*; /// Needed so we can use #[derive(HashStable_Generic)] pub trait HashStableContext {} -pub trait Interner: Sized { - type DefId: Clone + Debug + Hash + Ord; - type AdtDef: Clone + Debug + Hash + Ord; - - type GenericArgs: Clone - + DebugWithInfcx - + Hash - + Ord - + IntoIterator; - type GenericArg: Clone + DebugWithInfcx + Hash + Ord; - - type Binder; - - // Predicates - type Predicate; - type PredicateKind: Clone + Debug + Hash + PartialEq + Eq; - - type TypeAndMut: Clone + Debug + Hash + Ord; - - // Kinds of tys - type Ty: Clone + DebugWithInfcx + Hash + Ord; - type Tys: Clone + Debug + Hash + Ord + IntoIterator; - type AliasTy: Clone + DebugWithInfcx + Hash + Ord; - type ParamTy: Clone + Debug + Hash + Ord; - type BoundTy: Clone + Debug + Hash + Ord; - type PlaceholderTy: Clone + Debug + Hash + Ord; - type InferTy: Clone + DebugWithInfcx + Hash + Ord; - - // Things stored inside of tys - type ErrorGuaranteed: Clone + Debug + Hash + Ord; - type BoundExistentialPredicates: Clone + DebugWithInfcx + Hash + Ord; - type PolyFnSig: Clone + DebugWithInfcx + Hash + Ord; - type AllocId: Clone + Debug + Hash + Ord; - - // Kinds of consts - type Const: Clone + DebugWithInfcx + Hash + Ord; - type InferConst: Clone + DebugWithInfcx + Hash + Ord; - type AliasConst: Clone + DebugWithInfcx + Hash + Ord; - type PlaceholderConst: Clone + Debug + Hash + Ord; - type ParamConst: Clone + Debug + Hash + Ord; - type BoundConst: Clone + Debug + Hash + Ord; - type ValueConst: Clone + Debug + Hash + Ord; - type ExprConst: Clone + DebugWithInfcx + Hash + Ord; - - // Kinds of regions - type Region: Clone + DebugWithInfcx + Hash + Ord; - type EarlyBoundRegion: Clone + Debug + Hash + Ord; - type BoundRegion: Clone + Debug + Hash + Ord; - type FreeRegion: Clone + Debug + Hash + Ord; - type InferRegion: Clone + DebugWithInfcx + Hash + Ord; - type PlaceholderRegion: Clone + Debug + Hash + Ord; - - fn ty_and_mut_to_parts(ty_and_mut: Self::TypeAndMut) -> (Self::Ty, Mutability); -} - -/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter` -/// that produces `T` items. You could combine them with -/// `f(&iter.collect::>())`, but this requires allocating memory for the -/// `Vec`. -/// -/// This trait allows for faster implementations, intended for cases where the -/// number of items produced by the iterator is small. There is a blanket impl -/// for `T` items, but there is also a fallible impl for `Result` items. -pub trait CollectAndApply: Sized { - type Output; - - /// Produce a result of type `Self::Output` from `iter`. The result will - /// typically be produced by applying `f` on the elements produced by - /// `iter`, though this may not happen in some impls, e.g. if an error - /// occurred during iteration. - fn collect_and_apply(iter: I, f: F) -> Self::Output - where - I: Iterator, - F: FnOnce(&[T]) -> R; -} - -/// The blanket impl that always collects all elements and applies `f`. -impl CollectAndApply for T { - type Output = R; - - /// Equivalent to `f(&iter.collect::>())`. - fn collect_and_apply(mut iter: I, f: F) -> R - where - I: Iterator, - F: FnOnce(&[T]) -> R, - { - // This code is hot enough that it's worth specializing for the most - // common length lists, to avoid the overhead of `SmallVec` creation. - // Lengths 0, 1, and 2 typically account for ~95% of cases. If - // `size_hint` is incorrect a panic will occur via an `unwrap` or an - // `assert`. - match iter.size_hint() { - (0, Some(0)) => { - assert!(iter.next().is_none()); - f(&[]) - } - (1, Some(1)) => { - let t0 = iter.next().unwrap(); - assert!(iter.next().is_none()); - f(&[t0]) - } - (2, Some(2)) => { - let t0 = iter.next().unwrap(); - let t1 = iter.next().unwrap(); - assert!(iter.next().is_none()); - f(&[t0, t1]) - } - _ => f(&iter.collect::>()), - } - } -} - -/// A fallible impl that will fail, without calling `f`, if there are any -/// errors during collection. -impl CollectAndApply for Result { - type Output = Result; - - /// Equivalent to `Ok(f(&iter.collect::>>()?))`. - fn collect_and_apply(mut iter: I, f: F) -> Result - where - I: Iterator>, - F: FnOnce(&[T]) -> R, - { - // This code is hot enough that it's worth specializing for the most - // common length lists, to avoid the overhead of `SmallVec` creation. - // Lengths 0, 1, and 2 typically account for ~95% of cases. If - // `size_hint` is incorrect a panic will occur via an `unwrap` or an - // `assert`, unless a failure happens first, in which case the result - // will be an error anyway. - Ok(match iter.size_hint() { - (0, Some(0)) => { - assert!(iter.next().is_none()); - f(&[]) - } - (1, Some(1)) => { - let t0 = iter.next().unwrap()?; - assert!(iter.next().is_none()); - f(&[t0]) - } - (2, Some(2)) => { - let t0 = iter.next().unwrap()?; - let t1 = iter.next().unwrap()?; - assert!(iter.next().is_none()); - f(&[t0, t1]) - } - _ => f(&iter.collect::, _>>()?), - }) - } -} - -bitflags! { - /// Flags that we track on types. These flags are propagated upwards - /// through the type during type construction, so that we can quickly check - /// whether the type has various kinds of types in it without recursing - /// over the type itself. - pub struct TypeFlags: u32 { - // Does this have parameters? Used to determine whether substitution is - // required. - /// Does this have `Param`? - const HAS_TY_PARAM = 1 << 0; - /// Does this have `ReEarlyBound`? - const HAS_RE_PARAM = 1 << 1; - /// Does this have `ConstKind::Param`? - const HAS_CT_PARAM = 1 << 2; - - const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_RE_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits; - - /// Does this have `Infer`? - const HAS_TY_INFER = 1 << 3; - /// Does this have `ReVar`? - const HAS_RE_INFER = 1 << 4; - /// Does this have `ConstKind::Infer`? - const HAS_CT_INFER = 1 << 5; - - /// Does this have inference variables? Used to determine whether - /// inference is required. - const HAS_INFER = TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_RE_INFER.bits - | TypeFlags::HAS_CT_INFER.bits; - - /// Does this have `Placeholder`? - const HAS_TY_PLACEHOLDER = 1 << 6; - /// Does this have `RePlaceholder`? - const HAS_RE_PLACEHOLDER = 1 << 7; - /// Does this have `ConstKind::Placeholder`? - const HAS_CT_PLACEHOLDER = 1 << 8; - - /// Does this have placeholders? - const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_RE_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits; - - /// `true` if there are "names" of regions and so forth - /// that are local to a particular fn/inferctxt - const HAS_FREE_LOCAL_REGIONS = 1 << 9; - - /// `true` if there are "names" of types and regions and so forth - /// that are local to a particular fn - const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits - | TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_CT_INFER.bits - | TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits - // We consider 'freshened' types and constants - // to depend on a particular fn. - // The freshening process throws away information, - // which can make things unsuitable for use in a global - // cache. Note that there is no 'fresh lifetime' flag - - // freshening replaces all lifetimes with `ReErased`, - // which is different from how types/const are freshened. - | TypeFlags::HAS_TY_FRESH.bits - | TypeFlags::HAS_CT_FRESH.bits - | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits - | TypeFlags::HAS_RE_ERASED.bits; - - /// Does this have `Projection`? - const HAS_TY_PROJECTION = 1 << 10; - /// Does this have `Inherent`? - const HAS_TY_INHERENT = 1 << 11; - /// Does this have `Opaque`? - const HAS_TY_OPAQUE = 1 << 12; - /// Does this have `ConstKind::Unevaluated`? - const HAS_CT_PROJECTION = 1 << 13; - - /// Could this type be normalized further? - const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits - | TypeFlags::HAS_TY_OPAQUE.bits - | TypeFlags::HAS_TY_INHERENT.bits - | TypeFlags::HAS_CT_PROJECTION.bits; - - /// Is an error type/const reachable? - const HAS_ERROR = 1 << 14; - - /// Does this have any region that "appears free" in the type? - /// Basically anything but `ReLateBound` and `ReErased`. - const HAS_FREE_REGIONS = 1 << 15; - - /// Does this have any `ReLateBound` regions? - const HAS_RE_LATE_BOUND = 1 << 16; - /// Does this have any `Bound` types? - const HAS_TY_LATE_BOUND = 1 << 17; - /// Does this have any `ConstKind::Bound` consts? - const HAS_CT_LATE_BOUND = 1 << 18; - /// Does this have any bound variables? - /// Used to check if a global bound is safe to evaluate. - const HAS_LATE_BOUND = TypeFlags::HAS_RE_LATE_BOUND.bits - | TypeFlags::HAS_TY_LATE_BOUND.bits - | TypeFlags::HAS_CT_LATE_BOUND.bits; - - /// Does this have any `ReErased` regions? - const HAS_RE_ERASED = 1 << 19; - - /// Does this value have parameters/placeholders/inference variables which could be - /// replaced later, in a way that would change the results of `impl` specialization? - const STILL_FURTHER_SPECIALIZABLE = 1 << 20; - - /// Does this value have `InferTy::FreshTy/FreshIntTy/FreshFloatTy`? - const HAS_TY_FRESH = 1 << 21; - - /// Does this value have `InferConst::Fresh`? - const HAS_CT_FRESH = 1 << 22; - - /// Does this have `Generator` or `GeneratorWitness`? - const HAS_TY_GENERATOR = 1 << 23; - } -} - rustc_index::newtype_index! { /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In @@ -434,259 +167,6 @@ pub fn debug_bound_var( } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[derive(Encodable, Decodable, HashStable_Generic)] -pub enum IntTy { - Isize, - I8, - I16, - I32, - I64, - I128, -} - -impl IntTy { - pub fn name_str(&self) -> &'static str { - match *self { - IntTy::Isize => "isize", - IntTy::I8 => "i8", - IntTy::I16 => "i16", - IntTy::I32 => "i32", - IntTy::I64 => "i64", - IntTy::I128 => "i128", - } - } - - pub fn bit_width(&self) -> Option { - Some(match *self { - IntTy::Isize => return None, - IntTy::I8 => 8, - IntTy::I16 => 16, - IntTy::I32 => 32, - IntTy::I64 => 64, - IntTy::I128 => 128, - }) - } - - pub fn normalize(&self, target_width: u32) -> Self { - match self { - IntTy::Isize => match target_width { - 16 => IntTy::I16, - 32 => IntTy::I32, - 64 => IntTy::I64, - _ => unreachable!(), - }, - _ => *self, - } - } - - pub fn to_unsigned(self) -> UintTy { - match self { - IntTy::Isize => UintTy::Usize, - IntTy::I8 => UintTy::U8, - IntTy::I16 => UintTy::U16, - IntTy::I32 => UintTy::U32, - IntTy::I64 => UintTy::U64, - IntTy::I128 => UintTy::U128, - } - } -} - -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] -#[derive(Encodable, Decodable, HashStable_Generic)] -pub enum UintTy { - Usize, - U8, - U16, - U32, - U64, - U128, -} - -impl UintTy { - pub fn name_str(&self) -> &'static str { - match *self { - UintTy::Usize => "usize", - UintTy::U8 => "u8", - UintTy::U16 => "u16", - UintTy::U32 => "u32", - UintTy::U64 => "u64", - UintTy::U128 => "u128", - } - } - - pub fn bit_width(&self) -> Option { - Some(match *self { - UintTy::Usize => return None, - UintTy::U8 => 8, - UintTy::U16 => 16, - UintTy::U32 => 32, - UintTy::U64 => 64, - UintTy::U128 => 128, - }) - } - - pub fn normalize(&self, target_width: u32) -> Self { - match self { - UintTy::Usize => match target_width { - 16 => UintTy::U16, - 32 => UintTy::U32, - 64 => UintTy::U64, - _ => unreachable!(), - }, - _ => *self, - } - } - - pub fn to_signed(self) -> IntTy { - match self { - UintTy::Usize => IntTy::Isize, - UintTy::U8 => IntTy::I8, - UintTy::U16 => IntTy::I16, - UintTy::U32 => IntTy::I32, - UintTy::U64 => IntTy::I64, - UintTy::U128 => IntTy::I128, - } - } -} - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[derive(Encodable, Decodable, HashStable_Generic)] -pub enum FloatTy { - F32, - F64, -} - -impl FloatTy { - pub fn name_str(self) -> &'static str { - match self { - FloatTy::F32 => "f32", - FloatTy::F64 => "f64", - } - } - - pub fn bit_width(self) -> u64 { - match self { - FloatTy::F32 => 32, - FloatTy::F64 => 64, - } - } -} - -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum IntVarValue { - IntType(IntTy), - UintType(UintTy), -} - -#[derive(Clone, Copy, PartialEq, Eq)] -pub struct FloatVarValue(pub FloatTy); - -rustc_index::newtype_index! { - /// A **ty**pe **v**ariable **ID**. - #[debug_format = "?{}t"] - pub struct TyVid {} -} - -rustc_index::newtype_index! { - /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. - #[debug_format = "?{}i"] - pub struct IntVid {} -} - -rustc_index::newtype_index! { - /// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**. - #[debug_format = "?{}f"] - pub struct FloatVid {} -} - -/// A placeholder for a type that hasn't been inferred yet. -/// -/// E.g., if we have an empty array (`[]`), then we create a fresh -/// type variable for the element type since we won't know until it's -/// used what the element type is supposed to be. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] -pub enum InferTy { - /// A type variable. - TyVar(TyVid), - /// An integral type variable (`{integer}`). - /// - /// These are created when the compiler sees an integer literal like - /// `1` that could be several different types (`u8`, `i32`, `u32`, etc.). - /// We don't know until it's used what type it's supposed to be, so - /// we create a fresh type variable. - IntVar(IntVid), - /// A floating-point type variable (`{float}`). - /// - /// These are created when the compiler sees an float literal like - /// `1.0` that could be either an `f32` or an `f64`. - /// We don't know until it's used what type it's supposed to be, so - /// we create a fresh type variable. - FloatVar(FloatVid), - - /// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement - /// for an unbound type variable. This is convenient for caching etc. See - /// `rustc_infer::infer::freshen` for more details. - /// - /// Compare with [`TyVar`][Self::TyVar]. - FreshTy(u32), - /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar]. - FreshIntTy(u32), - /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar]. - FreshFloatTy(u32), -} - -/// Raw `TyVid` are used as the unification key for `sub_relations`; -/// they carry no values. -impl UnifyKey for TyVid { - type Value = (); - #[inline] - fn index(&self) -> u32 { - self.as_u32() - } - #[inline] - fn from_index(i: u32) -> TyVid { - TyVid::from_u32(i) - } - fn tag() -> &'static str { - "TyVid" - } -} - -impl EqUnifyValue for IntVarValue {} - -impl UnifyKey for IntVid { - type Value = Option; - #[inline] // make this function eligible for inlining - it is quite hot. - fn index(&self) -> u32 { - self.as_u32() - } - #[inline] - fn from_index(i: u32) -> IntVid { - IntVid::from_u32(i) - } - fn tag() -> &'static str { - "IntVid" - } -} - -impl EqUnifyValue for FloatVarValue {} - -impl UnifyKey for FloatVid { - type Value = Option; - #[inline] - fn index(&self) -> u32 { - self.as_u32() - } - #[inline] - fn from_index(i: u32) -> FloatVid { - FloatVid::from_u32(i) - } - fn tag() -> &'static str { - "FloatVid" - } -} - #[derive(Copy, Clone, PartialEq, Eq, Decodable, Encodable, Hash, HashStable_Generic)] #[rustc_pass_by_value] pub enum Variance { @@ -756,34 +236,6 @@ impl Variance { } } -impl HashStable for InferTy { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - use InferTy::*; - discriminant(self).hash_stable(ctx, hasher); - match self { - TyVar(_) | IntVar(_) | FloatVar(_) => { - panic!("type variables should not be hashed: {self:?}") - } - FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher), - } - } -} - -impl fmt::Debug for IntVarValue { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - IntVarValue::IntType(ref v) => v.fmt(f), - IntVarValue::UintType(ref v) => v.fmt(f), - } - } -} - -impl fmt::Debug for FloatVarValue { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - impl fmt::Debug for Variance { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(match *self { @@ -795,20 +247,6 @@ impl fmt::Debug for Variance { } } -impl fmt::Display for InferTy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use InferTy::*; - match *self { - TyVar(_) => write!(f, "_"), - IntVar(_) => write!(f, "{}", "{integer}"), - FloatVar(_) => write!(f, "{}", "{float}"), - FreshTy(v) => write!(f, "FreshTy({v})"), - FreshIntTy(v) => write!(f, "FreshIntTy({v})"), - FreshFloatTy(v) => write!(f, "FreshFloatTy({v})"), - } - } -} - rustc_index::newtype_index! { /// "Universes" are used during type- and trait-checking in the /// presence of `for<..>` binders to control what sets of names are diff --git a/compiler/rustc_type_ir/src/macros.rs b/compiler/rustc_type_ir/src/macros.rs index 8c3cb22832299..9e10c65c20dc4 100644 --- a/compiler/rustc_type_ir/src/macros.rs +++ b/compiler/rustc_type_ir/src/macros.rs @@ -33,3 +33,20 @@ macro_rules! TrivialTypeTraversalImpls { )+ }; } + +/////////////////////////////////////////////////////////////////////////// +// Atomic structs +// +// For things that don't carry any arena-allocated data (and are +// copy...), just add them to this list. + +TrivialTypeTraversalImpls! { + (), + bool, + usize, + u16, + u32, + u64, + String, + crate::DebruijnIndex, +} diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs new file mode 100644 index 0000000000000..0006eec4d3007 --- /dev/null +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -0,0 +1,412 @@ +use rustc_data_structures::stable_hasher::HashStable; +use rustc_serialize::{Decodable, Decoder, Encodable}; +use std::cmp::Ordering; +use std::fmt; +use std::hash; + +use crate::{ + DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, OptWithInfcx, + TyDecoder, TyEncoder, +}; + +use self::RegionKind::*; + +/// Representation of regions. Note that the NLL checker uses a distinct +/// representation of regions. For this reason, it internally replaces all the +/// regions with inference variables -- the index of the variable is then used +/// to index into internal NLL data structures. See `rustc_const_eval::borrow_check` +/// module for more information. +/// +/// Note: operations are on the wrapper `Region` type, which is interned, +/// rather than this type. +/// +/// ## The Region lattice within a given function +/// +/// In general, the region lattice looks like +/// +/// ```text +/// static ----------+-----...------+ (greatest) +/// | | | +/// early-bound and | | +/// free regions | | +/// | | | +/// | | | +/// empty(root) placeholder(U1) | +/// | / | +/// | / placeholder(Un) +/// empty(U1) -- / +/// | / +/// ... / +/// | / +/// empty(Un) -------- (smallest) +/// ``` +/// +/// Early-bound/free regions are the named lifetimes in scope from the +/// function declaration. They have relationships to one another +/// determined based on the declared relationships from the +/// function. +/// +/// Note that inference variables and bound regions are not included +/// in this diagram. In the case of inference variables, they should +/// be inferred to some other region from the diagram. In the case of +/// bound regions, they are excluded because they don't make sense to +/// include -- the diagram indicates the relationship between free +/// regions. +/// +/// ## Inference variables +/// +/// During region inference, we sometimes create inference variables, +/// represented as `ReVar`. These will be inferred by the code in +/// `infer::lexical_region_resolve` to some free region from the +/// lattice above (the minimal region that meets the +/// constraints). +/// +/// During NLL checking, where regions are defined differently, we +/// also use `ReVar` -- in that case, the index is used to index into +/// the NLL region checker's data structures. The variable may in fact +/// represent either a free region or an inference variable, in that +/// case. +/// +/// ## Bound Regions +/// +/// These are regions that are stored behind a binder and must be substituted +/// with some concrete region before being used. There are two kind of +/// bound regions: early-bound, which are bound in an item's `Generics`, +/// and are substituted by an `GenericArgs`, and late-bound, which are part of +/// higher-ranked types (e.g., `for<'a> fn(&'a ())`), and are substituted by +/// the likes of `liberate_late_bound_regions`. The distinction exists +/// because higher-ranked lifetimes aren't supported in all places. See [1][2]. +/// +/// Unlike `Param`s, bound regions are not supposed to exist "in the wild" +/// outside their binder, e.g., in types passed to type inference, and +/// should first be substituted (by placeholder regions, free regions, +/// or region variables). +/// +/// ## Placeholder and Free Regions +/// +/// One often wants to work with bound regions without knowing their precise +/// identity. For example, when checking a function, the lifetime of a borrow +/// can end up being assigned to some region parameter. In these cases, +/// it must be ensured that bounds on the region can't be accidentally +/// assumed without being checked. +/// +/// To do this, we replace the bound regions with placeholder markers, +/// which don't satisfy any relation not explicitly provided. +/// +/// There are two kinds of placeholder regions in rustc: `ReFree` and +/// `RePlaceholder`. When checking an item's body, `ReFree` is supposed +/// to be used. These also support explicit bounds: both the internally-stored +/// *scope*, which the region is assumed to outlive, as well as other +/// relations stored in the `FreeRegionMap`. Note that these relations +/// aren't checked when you `make_subregion` (or `eq_types`), only by +/// `resolve_regions_and_report_errors`. +/// +/// When working with higher-ranked types, some region relations aren't +/// yet known, so you can't just call `resolve_regions_and_report_errors`. +/// `RePlaceholder` is designed for this purpose. In these contexts, +/// there's also the risk that some inference variable laying around will +/// get unified with your placeholder region: if you want to check whether +/// `for<'a> Foo<'_>: 'a`, and you substitute your bound region `'a` +/// with a placeholder region `'%a`, the variable `'_` would just be +/// instantiated to the placeholder region `'%a`, which is wrong because +/// the inference variable is supposed to satisfy the relation +/// *for every value of the placeholder region*. To ensure that doesn't +/// happen, you can use `leak_check`. This is more clearly explained +/// by the [rustc dev guide]. +/// +/// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ +/// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ +/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html +pub enum RegionKind { + /// Region bound in a type or fn declaration which will be + /// substituted 'early' -- that is, at the same time when type + /// parameters are substituted. + ReEarlyBound(I::EarlyBoundRegion), + + /// Region bound in a function scope, which will be substituted when the + /// function is called. + ReLateBound(DebruijnIndex, I::BoundRegion), + + /// When checking a function body, the types of all arguments and so forth + /// that refer to bound region parameters are modified to refer to free + /// region parameters. + ReFree(I::FreeRegion), + + /// Static data that has an "infinite" lifetime. Top in the region lattice. + ReStatic, + + /// A region variable. Should not exist outside of type inference. + ReVar(I::InferRegion), + + /// A placeholder region -- basically, the higher-ranked version of `ReFree`. + /// Should not exist outside of type inference. + RePlaceholder(I::PlaceholderRegion), + + /// Erased region, used by trait selection, in MIR and during codegen. + ReErased, + + /// A region that resulted from some other error. Used exclusively for diagnostics. + ReError(I::ErrorGuaranteed), +} + +// This is manually implemented for `RegionKind` because `std::mem::discriminant` +// returns an opaque value that is `PartialEq` but not `PartialOrd` +#[inline] +const fn regionkind_discriminant(value: &RegionKind) -> usize { + match value { + ReEarlyBound(_) => 0, + ReLateBound(_, _) => 1, + ReFree(_) => 2, + ReStatic => 3, + ReVar(_) => 4, + RePlaceholder(_) => 5, + ReErased => 6, + ReError(_) => 7, + } +} + +// This is manually implemented because a derive would require `I: Copy` +impl Copy for RegionKind +where + I::EarlyBoundRegion: Copy, + I::BoundRegion: Copy, + I::FreeRegion: Copy, + I::InferRegion: Copy, + I::PlaceholderRegion: Copy, + I::ErrorGuaranteed: Copy, +{ +} + +// This is manually implemented because a derive would require `I: Clone` +impl Clone for RegionKind { + fn clone(&self) -> Self { + match self { + ReEarlyBound(r) => ReEarlyBound(r.clone()), + ReLateBound(d, r) => ReLateBound(*d, r.clone()), + ReFree(r) => ReFree(r.clone()), + ReStatic => ReStatic, + ReVar(r) => ReVar(r.clone()), + RePlaceholder(r) => RePlaceholder(r.clone()), + ReErased => ReErased, + ReError(r) => ReError(r.clone()), + } + } +} + +// This is manually implemented because a derive would require `I: PartialEq` +impl PartialEq for RegionKind { + #[inline] + fn eq(&self, other: &RegionKind) -> bool { + regionkind_discriminant(self) == regionkind_discriminant(other) + && match (self, other) { + (ReEarlyBound(a_r), ReEarlyBound(b_r)) => a_r == b_r, + (ReLateBound(a_d, a_r), ReLateBound(b_d, b_r)) => a_d == b_d && a_r == b_r, + (ReFree(a_r), ReFree(b_r)) => a_r == b_r, + (ReStatic, ReStatic) => true, + (ReVar(a_r), ReVar(b_r)) => a_r == b_r, + (RePlaceholder(a_r), RePlaceholder(b_r)) => a_r == b_r, + (ReErased, ReErased) => true, + (ReError(_), ReError(_)) => true, + _ => { + debug_assert!( + false, + "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}" + ); + true + } + } + } +} + +// This is manually implemented because a derive would require `I: Eq` +impl Eq for RegionKind {} + +// This is manually implemented because a derive would require `I: PartialOrd` +impl PartialOrd for RegionKind { + #[inline] + fn partial_cmp(&self, other: &RegionKind) -> Option { + Some(self.cmp(other)) + } +} + +// This is manually implemented because a derive would require `I: Ord` +impl Ord for RegionKind { + #[inline] + fn cmp(&self, other: &RegionKind) -> Ordering { + regionkind_discriminant(self).cmp(®ionkind_discriminant(other)).then_with(|| { + match (self, other) { + (ReEarlyBound(a_r), ReEarlyBound(b_r)) => a_r.cmp(b_r), + (ReLateBound(a_d, a_r), ReLateBound(b_d, b_r)) => { + a_d.cmp(b_d).then_with(|| a_r.cmp(b_r)) + } + (ReFree(a_r), ReFree(b_r)) => a_r.cmp(b_r), + (ReStatic, ReStatic) => Ordering::Equal, + (ReVar(a_r), ReVar(b_r)) => a_r.cmp(b_r), + (RePlaceholder(a_r), RePlaceholder(b_r)) => a_r.cmp(b_r), + (ReErased, ReErased) => Ordering::Equal, + _ => { + debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"); + Ordering::Equal + } + } + }) + } +} + +// This is manually implemented because a derive would require `I: Hash` +impl hash::Hash for RegionKind { + fn hash(&self, state: &mut H) -> () { + regionkind_discriminant(self).hash(state); + match self { + ReEarlyBound(r) => r.hash(state), + ReLateBound(d, r) => { + d.hash(state); + r.hash(state) + } + ReFree(r) => r.hash(state), + ReStatic => (), + ReVar(r) => r.hash(state), + RePlaceholder(r) => r.hash(state), + ReErased => (), + ReError(_) => (), + } + } +} + +impl DebugWithInfcx for RegionKind { + fn fmt>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut core::fmt::Formatter<'_>, + ) -> core::fmt::Result { + match this.data { + ReEarlyBound(data) => write!(f, "ReEarlyBound({data:?})"), + + ReLateBound(binder_id, bound_region) => { + write!(f, "ReLateBound({binder_id:?}, {bound_region:?})") + } + + ReFree(fr) => write!(f, "{fr:?}"), + + ReStatic => f.write_str("ReStatic"), + + ReVar(vid) => write!(f, "{:?}", &this.wrap(vid)), + + RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"), + + ReErased => f.write_str("ReErased"), + + ReError(_) => f.write_str("ReError"), + } + } +} +impl fmt::Debug for RegionKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + OptWithInfcx::new_no_ctx(self).fmt(f) + } +} + +// This is manually implemented because a derive would require `I: Encodable` +impl Encodable for RegionKind +where + I::EarlyBoundRegion: Encodable, + I::BoundRegion: Encodable, + I::FreeRegion: Encodable, + I::InferRegion: Encodable, + I::PlaceholderRegion: Encodable, +{ + fn encode(&self, e: &mut E) { + let disc = regionkind_discriminant(self); + match self { + ReEarlyBound(a) => e.emit_enum_variant(disc, |e| { + a.encode(e); + }), + ReLateBound(a, b) => e.emit_enum_variant(disc, |e| { + a.encode(e); + b.encode(e); + }), + ReFree(a) => e.emit_enum_variant(disc, |e| { + a.encode(e); + }), + ReStatic => e.emit_enum_variant(disc, |_| {}), + ReVar(a) => e.emit_enum_variant(disc, |e| { + a.encode(e); + }), + RePlaceholder(a) => e.emit_enum_variant(disc, |e| { + a.encode(e); + }), + ReErased => e.emit_enum_variant(disc, |_| {}), + ReError(_) => e.emit_enum_variant(disc, |_| {}), + } + } +} + +// This is manually implemented because a derive would require `I: Decodable` +impl> Decodable for RegionKind +where + I::EarlyBoundRegion: Decodable, + I::BoundRegion: Decodable, + I::FreeRegion: Decodable, + I::InferRegion: Decodable, + I::PlaceholderRegion: Decodable, + I::ErrorGuaranteed: Decodable, +{ + fn decode(d: &mut D) -> Self { + match Decoder::read_usize(d) { + 0 => ReEarlyBound(Decodable::decode(d)), + 1 => ReLateBound(Decodable::decode(d), Decodable::decode(d)), + 2 => ReFree(Decodable::decode(d)), + 3 => ReStatic, + 4 => ReVar(Decodable::decode(d)), + 5 => RePlaceholder(Decodable::decode(d)), + 6 => ReErased, + 7 => ReError(Decodable::decode(d)), + _ => panic!( + "{}", + format!( + "invalid enum variant tag while decoding `{}`, expected 0..{}", + "RegionKind", 8, + ) + ), + } + } +} + +// This is not a derived impl because a derive would require `I: HashStable` +impl HashStable for RegionKind +where + I::EarlyBoundRegion: HashStable, + I::BoundRegion: HashStable, + I::FreeRegion: HashStable, + I::InferRegion: HashStable, + I::PlaceholderRegion: HashStable, +{ + #[inline] + fn hash_stable( + &self, + hcx: &mut CTX, + hasher: &mut rustc_data_structures::stable_hasher::StableHasher, + ) { + std::mem::discriminant(self).hash_stable(hcx, hasher); + match self { + ReErased | ReStatic | ReError(_) => { + // No variant fields to hash for these ... + } + ReLateBound(d, r) => { + d.hash_stable(hcx, hasher); + r.hash_stable(hcx, hasher); + } + ReEarlyBound(r) => { + r.hash_stable(hcx, hasher); + } + ReFree(r) => { + r.hash_stable(hcx, hasher); + } + RePlaceholder(r) => { + r.hash_stable(hcx, hasher); + } + ReVar(_) => { + panic!("region variables should not be hashed: {self:?}") + } + } + } +} diff --git a/compiler/rustc_type_ir/src/structural_impls.rs b/compiler/rustc_type_ir/src/structural_impls.rs deleted file mode 100644 index 93b3674b51a56..0000000000000 --- a/compiler/rustc_type_ir/src/structural_impls.rs +++ /dev/null @@ -1,390 +0,0 @@ -//! This module contains implementations of the `TypeFoldable` and `TypeVisitable` -//! traits for various types in the Rust compiler. Most are written by hand, though -//! we've recently added some macros and proc-macros to help with the tedium. - -use crate::fold::{FallibleTypeFolder, TypeFoldable}; -use crate::visit::{TypeVisitable, TypeVisitor}; -use crate::{ConstKind, FloatTy, InferTy, IntTy, Interner, UintTy, UniverseIndex}; -use rustc_data_structures::sync::Lrc; -use rustc_index::{Idx, IndexVec}; - -use core::fmt; -use std::marker::PhantomData; -use std::mem; -use std::ops::ControlFlow; - -/////////////////////////////////////////////////////////////////////////// -// Atomic structs -// -// For things that don't carry any arena-allocated data (and are -// copy...), just add them to this list. - -TrivialTypeTraversalImpls! { - (), - bool, - usize, - u16, - u32, - u64, - String, - crate::DebruijnIndex, -} - -/////////////////////////////////////////////////////////////////////////// -// Traversal implementations. - -impl, U: TypeFoldable> TypeFoldable for (T, U) { - fn try_fold_with>(self, folder: &mut F) -> Result<(T, U), F::Error> { - Ok((self.0.try_fold_with(folder)?, self.1.try_fold_with(folder)?)) - } -} - -impl, U: TypeVisitable> TypeVisitable for (T, U) { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.0.visit_with(visitor)?; - self.1.visit_with(visitor) - } -} - -impl, B: TypeFoldable, C: TypeFoldable> TypeFoldable - for (A, B, C) -{ - fn try_fold_with>( - self, - folder: &mut F, - ) -> Result<(A, B, C), F::Error> { - Ok(( - self.0.try_fold_with(folder)?, - self.1.try_fold_with(folder)?, - self.2.try_fold_with(folder)?, - )) - } -} - -impl, B: TypeVisitable, C: TypeVisitable> TypeVisitable - for (A, B, C) -{ - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.0.visit_with(visitor)?; - self.1.visit_with(visitor)?; - self.2.visit_with(visitor) - } -} - -impl> TypeFoldable for Option { - fn try_fold_with>(self, folder: &mut F) -> Result { - Ok(match self { - Some(v) => Some(v.try_fold_with(folder)?), - None => None, - }) - } -} - -impl> TypeVisitable for Option { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - match self { - Some(v) => v.visit_with(visitor), - None => ControlFlow::Continue(()), - } - } -} - -impl, E: TypeFoldable> TypeFoldable for Result { - fn try_fold_with>(self, folder: &mut F) -> Result { - Ok(match self { - Ok(v) => Ok(v.try_fold_with(folder)?), - Err(e) => Err(e.try_fold_with(folder)?), - }) - } -} - -impl, E: TypeVisitable> TypeVisitable for Result { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - match self { - Ok(v) => v.visit_with(visitor), - Err(e) => e.visit_with(visitor), - } - } -} - -impl> TypeFoldable for Lrc { - fn try_fold_with>(mut self, folder: &mut F) -> Result { - // We merely want to replace the contained `T`, if at all possible, - // so that we don't needlessly allocate a new `Lrc` or indeed clone - // the contained type. - unsafe { - // First step is to ensure that we have a unique reference to - // the contained type, which `Lrc::make_mut` will accomplish (by - // allocating a new `Lrc` and cloning the `T` only if required). - // This is done *before* casting to `Lrc>` so that - // panicking during `make_mut` does not leak the `T`. - Lrc::make_mut(&mut self); - - // Casting to `Lrc>` is safe because `ManuallyDrop` - // is `repr(transparent)`. - let ptr = Lrc::into_raw(self).cast::>(); - let mut unique = Lrc::from_raw(ptr); - - // Call to `Lrc::make_mut` above guarantees that `unique` is the - // sole reference to the contained value, so we can avoid doing - // a checked `get_mut` here. - let slot = Lrc::get_mut_unchecked(&mut unique); - - // Semantically move the contained type out from `unique`, fold - // it, then move the folded value back into `unique`. Should - // folding fail, `ManuallyDrop` ensures that the "moved-out" - // value is not re-dropped. - let owned = mem::ManuallyDrop::take(slot); - let folded = owned.try_fold_with(folder)?; - *slot = mem::ManuallyDrop::new(folded); - - // Cast back to `Lrc`. - Ok(Lrc::from_raw(Lrc::into_raw(unique).cast())) - } - } -} - -impl> TypeVisitable for Lrc { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - (**self).visit_with(visitor) - } -} - -impl> TypeFoldable for Box { - fn try_fold_with>(mut self, folder: &mut F) -> Result { - *self = (*self).try_fold_with(folder)?; - Ok(self) - } -} - -impl> TypeVisitable for Box { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - (**self).visit_with(visitor) - } -} - -impl> TypeFoldable for Vec { - fn try_fold_with>(self, folder: &mut F) -> Result { - self.into_iter().map(|t| t.try_fold_with(folder)).collect() - } -} - -impl> TypeVisitable for Vec { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.iter().try_for_each(|t| t.visit_with(visitor)) - } -} - -// `TypeFoldable` isn't impl'd for `&[T]`. It doesn't make sense in the general -// case, because we can't return a new slice. But note that there are a couple -// of trivial impls of `TypeFoldable` for specific slice types elsewhere. - -impl> TypeVisitable for &[T] { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.iter().try_for_each(|t| t.visit_with(visitor)) - } -} - -impl> TypeVisitable for Box<[T]> { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.iter().try_for_each(|t| t.visit_with(visitor)) - } -} - -impl, Ix: Idx> TypeFoldable for IndexVec { - fn try_fold_with>(self, folder: &mut F) -> Result { - self.raw.try_fold_with(folder).map(IndexVec::from_raw) - } -} - -impl, Ix: Idx> TypeVisitable for IndexVec { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.iter().try_for_each(|t| t.visit_with(visitor)) - } -} - -/////////////////////////////////////////////////// -// Debug impls - -pub trait InferCtxtLike { - fn universe_of_ty(&self, ty: I::InferTy) -> Option; - fn universe_of_lt(&self, lt: I::InferRegion) -> Option; - fn universe_of_ct(&self, ct: I::InferConst) -> Option; -} - -impl InferCtxtLike for core::convert::Infallible { - fn universe_of_ty(&self, _ty: ::InferTy) -> Option { - match *self {} - } - fn universe_of_ct(&self, _ct: ::InferConst) -> Option { - match *self {} - } - fn universe_of_lt(&self, _lt: ::InferRegion) -> Option { - match *self {} - } -} - -pub trait DebugWithInfcx: fmt::Debug { - fn fmt>( - this: OptWithInfcx<'_, I, InfCtx, &Self>, - f: &mut fmt::Formatter<'_>, - ) -> fmt::Result; -} - -impl + ?Sized> DebugWithInfcx for &'_ T { - fn fmt>( - this: OptWithInfcx<'_, I, InfCtx, &Self>, - f: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - >::fmt(this.map(|&data| data), f) - } -} -impl> DebugWithInfcx for [T] { - fn fmt>( - this: OptWithInfcx<'_, I, InfCtx, &Self>, - f: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - match f.alternate() { - true => { - write!(f, "[\n")?; - for element in this.data.iter() { - write!(f, "{:?},\n", &this.wrap(element))?; - } - write!(f, "]") - } - false => { - write!(f, "[")?; - if this.data.len() > 0 { - for element in &this.data[..(this.data.len() - 1)] { - write!(f, "{:?}, ", &this.wrap(element))?; - } - if let Some(element) = this.data.last() { - write!(f, "{:?}", &this.wrap(element))?; - } - } - write!(f, "]") - } - } - } -} - -pub struct OptWithInfcx<'a, I: Interner, InfCtx: InferCtxtLike, T> { - pub data: T, - pub infcx: Option<&'a InfCtx>, - _interner: PhantomData, -} - -impl, T: Copy> Copy for OptWithInfcx<'_, I, InfCtx, T> {} -impl, T: Clone> Clone for OptWithInfcx<'_, I, InfCtx, T> { - fn clone(&self) -> Self { - Self { data: self.data.clone(), infcx: self.infcx, _interner: self._interner } - } -} - -impl<'a, I: Interner, T> OptWithInfcx<'a, I, core::convert::Infallible, T> { - pub fn new_no_ctx(data: T) -> Self { - Self { data, infcx: None, _interner: PhantomData } - } -} - -impl<'a, I: Interner, InfCtx: InferCtxtLike, T> OptWithInfcx<'a, I, InfCtx, T> { - pub fn new(data: T, infcx: &'a InfCtx) -> Self { - Self { data, infcx: Some(infcx), _interner: PhantomData } - } - - pub fn wrap(self, u: U) -> OptWithInfcx<'a, I, InfCtx, U> { - OptWithInfcx { data: u, infcx: self.infcx, _interner: PhantomData } - } - - pub fn map(self, f: impl FnOnce(T) -> U) -> OptWithInfcx<'a, I, InfCtx, U> { - OptWithInfcx { data: f(self.data), infcx: self.infcx, _interner: PhantomData } - } - - pub fn as_ref(&self) -> OptWithInfcx<'a, I, InfCtx, &T> { - OptWithInfcx { data: &self.data, infcx: self.infcx, _interner: PhantomData } - } -} - -impl, T: DebugWithInfcx> fmt::Debug - for OptWithInfcx<'_, I, InfCtx, T> -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - DebugWithInfcx::fmt(self.as_ref(), f) - } -} - -impl fmt::Debug for IntTy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.name_str()) - } -} - -impl fmt::Debug for UintTy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.name_str()) - } -} - -impl fmt::Debug for FloatTy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.name_str()) - } -} - -impl fmt::Debug for InferTy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use InferTy::*; - match *self { - TyVar(ref v) => v.fmt(f), - IntVar(ref v) => v.fmt(f), - FloatVar(ref v) => v.fmt(f), - FreshTy(v) => write!(f, "FreshTy({v:?})"), - FreshIntTy(v) => write!(f, "FreshIntTy({v:?})"), - FreshFloatTy(v) => write!(f, "FreshFloatTy({v:?})"), - } - } -} -impl> DebugWithInfcx for InferTy { - fn fmt>( - this: OptWithInfcx<'_, I, InfCtx, &Self>, - f: &mut fmt::Formatter<'_>, - ) -> fmt::Result { - use InferTy::*; - match this.infcx.and_then(|infcx| infcx.universe_of_ty(*this.data)) { - None => write!(f, "{:?}", this.data), - Some(universe) => match *this.data { - TyVar(ty_vid) => write!(f, "?{}_{}t", ty_vid.index(), universe.index()), - IntVar(_) | FloatVar(_) | FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_) => { - unreachable!() - } - }, - } - } -} - -impl fmt::Debug for ConstKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - OptWithInfcx::new_no_ctx(self).fmt(f) - } -} -impl DebugWithInfcx for ConstKind { - fn fmt>( - this: OptWithInfcx<'_, I, InfCtx, &Self>, - f: &mut core::fmt::Formatter<'_>, - ) -> core::fmt::Result { - use ConstKind::*; - - match this.data { - Param(param) => write!(f, "{param:?}"), - Infer(var) => write!(f, "{:?}", &this.wrap(var)), - Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var.clone()), - Placeholder(placeholder) => write!(f, "{placeholder:?}"), - Unevaluated(uv) => { - write!(f, "{:?}", &this.wrap(uv)) - } - Value(valtree) => write!(f, "{valtree:?}"), - Error(_) => write!(f, "{{const error}}"), - Expr(expr) => write!(f, "{:?}", &this.wrap(expr)), - } - } -} diff --git a/compiler/rustc_type_ir/src/ty_info.rs b/compiler/rustc_type_ir/src/ty_info.rs index 4e5d424886ad8..d986e310c3297 100644 --- a/compiler/rustc_type_ir/src/ty_info.rs +++ b/compiler/rustc_type_ir/src/ty_info.rs @@ -1,13 +1,8 @@ -use std::{ - cmp::Ordering, - hash::{Hash, Hasher}, - ops::Deref, -}; - -use rustc_data_structures::{ - fingerprint::Fingerprint, - stable_hasher::{HashStable, StableHasher}, -}; +use rustc_data_structures::fingerprint::Fingerprint; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use std::cmp::Ordering; +use std::hash::{Hash, Hasher}; +use std::ops::Deref; use crate::{DebruijnIndex, TypeFlags}; diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/ty_kind.rs similarity index 56% rename from compiler/rustc_type_ir/src/sty.rs rename to compiler/rustc_type_ir/src/ty_kind.rs index 5ca77701eb01a..91bfce9a142f9 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -1,25 +1,22 @@ #![allow(rustc::usage_of_ty_tykind)] +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::unify::{EqUnifyValue, UnifyKey}; +use rustc_serialize::{Decodable, Decoder, Encodable}; use std::cmp::Ordering; +use std::mem::discriminant; use std::{fmt, hash}; -use crate::FloatTy; use crate::HashStableContext; -use crate::IntTy; use crate::Interner; use crate::TyDecoder; use crate::TyEncoder; -use crate::UintTy; use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, OptWithInfcx}; -use self::RegionKind::*; use self::TyKind::*; -use rustc_data_structures::stable_hasher::HashStable; -use rustc_serialize::{Decodable, Decoder, Encodable}; - -/// The movability of a generator / closure literal: -/// whether a generator contains self-references, causing it to be `!Unpin`. +/// The movability of a coroutine / closure literal: +/// whether a coroutine contains self-references, causing it to be `!Unpin`. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, Debug, Copy)] #[derive(HashStable_Generic)] pub enum Movability { @@ -198,30 +195,30 @@ pub enum TyKind { /// `ClosureArgs` for more details. Closure(I::DefId, I::GenericArgs), - /// The anonymous type of a generator. Used to represent the type of + /// The anonymous type of a coroutine. Used to represent the type of /// `|a| yield a`. /// - /// For more info about generator args, visit the documentation for - /// `GeneratorArgs`. - Generator(I::DefId, I::GenericArgs, Movability), + /// For more info about coroutine args, visit the documentation for + /// `CoroutineArgs`. + Coroutine(I::DefId, I::GenericArgs, Movability), - /// A type representing the types stored inside a generator. - /// This should only appear as part of the `GeneratorArgs`. + /// A type representing the types stored inside a coroutine. + /// This should only appear as part of the `CoroutineArgs`. /// /// Unlike upvars, the witness can reference lifetimes from - /// inside of the generator itself. To deal with them in - /// the type of the generator, we convert them to higher ranked + /// inside of the coroutine itself. To deal with them in + /// the type of the coroutine, we convert them to higher ranked /// lifetimes bound by the witness itself. /// /// This variant is only using when `drop_tracking_mir` is set. - /// This contains the `DefId` and the `GenericArgsRef` of the generator. - /// The actual witness types are computed on MIR by the `mir_generator_witnesses` query. + /// This contains the `DefId` and the `GenericArgsRef` of the coroutine. + /// The actual witness types are computed on MIR by the `mir_coroutine_witnesses` query. /// - /// Looking at the following example, the witness for this generator + /// Looking at the following example, the witness for this coroutine /// may end up as something like `for<'a> [Vec, &'a Vec]`: /// /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?) - /// #![feature(generators)] + /// #![feature(coroutines)] /// |a| { /// let x = &vec![3]; /// yield a; @@ -229,7 +226,7 @@ pub enum TyKind { /// } /// # ; /// ``` - GeneratorWitness(I::DefId, I::GenericArgs), + CoroutineWitness(I::DefId, I::GenericArgs), /// The never type `!`. Never, @@ -314,8 +311,8 @@ const fn tykind_discriminant(value: &TyKind) -> usize { FnPtr(_) => 13, Dynamic(..) => 14, Closure(_, _) => 15, - Generator(_, _, _) => 16, - GeneratorWitness(_, _) => 17, + Coroutine(_, _, _) => 16, + CoroutineWitness(_, _) => 17, Never => 18, Tuple(_) => 19, Alias(_, _) => 20, @@ -347,8 +344,8 @@ impl Clone for TyKind { FnPtr(s) => FnPtr(s.clone()), Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), *repr), Closure(d, s) => Closure(d.clone(), s.clone()), - Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()), - GeneratorWitness(d, s) => GeneratorWitness(d.clone(), s.clone()), + Coroutine(d, s, m) => Coroutine(d.clone(), s.clone(), m.clone()), + CoroutineWitness(d, s) => CoroutineWitness(d.clone(), s.clone()), Never => Never, Tuple(t) => Tuple(t.clone()), Alias(k, p) => Alias(*k, p.clone()), @@ -387,10 +384,10 @@ impl PartialEq for TyKind { a_p == b_p && a_r == b_r && a_repr == b_repr } (Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s, - (Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => { + (Coroutine(a_d, a_s, a_m), Coroutine(b_d, b_s, b_m)) => { a_d == b_d && a_s == b_s && a_m == b_m } - (GeneratorWitness(a_d, a_s), GeneratorWitness(b_d, b_s)) => a_d == b_d && a_s == b_s, + (CoroutineWitness(a_d, a_s), CoroutineWitness(b_d, b_s)) => a_d == b_d && a_s == b_s, (Tuple(a_t), Tuple(b_t)) => a_t == b_t, (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p, (Param(a_p), Param(b_p)) => a_p == b_p, @@ -444,12 +441,12 @@ impl Ord for TyKind { a_p.cmp(b_p).then_with(|| a_r.cmp(b_r).then_with(|| a_repr.cmp(b_repr))) } (Closure(a_p, a_s), Closure(b_p, b_s)) => a_p.cmp(b_p).then_with(|| a_s.cmp(b_s)), - (Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => { + (Coroutine(a_d, a_s, a_m), Coroutine(b_d, b_s, b_m)) => { a_d.cmp(b_d).then_with(|| a_s.cmp(b_s).then_with(|| a_m.cmp(b_m))) } ( - GeneratorWitness(a_d, a_s), - GeneratorWitness(b_d, b_s), + CoroutineWitness(a_d, a_s), + CoroutineWitness(b_d, b_s), ) => match Ord::cmp(a_d, b_d) { Ordering::Equal => Ord::cmp(a_s, b_s), cmp => cmp, @@ -509,12 +506,12 @@ impl hash::Hash for TyKind { d.hash(state); s.hash(state) } - Generator(d, s, m) => { + Coroutine(d, s, m) => { d.hash(state); s.hash(state); m.hash(state) } - GeneratorWitness(d, s) => { + CoroutineWitness(d, s) => { d.hash(state); s.hash(state); } @@ -587,9 +584,9 @@ impl DebugWithInfcx for TyKind { } }, Closure(d, s) => f.debug_tuple_field2_finish("Closure", d, &this.wrap(s)), - Generator(d, s, m) => f.debug_tuple_field3_finish("Generator", d, &this.wrap(s), m), - GeneratorWitness(d, s) => { - f.debug_tuple_field2_finish("GeneratorWitness", d, &this.wrap(s)) + Coroutine(d, s, m) => f.debug_tuple_field3_finish("Coroutine", d, &this.wrap(s), m), + CoroutineWitness(d, s) => { + f.debug_tuple_field2_finish("CoroutineWitness", d, &this.wrap(s)) } Never => write!(f, "!"), Tuple(t) => { @@ -699,12 +696,12 @@ where def_id.encode(e); args.encode(e); }), - Generator(def_id, args, m) => e.emit_enum_variant(disc, |e| { + Coroutine(def_id, args, m) => e.emit_enum_variant(disc, |e| { def_id.encode(e); args.encode(e); m.encode(e); }), - GeneratorWitness(def_id, args) => e.emit_enum_variant(disc, |e| { + CoroutineWitness(def_id, args) => e.emit_enum_variant(disc, |e| { def_id.encode(e); args.encode(e); }), @@ -777,8 +774,8 @@ where 13 => FnPtr(Decodable::decode(d)), 14 => Dynamic(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), 15 => Closure(Decodable::decode(d), Decodable::decode(d)), - 16 => Generator(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), - 17 => GeneratorWitness(Decodable::decode(d), Decodable::decode(d)), + 16 => Coroutine(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), + 17 => CoroutineWitness(Decodable::decode(d), Decodable::decode(d)), 18 => Never, 19 => Tuple(Decodable::decode(d)), 20 => Alias(Decodable::decode(d), Decodable::decode(d)), @@ -877,12 +874,12 @@ where def_id.hash_stable(__hcx, __hasher); args.hash_stable(__hcx, __hasher); } - Generator(def_id, args, m) => { + Coroutine(def_id, args, m) => { def_id.hash_stable(__hcx, __hasher); args.hash_stable(__hcx, __hasher); m.hash_stable(__hcx, __hasher); } - GeneratorWitness(def_id, args) => { + CoroutineWitness(def_id, args) => { def_id.hash_stable(__hcx, __hasher); args.hash_stable(__hcx, __hasher); } @@ -914,620 +911,347 @@ where } } -/// Represents a constant in Rust. -// #[derive(derive_more::From)] -pub enum ConstKind { - /// A const generic parameter. - Param(I::ParamConst), - - /// Infer the value of the const. - Infer(I::InferConst), - - /// Bound const variable, used only when preparing a trait query. - Bound(DebruijnIndex, I::BoundConst), - - /// A placeholder const - universally quantified higher-ranked const. - Placeholder(I::PlaceholderConst), - - /// An unnormalized const item such as an anon const or assoc const or free const item. - /// Right now anything other than anon consts does not actually work properly but this - /// should - Unevaluated(I::AliasConst), - - /// Used to hold computed value. - Value(I::ValueConst), - - /// A placeholder for a const which could not be computed; this is - /// propagated to avoid useless error messages. - Error(I::ErrorGuaranteed), - - /// Unevaluated non-const-item, used by `feature(generic_const_exprs)` to represent - /// const arguments such as `N + 1` or `foo(N)` - Expr(I::ExprConst), +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Encodable, Decodable, HashStable_Generic)] +pub enum IntTy { + Isize, + I8, + I16, + I32, + I64, + I128, } -const fn const_kind_discriminant(value: &ConstKind) -> usize { - match value { - ConstKind::Param(_) => 0, - ConstKind::Infer(_) => 1, - ConstKind::Bound(_, _) => 2, - ConstKind::Placeholder(_) => 3, - ConstKind::Unevaluated(_) => 4, - ConstKind::Value(_) => 5, - ConstKind::Error(_) => 6, - ConstKind::Expr(_) => 7, +impl IntTy { + pub fn name_str(&self) -> &'static str { + match *self { + IntTy::Isize => "isize", + IntTy::I8 => "i8", + IntTy::I16 => "i16", + IntTy::I32 => "i32", + IntTy::I64 => "i64", + IntTy::I128 => "i128", + } } -} -impl hash::Hash for ConstKind { - fn hash(&self, state: &mut H) { - const_kind_discriminant(self).hash(state); + pub fn bit_width(&self) -> Option { + Some(match *self { + IntTy::Isize => return None, + IntTy::I8 => 8, + IntTy::I16 => 16, + IntTy::I32 => 32, + IntTy::I64 => 64, + IntTy::I128 => 128, + }) + } + + pub fn normalize(&self, target_width: u32) -> Self { match self { - ConstKind::Param(p) => p.hash(state), - ConstKind::Infer(i) => i.hash(state), - ConstKind::Bound(d, b) => { - d.hash(state); - b.hash(state); - } - ConstKind::Placeholder(p) => p.hash(state), - ConstKind::Unevaluated(u) => u.hash(state), - ConstKind::Value(v) => v.hash(state), - ConstKind::Error(e) => e.hash(state), - ConstKind::Expr(e) => e.hash(state), + IntTy::Isize => match target_width { + 16 => IntTy::I16, + 32 => IntTy::I32, + 64 => IntTy::I64, + _ => unreachable!(), + }, + _ => *self, } } -} -impl HashStable for ConstKind -where - I::ParamConst: HashStable, - I::InferConst: HashStable, - I::BoundConst: HashStable, - I::PlaceholderConst: HashStable, - I::AliasConst: HashStable, - I::ValueConst: HashStable, - I::ErrorGuaranteed: HashStable, - I::ExprConst: HashStable, -{ - fn hash_stable( - &self, - hcx: &mut CTX, - hasher: &mut rustc_data_structures::stable_hasher::StableHasher, - ) { - const_kind_discriminant(self).hash_stable(hcx, hasher); + pub fn to_unsigned(self) -> UintTy { match self { - ConstKind::Param(p) => p.hash_stable(hcx, hasher), - ConstKind::Infer(i) => i.hash_stable(hcx, hasher), - ConstKind::Bound(d, b) => { - d.hash_stable(hcx, hasher); - b.hash_stable(hcx, hasher); - } - ConstKind::Placeholder(p) => p.hash_stable(hcx, hasher), - ConstKind::Unevaluated(u) => u.hash_stable(hcx, hasher), - ConstKind::Value(v) => v.hash_stable(hcx, hasher), - ConstKind::Error(e) => e.hash_stable(hcx, hasher), - ConstKind::Expr(e) => e.hash_stable(hcx, hasher), + IntTy::Isize => UintTy::Usize, + IntTy::I8 => UintTy::U8, + IntTy::I16 => UintTy::U16, + IntTy::I32 => UintTy::U32, + IntTy::I64 => UintTy::U64, + IntTy::I128 => UintTy::U128, } } } -impl> Decodable for ConstKind -where - I::ParamConst: Decodable, - I::InferConst: Decodable, - I::BoundConst: Decodable, - I::PlaceholderConst: Decodable, - I::AliasConst: Decodable, - I::ValueConst: Decodable, - I::ErrorGuaranteed: Decodable, - I::ExprConst: Decodable, -{ - fn decode(d: &mut D) -> Self { - match Decoder::read_usize(d) { - 0 => ConstKind::Param(Decodable::decode(d)), - 1 => ConstKind::Infer(Decodable::decode(d)), - 2 => ConstKind::Bound(Decodable::decode(d), Decodable::decode(d)), - 3 => ConstKind::Placeholder(Decodable::decode(d)), - 4 => ConstKind::Unevaluated(Decodable::decode(d)), - 5 => ConstKind::Value(Decodable::decode(d)), - 6 => ConstKind::Error(Decodable::decode(d)), - 7 => ConstKind::Expr(Decodable::decode(d)), - _ => panic!( - "{}", - format!( - "invalid enum variant tag while decoding `{}`, expected 0..{}", - "ConstKind", 8, - ) - ), +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] +#[derive(Encodable, Decodable, HashStable_Generic)] +pub enum UintTy { + Usize, + U8, + U16, + U32, + U64, + U128, +} + +impl UintTy { + pub fn name_str(&self) -> &'static str { + match *self { + UintTy::Usize => "usize", + UintTy::U8 => "u8", + UintTy::U16 => "u16", + UintTy::U32 => "u32", + UintTy::U64 => "u64", + UintTy::U128 => "u128", } } -} -impl> Encodable for ConstKind -where - I::ParamConst: Encodable, - I::InferConst: Encodable, - I::BoundConst: Encodable, - I::PlaceholderConst: Encodable, - I::AliasConst: Encodable, - I::ValueConst: Encodable, - I::ErrorGuaranteed: Encodable, - I::ExprConst: Encodable, -{ - fn encode(&self, e: &mut E) { - let disc = const_kind_discriminant(self); + pub fn bit_width(&self) -> Option { + Some(match *self { + UintTy::Usize => return None, + UintTy::U8 => 8, + UintTy::U16 => 16, + UintTy::U32 => 32, + UintTy::U64 => 64, + UintTy::U128 => 128, + }) + } + + pub fn normalize(&self, target_width: u32) -> Self { match self { - ConstKind::Param(p) => e.emit_enum_variant(disc, |e| p.encode(e)), - ConstKind::Infer(i) => e.emit_enum_variant(disc, |e| i.encode(e)), - ConstKind::Bound(d, b) => e.emit_enum_variant(disc, |e| { - d.encode(e); - b.encode(e); - }), - ConstKind::Placeholder(p) => e.emit_enum_variant(disc, |e| p.encode(e)), - ConstKind::Unevaluated(u) => e.emit_enum_variant(disc, |e| u.encode(e)), - ConstKind::Value(v) => e.emit_enum_variant(disc, |e| v.encode(e)), - ConstKind::Error(er) => e.emit_enum_variant(disc, |e| er.encode(e)), - ConstKind::Expr(ex) => e.emit_enum_variant(disc, |e| ex.encode(e)), + UintTy::Usize => match target_width { + 16 => UintTy::U16, + 32 => UintTy::U32, + 64 => UintTy::U64, + _ => unreachable!(), + }, + _ => *self, } } -} -impl PartialOrd for ConstKind { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) + pub fn to_signed(self) -> IntTy { + match self { + UintTy::Usize => IntTy::Isize, + UintTy::U8 => IntTy::I8, + UintTy::U16 => IntTy::I16, + UintTy::U32 => IntTy::I32, + UintTy::U64 => IntTy::I64, + UintTy::U128 => IntTy::I128, + } } } -impl Ord for ConstKind { - fn cmp(&self, other: &Self) -> Ordering { - const_kind_discriminant(self) - .cmp(&const_kind_discriminant(other)) - .then_with(|| match (self, other) { - (ConstKind::Param(p1), ConstKind::Param(p2)) => p1.cmp(p2), - (ConstKind::Infer(i1), ConstKind::Infer(i2)) => i1.cmp(i2), - (ConstKind::Bound(d1, b1), ConstKind::Bound(d2, b2)) => d1.cmp(d2).then_with(|| b1.cmp(b2)), - (ConstKind::Placeholder(p1), ConstKind::Placeholder(p2)) => p1.cmp(p2), - (ConstKind::Unevaluated(u1), ConstKind::Unevaluated(u2)) => u1.cmp(u2), - (ConstKind::Value(v1), ConstKind::Value(v2)) => v1.cmp(v2), - (ConstKind::Error(e1), ConstKind::Error(e2)) => e1.cmp(e2), - (ConstKind::Expr(e1), ConstKind::Expr(e2)) => e1.cmp(e2), - _ => { - debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}"); - Ordering::Equal - } - }) - } +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Encodable, Decodable, HashStable_Generic)] +pub enum FloatTy { + F32, + F64, } -impl PartialEq for ConstKind { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Param(l0), Self::Param(r0)) => l0 == r0, - (Self::Infer(l0), Self::Infer(r0)) => l0 == r0, - (Self::Bound(l0, l1), Self::Bound(r0, r1)) => l0 == r0 && l1 == r1, - (Self::Placeholder(l0), Self::Placeholder(r0)) => l0 == r0, - (Self::Unevaluated(l0), Self::Unevaluated(r0)) => l0 == r0, - (Self::Value(l0), Self::Value(r0)) => l0 == r0, - (Self::Error(l0), Self::Error(r0)) => l0 == r0, - (Self::Expr(l0), Self::Expr(r0)) => l0 == r0, - _ => false, +impl FloatTy { + pub fn name_str(self) -> &'static str { + match self { + FloatTy::F32 => "f32", + FloatTy::F64 => "f64", } } -} - -impl Eq for ConstKind {} -impl Clone for ConstKind { - fn clone(&self) -> Self { + pub fn bit_width(self) -> u64 { match self { - Self::Param(arg0) => Self::Param(arg0.clone()), - Self::Infer(arg0) => Self::Infer(arg0.clone()), - Self::Bound(arg0, arg1) => Self::Bound(arg0.clone(), arg1.clone()), - Self::Placeholder(arg0) => Self::Placeholder(arg0.clone()), - Self::Unevaluated(arg0) => Self::Unevaluated(arg0.clone()), - Self::Value(arg0) => Self::Value(arg0.clone()), - Self::Error(arg0) => Self::Error(arg0.clone()), - Self::Expr(arg0) => Self::Expr(arg0.clone()), + FloatTy::F32 => 32, + FloatTy::F64 => 64, } } } -/// Representation of regions. Note that the NLL checker uses a distinct -/// representation of regions. For this reason, it internally replaces all the -/// regions with inference variables -- the index of the variable is then used -/// to index into internal NLL data structures. See `rustc_const_eval::borrow_check` -/// module for more information. -/// -/// Note: operations are on the wrapper `Region` type, which is interned, -/// rather than this type. -/// -/// ## The Region lattice within a given function -/// -/// In general, the region lattice looks like -/// -/// ```text -/// static ----------+-----...------+ (greatest) -/// | | | -/// early-bound and | | -/// free regions | | -/// | | | -/// | | | -/// empty(root) placeholder(U1) | -/// | / | -/// | / placeholder(Un) -/// empty(U1) -- / -/// | / -/// ... / -/// | / -/// empty(Un) -------- (smallest) -/// ``` -/// -/// Early-bound/free regions are the named lifetimes in scope from the -/// function declaration. They have relationships to one another -/// determined based on the declared relationships from the -/// function. -/// -/// Note that inference variables and bound regions are not included -/// in this diagram. In the case of inference variables, they should -/// be inferred to some other region from the diagram. In the case of -/// bound regions, they are excluded because they don't make sense to -/// include -- the diagram indicates the relationship between free -/// regions. -/// -/// ## Inference variables -/// -/// During region inference, we sometimes create inference variables, -/// represented as `ReVar`. These will be inferred by the code in -/// `infer::lexical_region_resolve` to some free region from the -/// lattice above (the minimal region that meets the -/// constraints). -/// -/// During NLL checking, where regions are defined differently, we -/// also use `ReVar` -- in that case, the index is used to index into -/// the NLL region checker's data structures. The variable may in fact -/// represent either a free region or an inference variable, in that -/// case. -/// -/// ## Bound Regions -/// -/// These are regions that are stored behind a binder and must be substituted -/// with some concrete region before being used. There are two kind of -/// bound regions: early-bound, which are bound in an item's `Generics`, -/// and are substituted by an `GenericArgs`, and late-bound, which are part of -/// higher-ranked types (e.g., `for<'a> fn(&'a ())`), and are substituted by -/// the likes of `liberate_late_bound_regions`. The distinction exists -/// because higher-ranked lifetimes aren't supported in all places. See [1][2]. -/// -/// Unlike `Param`s, bound regions are not supposed to exist "in the wild" -/// outside their binder, e.g., in types passed to type inference, and -/// should first be substituted (by placeholder regions, free regions, -/// or region variables). -/// -/// ## Placeholder and Free Regions -/// -/// One often wants to work with bound regions without knowing their precise -/// identity. For example, when checking a function, the lifetime of a borrow -/// can end up being assigned to some region parameter. In these cases, -/// it must be ensured that bounds on the region can't be accidentally -/// assumed without being checked. -/// -/// To do this, we replace the bound regions with placeholder markers, -/// which don't satisfy any relation not explicitly provided. -/// -/// There are two kinds of placeholder regions in rustc: `ReFree` and -/// `RePlaceholder`. When checking an item's body, `ReFree` is supposed -/// to be used. These also support explicit bounds: both the internally-stored -/// *scope*, which the region is assumed to outlive, as well as other -/// relations stored in the `FreeRegionMap`. Note that these relations -/// aren't checked when you `make_subregion` (or `eq_types`), only by -/// `resolve_regions_and_report_errors`. -/// -/// When working with higher-ranked types, some region relations aren't -/// yet known, so you can't just call `resolve_regions_and_report_errors`. -/// `RePlaceholder` is designed for this purpose. In these contexts, -/// there's also the risk that some inference variable laying around will -/// get unified with your placeholder region: if you want to check whether -/// `for<'a> Foo<'_>: 'a`, and you substitute your bound region `'a` -/// with a placeholder region `'%a`, the variable `'_` would just be -/// instantiated to the placeholder region `'%a`, which is wrong because -/// the inference variable is supposed to satisfy the relation -/// *for every value of the placeholder region*. To ensure that doesn't -/// happen, you can use `leak_check`. This is more clearly explained -/// by the [rustc dev guide]. -/// -/// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ -/// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ -/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html -pub enum RegionKind { - /// Region bound in a type or fn declaration which will be - /// substituted 'early' -- that is, at the same time when type - /// parameters are substituted. - ReEarlyBound(I::EarlyBoundRegion), - - /// Region bound in a function scope, which will be substituted when the - /// function is called. - ReLateBound(DebruijnIndex, I::BoundRegion), - - /// When checking a function body, the types of all arguments and so forth - /// that refer to bound region parameters are modified to refer to free - /// region parameters. - ReFree(I::FreeRegion), - - /// Static data that has an "infinite" lifetime. Top in the region lattice. - ReStatic, - - /// A region variable. Should not exist outside of type inference. - ReVar(I::InferRegion), - - /// A placeholder region -- basically, the higher-ranked version of `ReFree`. - /// Should not exist outside of type inference. - RePlaceholder(I::PlaceholderRegion), - - /// Erased region, used by trait selection, in MIR and during codegen. - ReErased, - - /// A region that resulted from some other error. Used exclusively for diagnostics. - ReError(I::ErrorGuaranteed), +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum IntVarValue { + IntType(IntTy), + UintType(UintTy), } -// This is manually implemented for `RegionKind` because `std::mem::discriminant` -// returns an opaque value that is `PartialEq` but not `PartialOrd` -#[inline] -const fn regionkind_discriminant(value: &RegionKind) -> usize { - match value { - ReEarlyBound(_) => 0, - ReLateBound(_, _) => 1, - ReFree(_) => 2, - ReStatic => 3, - ReVar(_) => 4, - RePlaceholder(_) => 5, - ReErased => 6, - ReError(_) => 7, - } +#[derive(Clone, Copy, PartialEq, Eq)] +pub struct FloatVarValue(pub FloatTy); + +rustc_index::newtype_index! { + /// A **ty**pe **v**ariable **ID**. + #[debug_format = "?{}t"] + pub struct TyVid {} } -// This is manually implemented because a derive would require `I: Copy` -impl Copy for RegionKind -where - I::EarlyBoundRegion: Copy, - I::BoundRegion: Copy, - I::FreeRegion: Copy, - I::InferRegion: Copy, - I::PlaceholderRegion: Copy, - I::ErrorGuaranteed: Copy, -{ +rustc_index::newtype_index! { + /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. + #[debug_format = "?{}i"] + pub struct IntVid {} } -// This is manually implemented because a derive would require `I: Clone` -impl Clone for RegionKind { - fn clone(&self) -> Self { - match self { - ReEarlyBound(r) => ReEarlyBound(r.clone()), - ReLateBound(d, r) => ReLateBound(*d, r.clone()), - ReFree(r) => ReFree(r.clone()), - ReStatic => ReStatic, - ReVar(r) => ReVar(r.clone()), - RePlaceholder(r) => RePlaceholder(r.clone()), - ReErased => ReErased, - ReError(r) => ReError(r.clone()), - } - } +rustc_index::newtype_index! { + /// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**. + #[debug_format = "?{}f"] + pub struct FloatVid {} } -// This is manually implemented because a derive would require `I: PartialEq` -impl PartialEq for RegionKind { +/// A placeholder for a type that hasn't been inferred yet. +/// +/// E.g., if we have an empty array (`[]`), then we create a fresh +/// type variable for the element type since we won't know until it's +/// used what the element type is supposed to be. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] +pub enum InferTy { + /// A type variable. + TyVar(TyVid), + /// An integral type variable (`{integer}`). + /// + /// These are created when the compiler sees an integer literal like + /// `1` that could be several different types (`u8`, `i32`, `u32`, etc.). + /// We don't know until it's used what type it's supposed to be, so + /// we create a fresh type variable. + IntVar(IntVid), + /// A floating-point type variable (`{float}`). + /// + /// These are created when the compiler sees an float literal like + /// `1.0` that could be either an `f32` or an `f64`. + /// We don't know until it's used what type it's supposed to be, so + /// we create a fresh type variable. + FloatVar(FloatVid), + + /// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement + /// for an unbound type variable. This is convenient for caching etc. See + /// `rustc_infer::infer::freshen` for more details. + /// + /// Compare with [`TyVar`][Self::TyVar]. + FreshTy(u32), + /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar]. + FreshIntTy(u32), + /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar]. + FreshFloatTy(u32), +} + +/// Raw `TyVid` are used as the unification key for `sub_relations`; +/// they carry no values. +impl UnifyKey for TyVid { + type Value = (); #[inline] - fn eq(&self, other: &RegionKind) -> bool { - regionkind_discriminant(self) == regionkind_discriminant(other) - && match (self, other) { - (ReEarlyBound(a_r), ReEarlyBound(b_r)) => a_r == b_r, - (ReLateBound(a_d, a_r), ReLateBound(b_d, b_r)) => a_d == b_d && a_r == b_r, - (ReFree(a_r), ReFree(b_r)) => a_r == b_r, - (ReStatic, ReStatic) => true, - (ReVar(a_r), ReVar(b_r)) => a_r == b_r, - (RePlaceholder(a_r), RePlaceholder(b_r)) => a_r == b_r, - (ReErased, ReErased) => true, - (ReError(_), ReError(_)) => true, - _ => { - debug_assert!( - false, - "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}" - ); - true - } - } + fn index(&self) -> u32 { + self.as_u32() + } + #[inline] + fn from_index(i: u32) -> TyVid { + TyVid::from_u32(i) + } + fn tag() -> &'static str { + "TyVid" } } -// This is manually implemented because a derive would require `I: Eq` -impl Eq for RegionKind {} +impl EqUnifyValue for IntVarValue {} -// This is manually implemented because a derive would require `I: PartialOrd` -impl PartialOrd for RegionKind { +impl UnifyKey for IntVid { + type Value = Option; + #[inline] // make this function eligible for inlining - it is quite hot. + fn index(&self) -> u32 { + self.as_u32() + } #[inline] - fn partial_cmp(&self, other: &RegionKind) -> Option { - Some(self.cmp(other)) + fn from_index(i: u32) -> IntVid { + IntVid::from_u32(i) + } + fn tag() -> &'static str { + "IntVid" } } -// This is manually implemented because a derive would require `I: Ord` -impl Ord for RegionKind { +impl EqUnifyValue for FloatVarValue {} + +impl UnifyKey for FloatVid { + type Value = Option; #[inline] - fn cmp(&self, other: &RegionKind) -> Ordering { - regionkind_discriminant(self).cmp(®ionkind_discriminant(other)).then_with(|| { - match (self, other) { - (ReEarlyBound(a_r), ReEarlyBound(b_r)) => a_r.cmp(b_r), - (ReLateBound(a_d, a_r), ReLateBound(b_d, b_r)) => { - a_d.cmp(b_d).then_with(|| a_r.cmp(b_r)) - } - (ReFree(a_r), ReFree(b_r)) => a_r.cmp(b_r), - (ReStatic, ReStatic) => Ordering::Equal, - (ReVar(a_r), ReVar(b_r)) => a_r.cmp(b_r), - (RePlaceholder(a_r), RePlaceholder(b_r)) => a_r.cmp(b_r), - (ReErased, ReErased) => Ordering::Equal, - _ => { - debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"); - Ordering::Equal - } - } - }) + fn index(&self) -> u32 { + self.as_u32() + } + #[inline] + fn from_index(i: u32) -> FloatVid { + FloatVid::from_u32(i) + } + fn tag() -> &'static str { + "FloatVid" } } -// This is manually implemented because a derive would require `I: Hash` -impl hash::Hash for RegionKind { - fn hash(&self, state: &mut H) -> () { - regionkind_discriminant(self).hash(state); +impl HashStable for InferTy { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + use InferTy::*; + discriminant(self).hash_stable(ctx, hasher); match self { - ReEarlyBound(r) => r.hash(state), - ReLateBound(d, r) => { - d.hash(state); - r.hash(state) + TyVar(_) | IntVar(_) | FloatVar(_) => { + panic!("type variables should not be hashed: {self:?}") } - ReFree(r) => r.hash(state), - ReStatic => (), - ReVar(r) => r.hash(state), - RePlaceholder(r) => r.hash(state), - ReErased => (), - ReError(_) => (), + FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher), } } } -impl DebugWithInfcx for RegionKind { - fn fmt>( - this: OptWithInfcx<'_, I, InfCtx, &Self>, - f: &mut core::fmt::Formatter<'_>, - ) -> core::fmt::Result { - match this.data { - ReEarlyBound(data) => write!(f, "ReEarlyBound({data:?})"), - - ReLateBound(binder_id, bound_region) => { - write!(f, "ReLateBound({binder_id:?}, {bound_region:?})") - } - - ReFree(fr) => write!(f, "{fr:?}"), - - ReStatic => f.write_str("ReStatic"), - - ReVar(vid) => write!(f, "{:?}", &this.wrap(vid)), - - RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"), +impl fmt::Debug for IntVarValue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + IntVarValue::IntType(ref v) => v.fmt(f), + IntVarValue::UintType(ref v) => v.fmt(f), + } + } +} - ReErased => f.write_str("ReErased"), +impl fmt::Debug for FloatVarValue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} - ReError(_) => f.write_str("ReError"), +impl fmt::Display for InferTy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use InferTy::*; + match *self { + TyVar(_) => write!(f, "_"), + IntVar(_) => write!(f, "{}", "{integer}"), + FloatVar(_) => write!(f, "{}", "{float}"), + FreshTy(v) => write!(f, "FreshTy({v})"), + FreshIntTy(v) => write!(f, "FreshIntTy({v})"), + FreshFloatTy(v) => write!(f, "FreshFloatTy({v})"), } } } -impl fmt::Debug for RegionKind { + +impl fmt::Debug for IntTy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - OptWithInfcx::new_no_ctx(self).fmt(f) + write!(f, "{}", self.name_str()) } } -// This is manually implemented because a derive would require `I: Encodable` -impl Encodable for RegionKind -where - I::EarlyBoundRegion: Encodable, - I::BoundRegion: Encodable, - I::FreeRegion: Encodable, - I::InferRegion: Encodable, - I::PlaceholderRegion: Encodable, -{ - fn encode(&self, e: &mut E) { - let disc = regionkind_discriminant(self); - match self { - ReEarlyBound(a) => e.emit_enum_variant(disc, |e| { - a.encode(e); - }), - ReLateBound(a, b) => e.emit_enum_variant(disc, |e| { - a.encode(e); - b.encode(e); - }), - ReFree(a) => e.emit_enum_variant(disc, |e| { - a.encode(e); - }), - ReStatic => e.emit_enum_variant(disc, |_| {}), - ReVar(a) => e.emit_enum_variant(disc, |e| { - a.encode(e); - }), - RePlaceholder(a) => e.emit_enum_variant(disc, |e| { - a.encode(e); - }), - ReErased => e.emit_enum_variant(disc, |_| {}), - ReError(_) => e.emit_enum_variant(disc, |_| {}), - } +impl fmt::Debug for UintTy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name_str()) } } -// This is manually implemented because a derive would require `I: Decodable` -impl> Decodable for RegionKind -where - I::EarlyBoundRegion: Decodable, - I::BoundRegion: Decodable, - I::FreeRegion: Decodable, - I::InferRegion: Decodable, - I::PlaceholderRegion: Decodable, - I::ErrorGuaranteed: Decodable, -{ - fn decode(d: &mut D) -> Self { - match Decoder::read_usize(d) { - 0 => ReEarlyBound(Decodable::decode(d)), - 1 => ReLateBound(Decodable::decode(d), Decodable::decode(d)), - 2 => ReFree(Decodable::decode(d)), - 3 => ReStatic, - 4 => ReVar(Decodable::decode(d)), - 5 => RePlaceholder(Decodable::decode(d)), - 6 => ReErased, - 7 => ReError(Decodable::decode(d)), - _ => panic!( - "{}", - format!( - "invalid enum variant tag while decoding `{}`, expected 0..{}", - "RegionKind", 8, - ) - ), +impl fmt::Debug for FloatTy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name_str()) + } +} + +impl fmt::Debug for InferTy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use InferTy::*; + match *self { + TyVar(ref v) => v.fmt(f), + IntVar(ref v) => v.fmt(f), + FloatVar(ref v) => v.fmt(f), + FreshTy(v) => write!(f, "FreshTy({v:?})"), + FreshIntTy(v) => write!(f, "FreshIntTy({v:?})"), + FreshFloatTy(v) => write!(f, "FreshFloatTy({v:?})"), } } } -// This is not a derived impl because a derive would require `I: HashStable` -impl HashStable for RegionKind -where - I::EarlyBoundRegion: HashStable, - I::BoundRegion: HashStable, - I::FreeRegion: HashStable, - I::InferRegion: HashStable, - I::PlaceholderRegion: HashStable, -{ - #[inline] - fn hash_stable( - &self, - hcx: &mut CTX, - hasher: &mut rustc_data_structures::stable_hasher::StableHasher, - ) { - std::mem::discriminant(self).hash_stable(hcx, hasher); - match self { - ReErased | ReStatic | ReError(_) => { - // No variant fields to hash for these ... - } - ReLateBound(d, r) => { - d.hash_stable(hcx, hasher); - r.hash_stable(hcx, hasher); - } - ReEarlyBound(r) => { - r.hash_stable(hcx, hasher); - } - ReFree(r) => { - r.hash_stable(hcx, hasher); - } - RePlaceholder(r) => { - r.hash_stable(hcx, hasher); - } - ReVar(_) => { - panic!("region variables should not be hashed: {self:?}") - } +impl> DebugWithInfcx for InferTy { + fn fmt>( + this: OptWithInfcx<'_, I, InfCtx, &Self>, + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + use InferTy::*; + match this.infcx.and_then(|infcx| infcx.universe_of_ty(*this.data)) { + None => write!(f, "{:?}", this.data), + Some(universe) => match *this.data { + TyVar(ty_vid) => write!(f, "?{}_{}t", ty_vid.index(), universe.index()), + IntVar(_) | FloatVar(_) | FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_) => { + unreachable!() + } + }, } } } diff --git a/compiler/rustc_type_ir/src/visit.rs b/compiler/rustc_type_ir/src/visit.rs index 891a4dda22fef..9c7b8156b0437 100644 --- a/compiler/rustc_type_ir/src/visit.rs +++ b/compiler/rustc_type_ir/src/visit.rs @@ -40,11 +40,14 @@ //! - ty.super_visit_with(visitor) //! - u.visit_with(visitor) //! ``` -use crate::Interner; +use rustc_data_structures::sync::Lrc; +use rustc_index::{Idx, IndexVec}; use std::fmt; use std::ops::ControlFlow; +use crate::Interner; + /// This trait is implemented for every type that can be visited, /// providing the skeleton of the traversal. /// @@ -116,3 +119,80 @@ pub trait TypeVisitor: Sized { p.super_visit_with(self) } } + +/////////////////////////////////////////////////////////////////////////// +// Traversal implementations. + +impl, U: TypeVisitable> TypeVisitable for (T, U) { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.0.visit_with(visitor)?; + self.1.visit_with(visitor) + } +} + +impl, B: TypeVisitable, C: TypeVisitable> TypeVisitable + for (A, B, C) +{ + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.0.visit_with(visitor)?; + self.1.visit_with(visitor)?; + self.2.visit_with(visitor) + } +} + +impl> TypeVisitable for Option { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + match self { + Some(v) => v.visit_with(visitor), + None => ControlFlow::Continue(()), + } + } +} + +impl, E: TypeVisitable> TypeVisitable for Result { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + match self { + Ok(v) => v.visit_with(visitor), + Err(e) => e.visit_with(visitor), + } + } +} + +impl> TypeVisitable for Lrc { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + (**self).visit_with(visitor) + } +} + +impl> TypeVisitable for Box { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + (**self).visit_with(visitor) + } +} + +impl> TypeVisitable for Vec { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + +// `TypeFoldable` isn't impl'd for `&[T]`. It doesn't make sense in the general +// case, because we can't return a new slice. But note that there are a couple +// of trivial impls of `TypeFoldable` for specific slice types elsewhere. +impl> TypeVisitable for &[T] { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + +impl> TypeVisitable for Box<[T]> { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + +impl, Ix: Idx> TypeVisitable for IndexVec { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} diff --git a/compiler/stable_mir/src/fold.rs b/compiler/stable_mir/src/fold.rs index 6471b2c2a3a5e..ca6ea92c4a13c 100644 --- a/compiler/stable_mir/src/fold.rs +++ b/compiler/stable_mir/src/fold.rs @@ -155,7 +155,7 @@ impl Foldable for RigidTy { RigidTy::FnDef(_, args) => *args = args.fold(folder)?, RigidTy::FnPtr(sig) => *sig = sig.fold(folder)?, RigidTy::Closure(_, args) => *args = args.fold(folder)?, - RigidTy::Generator(_, args, _) => *args = args.fold(folder)?, + RigidTy::Coroutine(_, args, _) => *args = args.fold(folder)?, RigidTy::Dynamic(pred, r, _) => { *pred = pred.fold(folder)?; *r = r.fold(folder)?; diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 72f026ee8de09..ea30fe6dbcd8b 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -1,4 +1,4 @@ -use crate::ty::{AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region}; +use crate::ty::{AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Movability, Region}; use crate::Opaque; use crate::{ty::Ty, Span}; @@ -59,7 +59,7 @@ pub enum TerminatorKind { target: usize, unwind: UnwindAction, }, - GeneratorDrop, + CoroutineDrop, InlineAsm { template: String, operands: Vec, @@ -94,8 +94,8 @@ pub enum AssertMessage { OverflowNeg(Operand), DivisionByZero(Operand), RemainderByZero(Operand), - ResumedAfterReturn(GeneratorKind), - ResumedAfterPanic(GeneratorKind), + ResumedAfterReturn(CoroutineKind), + ResumedAfterPanic(CoroutineKind), MisalignedPointerDereference { required: Operand, found: Operand }, } @@ -132,13 +132,13 @@ pub enum UnOp { } #[derive(Clone, Debug)] -pub enum GeneratorKind { - Async(AsyncGeneratorKind), - Gen, +pub enum CoroutineKind { + Async(AsyncCoroutineKind), + Coroutine, } #[derive(Clone, Debug)] -pub enum AsyncGeneratorKind { +pub enum AsyncCoroutineKind { Block, Closure, Fn, @@ -227,8 +227,8 @@ pub enum Rvalue { /// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo` /// has a destructor. /// - /// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After - /// generator lowering, `Generator` aggregate kinds are disallowed too. + /// Disallowed after deaggregation for all aggregate kinds except `Array` and `Coroutine`. After + /// coroutine lowering, `Coroutine` aggregate kinds are disallowed too. Aggregate(AggregateKind, Vec), /// * `Offset` has the same semantics as `<*const T>::offset`, except that the second @@ -331,7 +331,7 @@ pub enum AggregateKind { Tuple, Adt(AdtDef, VariantIdx, GenericArgs, Option, Option), Closure(ClosureDef, GenericArgs), - Generator(GeneratorDef, GenericArgs, Movability), + Coroutine(CoroutineDef, GenericArgs, Movability), } #[derive(Clone, Debug)] diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index 003045a4696d5..0ed2813bccf54 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -142,7 +142,7 @@ pub enum RigidTy { FnDef(FnDef, GenericArgs), FnPtr(PolyFnSig), Closure(ClosureDef, GenericArgs), - Generator(GeneratorDef, GenericArgs, Movability), + Coroutine(CoroutineDef, GenericArgs, Movability), Dynamic(Vec>, Region, DynKind), Never, Tuple(Vec), @@ -196,7 +196,7 @@ impl FnDef { pub struct ClosureDef(pub DefId); #[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub struct GeneratorDef(pub DefId); +pub struct CoroutineDef(pub DefId); #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct ParamDef(pub DefId); diff --git a/compiler/stable_mir/src/visitor.rs b/compiler/stable_mir/src/visitor.rs index 961009581388d..a6020cc5bd9b2 100644 --- a/compiler/stable_mir/src/visitor.rs +++ b/compiler/stable_mir/src/visitor.rs @@ -148,7 +148,7 @@ impl Visitable for RigidTy { RigidTy::FnDef(_, args) => args.visit(visitor), RigidTy::FnPtr(sig) => sig.visit(visitor), RigidTy::Closure(_, args) => args.visit(visitor), - RigidTy::Generator(_, args, _) => args.visit(visitor), + RigidTy::Coroutine(_, args, _) => args.visit(visitor), RigidTy::Dynamic(pred, r, _) => { pred.visit(visitor)?; r.visit(visitor) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 96b93830f9600..8ab851a0ea640 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -159,7 +159,7 @@ use core::marker::Tuple; use core::marker::Unsize; use core::mem::{self, SizedTypeProperties}; use core::ops::{ - CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver, + CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, DispatchFromDyn, Receiver, }; use core::pin::Pin; use core::ptr::{self, NonNull, Unique}; @@ -2106,28 +2106,28 @@ impl AsMut for Box { #[stable(feature = "pin", since = "1.33.0")] impl Unpin for Box where A: 'static {} -#[unstable(feature = "generator_trait", issue = "43122")] -impl + Unpin, R, A: Allocator> Generator for Box +#[unstable(feature = "coroutine_trait", issue = "43122")] +impl + Unpin, R, A: Allocator> Coroutine for Box where A: 'static, { type Yield = G::Yield; type Return = G::Return; - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState { + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState { G::resume(Pin::new(&mut *self), arg) } } -#[unstable(feature = "generator_trait", issue = "43122")] -impl, R, A: Allocator> Generator for Pin> +#[unstable(feature = "coroutine_trait", issue = "43122")] +impl, R, A: Allocator> Coroutine for Pin> where A: 'static, { type Yield = G::Yield; type Return = G::Return; - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState { + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState { G::resume((*self).as_mut(), arg) } } diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index d47f9de941cc8..f28ae9a07b48f 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -169,7 +169,7 @@ // // Language features: // tidy-alphabetical-start -#![cfg_attr(not(test), feature(generator_trait))] +#![cfg_attr(not(test), feature(coroutine_trait))] #![cfg_attr(test, feature(panic_update_hook))] #![cfg_attr(test, feature(test))] #![feature(allocator_internals)] diff --git a/library/alloc/tests/autotraits.rs b/library/alloc/tests/autotraits.rs index 6a8e55bff23d9..b41e457614e1d 100644 --- a/library/alloc/tests/autotraits.rs +++ b/library/alloc/tests/autotraits.rs @@ -14,8 +14,8 @@ fn test_btree_map() { // // We test autotraits in this convoluted way, instead of a straightforward // `require_send_sync::()`, because the interaction with - // generators exposes some current limitations in rustc's ability to prove a - // lifetime bound on the erased generator witness types. See the above link. + // coroutines exposes some current limitations in rustc's ability to prove a + // lifetime bound on the erased coroutine witness types. See the above link. // // A typical way this would surface in real code is: // diff --git a/library/core/src/future/mod.rs b/library/core/src/future/mod.rs index 089493d3766de..0f77a2d83433f 100644 --- a/library/core/src/future/mod.rs +++ b/library/core/src/future/mod.rs @@ -38,7 +38,7 @@ pub use poll_fn::{poll_fn, PollFn}; /// This type is needed because: /// -/// a) Generators cannot implement `for<'a, 'b> Generator<&'a mut Context<'b>>`, so we need to pass +/// a) Coroutines cannot implement `for<'a, 'b> Coroutine<&'a mut Context<'b>>`, so we need to pass /// a raw pointer (see ). /// b) Raw pointers and `NonNull` aren't `Send` or `Sync`, so that would make every single future /// non-Send/Sync as well, and we don't want that. diff --git a/library/core/src/iter/mod.rs b/library/core/src/iter/mod.rs index ca977d1ef8240..937a149acaa50 100644 --- a/library/core/src/iter/mod.rs +++ b/library/core/src/iter/mod.rs @@ -391,11 +391,11 @@ pub use self::traits::Iterator; pub use self::range::Step; #[unstable( - feature = "iter_from_generator", + feature = "iter_from_coroutine", issue = "43122", - reason = "generators are unstable" + reason = "coroutines are unstable" )] -pub use self::sources::from_generator; +pub use self::sources::from_coroutine; #[stable(feature = "iter_empty", since = "1.2.0")] pub use self::sources::{empty, Empty}; #[stable(feature = "iter_from_fn", since = "1.34.0")] diff --git a/library/core/src/iter/sources.rs b/library/core/src/iter/sources.rs index 3ec426a3ad9a1..56c1f86079a3a 100644 --- a/library/core/src/iter/sources.rs +++ b/library/core/src/iter/sources.rs @@ -1,6 +1,6 @@ mod empty; +mod from_coroutine; mod from_fn; -mod from_generator; mod once; mod once_with; mod repeat; @@ -27,11 +27,11 @@ pub use self::repeat_with::{repeat_with, RepeatWith}; pub use self::from_fn::{from_fn, FromFn}; #[unstable( - feature = "iter_from_generator", + feature = "iter_from_coroutine", issue = "43122", - reason = "generators are unstable" + reason = "coroutines are unstable" )] -pub use self::from_generator::from_generator; +pub use self::from_coroutine::from_coroutine; #[stable(feature = "iter_successors", since = "1.34.0")] pub use self::successors::{successors, Successors}; diff --git a/library/core/src/iter/sources/from_coroutine.rs b/library/core/src/iter/sources/from_coroutine.rs new file mode 100644 index 0000000000000..16fbca9b65e7d --- /dev/null +++ b/library/core/src/iter/sources/from_coroutine.rs @@ -0,0 +1,59 @@ +use crate::fmt; +use crate::ops::{Coroutine, CoroutineState}; +use crate::pin::Pin; + +/// Creates a new iterator where each iteration calls the provided coroutine. +/// +/// Similar to [`iter::from_fn`]. +/// +/// [`iter::from_fn`]: crate::iter::from_fn +/// +/// # Examples +/// +/// ``` +/// #![cfg_attr(bootstrap, feature(generators))] +/// #![cfg_attr(not(bootstrap), feature(coroutines))] +/// #![feature(iter_from_coroutine)] +/// +/// let it = std::iter::from_coroutine(|| { +/// yield 1; +/// yield 2; +/// yield 3; +/// }); +/// let v: Vec<_> = it.collect(); +/// assert_eq!(v, [1, 2, 3]); +/// ``` +#[inline] +#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")] +pub fn from_coroutine + Unpin>(coroutine: G) -> FromCoroutine { + FromCoroutine(coroutine) +} + +/// An iterator over the values yielded by an underlying coroutine. +/// +/// This `struct` is created by the [`iter::from_coroutine()`] function. See its documentation for +/// more. +/// +/// [`iter::from_coroutine()`]: from_coroutine +#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")] +#[derive(Clone)] +pub struct FromCoroutine(G); + +#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")] +impl + Unpin> Iterator for FromCoroutine { + type Item = G::Yield; + + fn next(&mut self) -> Option { + match Pin::new(&mut self.0).resume(()) { + CoroutineState::Yielded(n) => Some(n), + CoroutineState::Complete(()) => None, + } + } +} + +#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")] +impl fmt::Debug for FromCoroutine { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FromCoroutine").finish() + } +} diff --git a/library/core/src/iter/sources/from_generator.rs b/library/core/src/iter/sources/from_generator.rs deleted file mode 100644 index 4cbe731b222f9..0000000000000 --- a/library/core/src/iter/sources/from_generator.rs +++ /dev/null @@ -1,58 +0,0 @@ -use crate::fmt; -use crate::ops::{Generator, GeneratorState}; -use crate::pin::Pin; - -/// Creates a new iterator where each iteration calls the provided generator. -/// -/// Similar to [`iter::from_fn`]. -/// -/// [`iter::from_fn`]: crate::iter::from_fn -/// -/// # Examples -/// -/// ``` -/// #![feature(generators)] -/// #![feature(iter_from_generator)] -/// -/// let it = std::iter::from_generator(|| { -/// yield 1; -/// yield 2; -/// yield 3; -/// }); -/// let v: Vec<_> = it.collect(); -/// assert_eq!(v, [1, 2, 3]); -/// ``` -#[inline] -#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -pub fn from_generator + Unpin>(generator: G) -> FromGenerator { - FromGenerator(generator) -} - -/// An iterator over the values yielded by an underlying generator. -/// -/// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for -/// more. -/// -/// [`iter::from_generator()`]: from_generator -#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -#[derive(Clone)] -pub struct FromGenerator(G); - -#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -impl + Unpin> Iterator for FromGenerator { - type Item = G::Yield; - - fn next(&mut self) -> Option { - match Pin::new(&mut self.0).resume(()) { - GeneratorState::Yielded(n) => Some(n), - GeneratorState::Complete(()) => None, - } - } -} - -#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -impl fmt::Debug for FromGenerator { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("FromGenerator").finish() - } -} diff --git a/library/core/src/iter/sources/once_with.rs b/library/core/src/iter/sources/once_with.rs index 9309a06c8cf22..8b31ab2ff90c0 100644 --- a/library/core/src/iter/sources/once_with.rs +++ b/library/core/src/iter/sources/once_with.rs @@ -4,7 +4,7 @@ use crate::iter::{FusedIterator, TrustedLen}; /// Creates an iterator that lazily generates a value exactly once by invoking /// the provided closure. /// -/// This is commonly used to adapt a single value generator into a [`chain()`] of +/// This is commonly used to adapt a single value coroutine into a [`chain()`] of /// other kinds of iteration. Maybe you have an iterator that covers almost /// everything, but you need an extra special case. Maybe you have a function /// which works on iterators, but you only need to process one value. diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 6274a916f3e32..855bb1675c59d 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -242,7 +242,7 @@ use crate::slice; /// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that /// guarantee may evolve. #[stable(feature = "maybe_uninit", since = "1.36.0")] -// Lang item so we can wrap other types in it. This is useful for generators. +// Lang item so we can wrap other types in it. This is useful for coroutines. #[lang = "maybe_uninit"] #[derive(Copy)] #[repr(transparent)] diff --git a/library/core/src/ops/coroutine.rs b/library/core/src/ops/coroutine.rs new file mode 100644 index 0000000000000..e01a893a06853 --- /dev/null +++ b/library/core/src/ops/coroutine.rs @@ -0,0 +1,139 @@ +use crate::marker::Unpin; +use crate::pin::Pin; + +/// The result of a coroutine resumption. +/// +/// This enum is returned from the `Coroutine::resume` method and indicates the +/// possible return values of a coroutine. Currently this corresponds to either +/// a suspension point (`Yielded`) or a termination point (`Complete`). +#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] +#[cfg_attr(bootstrap, lang = "generator_state")] +#[cfg_attr(not(bootstrap), lang = "coroutine_state")] +#[unstable(feature = "coroutine_trait", issue = "43122")] +pub enum CoroutineState { + /// The coroutine suspended with a value. + /// + /// This state indicates that a coroutine has been suspended, and typically + /// corresponds to a `yield` statement. The value provided in this variant + /// corresponds to the expression passed to `yield` and allows coroutines to + /// provide a value each time they yield. + Yielded(Y), + + /// The coroutine completed with a return value. + /// + /// This state indicates that a coroutine has finished execution with the + /// provided value. Once a coroutine has returned `Complete` it is + /// considered a programmer error to call `resume` again. + Complete(R), +} + +/// The trait implemented by builtin coroutine types. +/// +/// Coroutines, also commonly referred to as coroutines, are currently an +/// experimental language feature in Rust. Added in [RFC 2033] coroutines are +/// currently intended to primarily provide a building block for async/await +/// syntax but will likely extend to also providing an ergonomic definition for +/// iterators and other primitives. +/// +/// The syntax and semantics for coroutines is unstable and will require a +/// further RFC for stabilization. At this time, though, the syntax is +/// closure-like: +/// +/// ```rust +/// #![cfg_attr(bootstrap, feature(generators))] +/// #![cfg_attr(not(bootstrap), feature(coroutines))] +/// #![feature(coroutine_trait)] +/// +/// use std::ops::{Coroutine, CoroutineState}; +/// use std::pin::Pin; +/// +/// fn main() { +/// let mut coroutine = || { +/// yield 1; +/// "foo" +/// }; +/// +/// match Pin::new(&mut coroutine).resume(()) { +/// CoroutineState::Yielded(1) => {} +/// _ => panic!("unexpected return from resume"), +/// } +/// match Pin::new(&mut coroutine).resume(()) { +/// CoroutineState::Complete("foo") => {} +/// _ => panic!("unexpected return from resume"), +/// } +/// } +/// ``` +/// +/// More documentation of coroutines can be found in the [unstable book]. +/// +/// [RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033 +/// [unstable book]: ../../unstable-book/language-features/coroutines.html +#[cfg_attr(bootstrap, lang = "generator")] +#[cfg_attr(not(bootstrap), lang = "coroutine")] +#[unstable(feature = "coroutine_trait", issue = "43122")] +#[fundamental] +pub trait Coroutine { + /// The type of value this coroutine yields. + /// + /// This associated type corresponds to the `yield` expression and the + /// values which are allowed to be returned each time a coroutine yields. + /// For example an iterator-as-a-coroutine would likely have this type as + /// `T`, the type being iterated over. + type Yield; + + /// The type of value this coroutine returns. + /// + /// This corresponds to the type returned from a coroutine either with a + /// `return` statement or implicitly as the last expression of a coroutine + /// literal. For example futures would use this as `Result` as it + /// represents a completed future. + type Return; + + /// Resumes the execution of this coroutine. + /// + /// This function will resume execution of the coroutine or start execution + /// if it hasn't already. This call will return back into the coroutine's + /// last suspension point, resuming execution from the latest `yield`. The + /// coroutine will continue executing until it either yields or returns, at + /// which point this function will return. + /// + /// # Return value + /// + /// The `CoroutineState` enum returned from this function indicates what + /// state the coroutine is in upon returning. If the `Yielded` variant is + /// returned then the coroutine has reached a suspension point and a value + /// has been yielded out. Coroutines in this state are available for + /// resumption at a later point. + /// + /// If `Complete` is returned then the coroutine has completely finished + /// with the value provided. It is invalid for the coroutine to be resumed + /// again. + /// + /// # Panics + /// + /// This function may panic if it is called after the `Complete` variant has + /// been returned previously. While coroutine literals in the language are + /// guaranteed to panic on resuming after `Complete`, this is not guaranteed + /// for all implementations of the `Coroutine` trait. + fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState; +} + +#[unstable(feature = "coroutine_trait", issue = "43122")] +impl, R> Coroutine for Pin<&mut G> { + type Yield = G::Yield; + type Return = G::Return; + + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState { + G::resume((*self).as_mut(), arg) + } +} + +#[unstable(feature = "coroutine_trait", issue = "43122")] +impl + Unpin, R> Coroutine for &mut G { + type Yield = G::Yield; + type Return = G::Return; + + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState { + G::resume(Pin::new(&mut *self), arg) + } +} diff --git a/library/core/src/ops/generator.rs b/library/core/src/ops/generator.rs deleted file mode 100644 index fee4beb1e84bb..0000000000000 --- a/library/core/src/ops/generator.rs +++ /dev/null @@ -1,135 +0,0 @@ -use crate::marker::Unpin; -use crate::pin::Pin; - -/// The result of a generator resumption. -/// -/// This enum is returned from the `Generator::resume` method and indicates the -/// possible return values of a generator. Currently this corresponds to either -/// a suspension point (`Yielded`) or a termination point (`Complete`). -#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] -#[lang = "generator_state"] -#[unstable(feature = "generator_trait", issue = "43122")] -pub enum GeneratorState { - /// The generator suspended with a value. - /// - /// This state indicates that a generator has been suspended, and typically - /// corresponds to a `yield` statement. The value provided in this variant - /// corresponds to the expression passed to `yield` and allows generators to - /// provide a value each time they yield. - Yielded(Y), - - /// The generator completed with a return value. - /// - /// This state indicates that a generator has finished execution with the - /// provided value. Once a generator has returned `Complete` it is - /// considered a programmer error to call `resume` again. - Complete(R), -} - -/// The trait implemented by builtin generator types. -/// -/// Generators, also commonly referred to as coroutines, are currently an -/// experimental language feature in Rust. Added in [RFC 2033] generators are -/// currently intended to primarily provide a building block for async/await -/// syntax but will likely extend to also providing an ergonomic definition for -/// iterators and other primitives. -/// -/// The syntax and semantics for generators is unstable and will require a -/// further RFC for stabilization. At this time, though, the syntax is -/// closure-like: -/// -/// ```rust -/// #![feature(generators, generator_trait)] -/// -/// use std::ops::{Generator, GeneratorState}; -/// use std::pin::Pin; -/// -/// fn main() { -/// let mut generator = || { -/// yield 1; -/// "foo" -/// }; -/// -/// match Pin::new(&mut generator).resume(()) { -/// GeneratorState::Yielded(1) => {} -/// _ => panic!("unexpected return from resume"), -/// } -/// match Pin::new(&mut generator).resume(()) { -/// GeneratorState::Complete("foo") => {} -/// _ => panic!("unexpected return from resume"), -/// } -/// } -/// ``` -/// -/// More documentation of generators can be found in the [unstable book]. -/// -/// [RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033 -/// [unstable book]: ../../unstable-book/language-features/generators.html -#[lang = "generator"] -#[unstable(feature = "generator_trait", issue = "43122")] -#[fundamental] -pub trait Generator { - /// The type of value this generator yields. - /// - /// This associated type corresponds to the `yield` expression and the - /// values which are allowed to be returned each time a generator yields. - /// For example an iterator-as-a-generator would likely have this type as - /// `T`, the type being iterated over. - type Yield; - - /// The type of value this generator returns. - /// - /// This corresponds to the type returned from a generator either with a - /// `return` statement or implicitly as the last expression of a generator - /// literal. For example futures would use this as `Result` as it - /// represents a completed future. - type Return; - - /// Resumes the execution of this generator. - /// - /// This function will resume execution of the generator or start execution - /// if it hasn't already. This call will return back into the generator's - /// last suspension point, resuming execution from the latest `yield`. The - /// generator will continue executing until it either yields or returns, at - /// which point this function will return. - /// - /// # Return value - /// - /// The `GeneratorState` enum returned from this function indicates what - /// state the generator is in upon returning. If the `Yielded` variant is - /// returned then the generator has reached a suspension point and a value - /// has been yielded out. Generators in this state are available for - /// resumption at a later point. - /// - /// If `Complete` is returned then the generator has completely finished - /// with the value provided. It is invalid for the generator to be resumed - /// again. - /// - /// # Panics - /// - /// This function may panic if it is called after the `Complete` variant has - /// been returned previously. While generator literals in the language are - /// guaranteed to panic on resuming after `Complete`, this is not guaranteed - /// for all implementations of the `Generator` trait. - fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState; -} - -#[unstable(feature = "generator_trait", issue = "43122")] -impl, R> Generator for Pin<&mut G> { - type Yield = G::Yield; - type Return = G::Return; - - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState { - G::resume((*self).as_mut(), arg) - } -} - -#[unstable(feature = "generator_trait", issue = "43122")] -impl + Unpin, R> Generator for &mut G { - type Yield = G::Yield; - type Return = G::Return; - - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState { - G::resume(Pin::new(&mut *self), arg) - } -} diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 97d9b750d92f9..fd8271b1344b5 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -141,10 +141,10 @@ mod arith; mod bit; mod control_flow; +mod coroutine; mod deref; mod drop; mod function; -mod generator; mod index; mod index_range; mod range; @@ -198,8 +198,8 @@ pub use self::try_trait::Residual; pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit}; -#[unstable(feature = "generator_trait", issue = "43122")] -pub use self::generator::{Generator, GeneratorState}; +#[unstable(feature = "coroutine_trait", issue = "43122")] +pub use self::coroutine::{Coroutine, CoroutineState}; #[unstable(feature = "coerce_unsized", issue = "18598")] pub use self::unsize::CoerceUnsized; diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 94c682b615ad4..bca97d4ee3643 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1085,17 +1085,19 @@ impl DispatchFromDyn> for Pin

where P: DispatchFromDyn {} /// # assert_eq!(42, block_on(async { 42 })); /// ``` /// -/// ### With `Generator`s +/// ### With `Coroutine`s /// /// ```rust -/// #![feature(generators, generator_trait)] +/// #![cfg_attr(bootstrap, feature(generators))] +/// #![cfg_attr(not(bootstrap), feature(coroutines))] +/// #![feature(coroutine_trait)] /// use core::{ -/// ops::{Generator, GeneratorState}, +/// ops::{Coroutine, CoroutineState}, /// pin::pin, /// }; /// -/// fn generator_fn() -> impl Generator /* not Unpin */ { -/// // Allow generator to be self-referential (not `Unpin`) +/// fn coroutine_fn() -> impl Coroutine /* not Unpin */ { +/// // Allow coroutine to be self-referential (not `Unpin`) /// // vvvvvv so that locals can cross yield points. /// static || { /// let foo = String::from("foo"); @@ -1107,18 +1109,18 @@ impl DispatchFromDyn> for Pin

where P: DispatchFromDyn {} /// } /// /// fn main() { -/// let mut generator = pin!(generator_fn()); -/// match generator.as_mut().resume(()) { -/// GeneratorState::Yielded(0) => {}, +/// let mut coroutine = pin!(coroutine_fn()); +/// match coroutine.as_mut().resume(()) { +/// CoroutineState::Yielded(0) => {}, /// _ => unreachable!(), /// } -/// match generator.as_mut().resume(()) { -/// GeneratorState::Yielded(3) => {}, +/// match coroutine.as_mut().resume(()) { +/// CoroutineState::Yielded(3) => {}, /// _ => unreachable!(), /// } -/// match generator.resume(()) { -/// GeneratorState::Yielded(_) => unreachable!(), -/// GeneratorState::Complete(()) => {}, +/// match coroutine.resume(()) { +/// CoroutineState::Yielded(_) => unreachable!(), +/// CoroutineState::Complete(()) => {}, /// } /// } /// ``` diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 073488817c483..b5ad3f280e6b1 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -102,7 +102,7 @@ //! //! | `target_arch` | Size limit | //! |---------------|---------| -//! | `x86`, `arm`, `mips`, `mips32r6, `powerpc`, `riscv32`, `sparc`, `hexagon` | 4 bytes | +//! | `x86`, `arm`, `mips`, `mips32r6`, `powerpc`, `riscv32`, `sparc`, `hexagon` | 4 bytes | //! | `x86_64`, `aarch64`, `loongarch64`, `mips64`, `mips64r6`, `powerpc64`, `riscv64`, `sparc64`, `s390x` | 8 bytes | //! //! Atomics loads that are larger than this limit as well as atomic loads with ordering other diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index ff538d55c6079..fa02dd52e0027 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -3,7 +3,7 @@ use core::fmt; use core::future::Future; use core::marker::Tuple; -use core::ops::{Generator, GeneratorState}; +use core::ops::{Coroutine, CoroutineState}; use core::pin::Pin; use core::task::{Context, Poll}; @@ -206,16 +206,16 @@ where } } -#[unstable(feature = "generator_trait", issue = "43122")] // also #98407 -impl Generator for Exclusive +#[unstable(feature = "coroutine_trait", issue = "43122")] // also #98407 +impl Coroutine for Exclusive where - G: Generator + ?Sized, + G: Coroutine + ?Sized, { type Yield = G::Yield; type Return = G::Return; #[inline] - fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState { + fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState { G::resume(self.get_pin_mut(), arg) } } diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index be173a7ace6d8..4d109285d1645 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -24,7 +24,7 @@ use crate::sys; /// reasonable best-effort is made to generate this seed from a high quality, /// secure source of randomness provided by the host without blocking the /// program. Because of this, the randomness of the seed depends on the output -/// quality of the system's random number generator when the seed is created. +/// quality of the system's random number coroutine when the seed is created. /// In particular, seeds generated when the system's entropy pool is abnormally /// low such as during system boot may be of a lower quality. /// diff --git a/src/doc/unstable-book/src/language-features/closure-track-caller.md b/src/doc/unstable-book/src/language-features/closure-track-caller.md index c948810d3e5a1..9974522319516 100644 --- a/src/doc/unstable-book/src/language-features/closure-track-caller.md +++ b/src/doc/unstable-book/src/language-features/closure-track-caller.md @@ -6,7 +6,7 @@ The tracking issue for this feature is: [#87417] ------------------------ -Allows using the `#[track_caller]` attribute on closures and generators. -Calls made to the closure or generator will have caller information +Allows using the `#[track_caller]` attribute on closures and coroutines. +Calls made to the closure or coroutine will have caller information available through `std::panic::Location::caller()`, just like using `#[track_caller]` on a function. diff --git a/src/doc/unstable-book/src/language-features/coroutines.md b/src/doc/unstable-book/src/language-features/coroutines.md new file mode 100644 index 0000000000000..fb1ba791aefe1 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/coroutines.md @@ -0,0 +1,246 @@ +# `coroutines` + +The tracking issue for this feature is: [#43122] + +[#43122]: https://github.com/rust-lang/rust/issues/43122 + +------------------------ + +The `coroutines` feature gate in Rust allows you to define coroutine or +coroutine literals. A coroutine is a "resumable function" that syntactically +resembles a closure but compiles to much different semantics in the compiler +itself. The primary feature of a coroutine is that it can be suspended during +execution to be resumed at a later date. Coroutines use the `yield` keyword to +"return", and then the caller can `resume` a coroutine to resume execution just +after the `yield` keyword. + +Coroutines are an extra-unstable feature in the compiler right now. Added in +[RFC 2033] they're mostly intended right now as a information/constraint +gathering phase. The intent is that experimentation can happen on the nightly +compiler before actual stabilization. A further RFC will be required to +stabilize coroutines/coroutines and will likely contain at least a few small +tweaks to the overall design. + +[RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033 + +A syntactical example of a coroutine is: + +```rust +#![feature(coroutines, coroutine_trait)] + +use std::ops::{Coroutine, CoroutineState}; +use std::pin::Pin; + +fn main() { + let mut coroutine = || { + yield 1; + return "foo" + }; + + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(1) => {} + _ => panic!("unexpected value from resume"), + } + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Complete("foo") => {} + _ => panic!("unexpected value from resume"), + } +} +``` + +Coroutines are closure-like literals which can contain a `yield` statement. The +`yield` statement takes an optional expression of a value to yield out of the +coroutine. All coroutine literals implement the `Coroutine` trait in the +`std::ops` module. The `Coroutine` trait has one main method, `resume`, which +resumes execution of the coroutine at the previous suspension point. + +An example of the control flow of coroutines is that the following example +prints all numbers in order: + +```rust +#![feature(coroutines, coroutine_trait)] + +use std::ops::Coroutine; +use std::pin::Pin; + +fn main() { + let mut coroutine = || { + println!("2"); + yield; + println!("4"); + }; + + println!("1"); + Pin::new(&mut coroutine).resume(()); + println!("3"); + Pin::new(&mut coroutine).resume(()); + println!("5"); +} +``` + +At this time the main intended use case of coroutines is an implementation +primitive for async/await syntax, but coroutines will likely be extended to +ergonomic implementations of iterators and other primitives in the future. +Feedback on the design and usage is always appreciated! + +### The `Coroutine` trait + +The `Coroutine` trait in `std::ops` currently looks like: + +```rust +# #![feature(arbitrary_self_types, coroutine_trait)] +# use std::ops::CoroutineState; +# use std::pin::Pin; + +pub trait Coroutine { + type Yield; + type Return; + fn resume(self: Pin<&mut Self>, resume: R) -> CoroutineState; +} +``` + +The `Coroutine::Yield` type is the type of values that can be yielded with the +`yield` statement. The `Coroutine::Return` type is the returned type of the +coroutine. This is typically the last expression in a coroutine's definition or +any value passed to `return` in a coroutine. The `resume` function is the entry +point for executing the `Coroutine` itself. + +The return value of `resume`, `CoroutineState`, looks like: + +```rust +pub enum CoroutineState { + Yielded(Y), + Complete(R), +} +``` + +The `Yielded` variant indicates that the coroutine can later be resumed. This +corresponds to a `yield` point in a coroutine. The `Complete` variant indicates +that the coroutine is complete and cannot be resumed again. Calling `resume` +after a coroutine has returned `Complete` will likely result in a panic of the +program. + +### Closure-like semantics + +The closure-like syntax for coroutines alludes to the fact that they also have +closure-like semantics. Namely: + +* When created, a coroutine executes no code. A closure literal does not + actually execute any of the closure's code on construction, and similarly a + coroutine literal does not execute any code inside the coroutine when + constructed. + +* Coroutines can capture outer variables by reference or by move, and this can + be tweaked with the `move` keyword at the beginning of the closure. Like + closures all coroutines will have an implicit environment which is inferred by + the compiler. Outer variables can be moved into a coroutine for use as the + coroutine progresses. + +* Coroutine literals produce a value with a unique type which implements the + `std::ops::Coroutine` trait. This allows actual execution of the coroutine + through the `Coroutine::resume` method as well as also naming it in return + types and such. + +* Traits like `Send` and `Sync` are automatically implemented for a `Coroutine` + depending on the captured variables of the environment. Unlike closures, + coroutines also depend on variables live across suspension points. This means + that although the ambient environment may be `Send` or `Sync`, the coroutine + itself may not be due to internal variables live across `yield` points being + not-`Send` or not-`Sync`. Note that coroutines do + not implement traits like `Copy` or `Clone` automatically. + +* Whenever a coroutine is dropped it will drop all captured environment + variables. + +### Coroutines as state machines + +In the compiler, coroutines are currently compiled as state machines. Each +`yield` expression will correspond to a different state that stores all live +variables over that suspension point. Resumption of a coroutine will dispatch on +the current state and then execute internally until a `yield` is reached, at +which point all state is saved off in the coroutine and a value is returned. + +Let's take a look at an example to see what's going on here: + +```rust +#![feature(coroutines, coroutine_trait)] + +use std::ops::Coroutine; +use std::pin::Pin; + +fn main() { + let ret = "foo"; + let mut coroutine = move || { + yield 1; + return ret + }; + + Pin::new(&mut coroutine).resume(()); + Pin::new(&mut coroutine).resume(()); +} +``` + +This coroutine literal will compile down to something similar to: + +```rust +#![feature(arbitrary_self_types, coroutines, coroutine_trait)] + +use std::ops::{Coroutine, CoroutineState}; +use std::pin::Pin; + +fn main() { + let ret = "foo"; + let mut coroutine = { + enum __Coroutine { + Start(&'static str), + Yield1(&'static str), + Done, + } + + impl Coroutine for __Coroutine { + type Yield = i32; + type Return = &'static str; + + fn resume(mut self: Pin<&mut Self>, resume: ()) -> CoroutineState { + use std::mem; + match mem::replace(&mut *self, __Coroutine::Done) { + __Coroutine::Start(s) => { + *self = __Coroutine::Yield1(s); + CoroutineState::Yielded(1) + } + + __Coroutine::Yield1(s) => { + *self = __Coroutine::Done; + CoroutineState::Complete(s) + } + + __Coroutine::Done => { + panic!("coroutine resumed after completion") + } + } + } + } + + __Coroutine::Start(ret) + }; + + Pin::new(&mut coroutine).resume(()); + Pin::new(&mut coroutine).resume(()); +} +``` + +Notably here we can see that the compiler is generating a fresh type, +`__Coroutine` in this case. This type has a number of states (represented here +as an `enum`) corresponding to each of the conceptual states of the coroutine. +At the beginning we're closing over our outer variable `foo` and then that +variable is also live over the `yield` point, so it's stored in both states. + +When the coroutine starts it'll immediately yield 1, but it saves off its state +just before it does so indicating that it has reached the yield point. Upon +resuming again we'll execute the `return ret` which returns the `Complete` +state. + +Here we can also note that the `Done` state, if resumed, panics immediately as +it's invalid to resume a completed coroutine. It's also worth noting that this +is just a rough desugaring, not a normative specification for what the compiler +does. diff --git a/src/doc/unstable-book/src/language-features/generators.md b/src/doc/unstable-book/src/language-features/generators.md deleted file mode 100644 index 7b865c9c679bc..0000000000000 --- a/src/doc/unstable-book/src/language-features/generators.md +++ /dev/null @@ -1,246 +0,0 @@ -# `generators` - -The tracking issue for this feature is: [#43122] - -[#43122]: https://github.com/rust-lang/rust/issues/43122 - ------------------------- - -The `generators` feature gate in Rust allows you to define generator or -coroutine literals. A generator is a "resumable function" that syntactically -resembles a closure but compiles to much different semantics in the compiler -itself. The primary feature of a generator is that it can be suspended during -execution to be resumed at a later date. Generators use the `yield` keyword to -"return", and then the caller can `resume` a generator to resume execution just -after the `yield` keyword. - -Generators are an extra-unstable feature in the compiler right now. Added in -[RFC 2033] they're mostly intended right now as a information/constraint -gathering phase. The intent is that experimentation can happen on the nightly -compiler before actual stabilization. A further RFC will be required to -stabilize generators/coroutines and will likely contain at least a few small -tweaks to the overall design. - -[RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033 - -A syntactical example of a generator is: - -```rust -#![feature(generators, generator_trait)] - -use std::ops::{Generator, GeneratorState}; -use std::pin::Pin; - -fn main() { - let mut generator = || { - yield 1; - return "foo" - }; - - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(1) => {} - _ => panic!("unexpected value from resume"), - } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Complete("foo") => {} - _ => panic!("unexpected value from resume"), - } -} -``` - -Generators are closure-like literals which can contain a `yield` statement. The -`yield` statement takes an optional expression of a value to yield out of the -generator. All generator literals implement the `Generator` trait in the -`std::ops` module. The `Generator` trait has one main method, `resume`, which -resumes execution of the generator at the previous suspension point. - -An example of the control flow of generators is that the following example -prints all numbers in order: - -```rust -#![feature(generators, generator_trait)] - -use std::ops::Generator; -use std::pin::Pin; - -fn main() { - let mut generator = || { - println!("2"); - yield; - println!("4"); - }; - - println!("1"); - Pin::new(&mut generator).resume(()); - println!("3"); - Pin::new(&mut generator).resume(()); - println!("5"); -} -``` - -At this time the main intended use case of generators is an implementation -primitive for async/await syntax, but generators will likely be extended to -ergonomic implementations of iterators and other primitives in the future. -Feedback on the design and usage is always appreciated! - -### The `Generator` trait - -The `Generator` trait in `std::ops` currently looks like: - -```rust -# #![feature(arbitrary_self_types, generator_trait)] -# use std::ops::GeneratorState; -# use std::pin::Pin; - -pub trait Generator { - type Yield; - type Return; - fn resume(self: Pin<&mut Self>, resume: R) -> GeneratorState; -} -``` - -The `Generator::Yield` type is the type of values that can be yielded with the -`yield` statement. The `Generator::Return` type is the returned type of the -generator. This is typically the last expression in a generator's definition or -any value passed to `return` in a generator. The `resume` function is the entry -point for executing the `Generator` itself. - -The return value of `resume`, `GeneratorState`, looks like: - -```rust -pub enum GeneratorState { - Yielded(Y), - Complete(R), -} -``` - -The `Yielded` variant indicates that the generator can later be resumed. This -corresponds to a `yield` point in a generator. The `Complete` variant indicates -that the generator is complete and cannot be resumed again. Calling `resume` -after a generator has returned `Complete` will likely result in a panic of the -program. - -### Closure-like semantics - -The closure-like syntax for generators alludes to the fact that they also have -closure-like semantics. Namely: - -* When created, a generator executes no code. A closure literal does not - actually execute any of the closure's code on construction, and similarly a - generator literal does not execute any code inside the generator when - constructed. - -* Generators can capture outer variables by reference or by move, and this can - be tweaked with the `move` keyword at the beginning of the closure. Like - closures all generators will have an implicit environment which is inferred by - the compiler. Outer variables can be moved into a generator for use as the - generator progresses. - -* Generator literals produce a value with a unique type which implements the - `std::ops::Generator` trait. This allows actual execution of the generator - through the `Generator::resume` method as well as also naming it in return - types and such. - -* Traits like `Send` and `Sync` are automatically implemented for a `Generator` - depending on the captured variables of the environment. Unlike closures, - generators also depend on variables live across suspension points. This means - that although the ambient environment may be `Send` or `Sync`, the generator - itself may not be due to internal variables live across `yield` points being - not-`Send` or not-`Sync`. Note that generators do - not implement traits like `Copy` or `Clone` automatically. - -* Whenever a generator is dropped it will drop all captured environment - variables. - -### Generators as state machines - -In the compiler, generators are currently compiled as state machines. Each -`yield` expression will correspond to a different state that stores all live -variables over that suspension point. Resumption of a generator will dispatch on -the current state and then execute internally until a `yield` is reached, at -which point all state is saved off in the generator and a value is returned. - -Let's take a look at an example to see what's going on here: - -```rust -#![feature(generators, generator_trait)] - -use std::ops::Generator; -use std::pin::Pin; - -fn main() { - let ret = "foo"; - let mut generator = move || { - yield 1; - return ret - }; - - Pin::new(&mut generator).resume(()); - Pin::new(&mut generator).resume(()); -} -``` - -This generator literal will compile down to something similar to: - -```rust -#![feature(arbitrary_self_types, generators, generator_trait)] - -use std::ops::{Generator, GeneratorState}; -use std::pin::Pin; - -fn main() { - let ret = "foo"; - let mut generator = { - enum __Generator { - Start(&'static str), - Yield1(&'static str), - Done, - } - - impl Generator for __Generator { - type Yield = i32; - type Return = &'static str; - - fn resume(mut self: Pin<&mut Self>, resume: ()) -> GeneratorState { - use std::mem; - match mem::replace(&mut *self, __Generator::Done) { - __Generator::Start(s) => { - *self = __Generator::Yield1(s); - GeneratorState::Yielded(1) - } - - __Generator::Yield1(s) => { - *self = __Generator::Done; - GeneratorState::Complete(s) - } - - __Generator::Done => { - panic!("generator resumed after completion") - } - } - } - } - - __Generator::Start(ret) - }; - - Pin::new(&mut generator).resume(()); - Pin::new(&mut generator).resume(()); -} -``` - -Notably here we can see that the compiler is generating a fresh type, -`__Generator` in this case. This type has a number of states (represented here -as an `enum`) corresponding to each of the conceptual states of the generator. -At the beginning we're closing over our outer variable `foo` and then that -variable is also live over the `yield` point, so it's stored in both states. - -When the generator starts it'll immediately yield 1, but it saves off its state -just before it does so indicating that it has reached the yield point. Upon -resuming again we'll execute the `return ret` which returns the `Complete` -state. - -Here we can also note that the `Done` state, if resumed, panics immediately as -it's invalid to resume a completed generator. It's also worth noting that this -is just a rough desugaring, not a normative specification for what the compiler -does. diff --git a/src/doc/unstable-book/src/the-unstable-book.md b/src/doc/unstable-book/src/the-unstable-book.md index 9090b134dc688..0f4fb405669a1 100644 --- a/src/doc/unstable-book/src/the-unstable-book.md +++ b/src/doc/unstable-book/src/the-unstable-book.md @@ -5,31 +5,31 @@ each one organized by a "feature flag." That is, when using an unstable feature of Rust, you must use a flag, like this: ```rust -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn main() { - let mut generator = || { + let mut coroutine = || { yield 1; return "foo" }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(1) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(1) => {} _ => panic!("unexpected value from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Complete("foo") => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Complete("foo") => {} _ => panic!("unexpected value from resume"), } } ``` -The `generators` feature [has a chapter][generators] describing how to use it. +The `coroutines` feature [has a chapter][coroutines] describing how to use it. -[generators]: language-features/generators.md +[coroutines]: language-features/coroutines.md Because this documentation relates to unstable features, we make no guarantees that what is contained here is accurate or up to date. It's developed on a diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e08318e4f5427..7becc156142df 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2266,9 +2266,9 @@ pub(crate) fn clean_middle_ty<'tcx>( } ty::Closure(..) => panic!("Closure"), - ty::Generator(..) => panic!("Generator"), + ty::Coroutine(..) => panic!("Coroutine"), ty::Placeholder(..) => panic!("Placeholder"), - ty::GeneratorWitness(..) => panic!("GeneratorWitness"), + ty::CoroutineWitness(..) => panic!("CoroutineWitness"), ty::Infer(..) => panic!("Infer"), ty::Error(_) => rustc_errors::FatalError.raise(), } diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index be2ee7915889a..e37d16f5bd0b8 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -141,7 +141,7 @@ impl From for ItemType { | DefKind::GlobalAsm | DefKind::Impl { .. } | DefKind::Closure - | DefKind::Generator => Self::ForeignType, + | DefKind::Coroutine => Self::ForeignType, } } } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index d216305e6a97d..fcd078858948e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -521,8 +521,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { } ty::Alias(..) | ty::Closure(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Dynamic(..) | ty::Param(_) | ty::Bound(..) @@ -1918,7 +1918,7 @@ fn resolution_failure( Variant | Field | Closure - | Generator + | Coroutine | AssocTy | AssocConst | AssocFn diff --git a/src/tools/clippy/clippy_lints/src/async_yields_async.rs b/src/tools/clippy/clippy_lints/src/async_yields_async.rs index 9464694a3b55a..96a90d599abaa 100644 --- a/src/tools/clippy/clippy_lints/src/async_yields_async.rs +++ b/src/tools/clippy/clippy_lints/src/async_yields_async.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; -use rustc_hir::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath}; +use rustc_hir::{AsyncCoroutineKind, Body, BodyId, ExprKind, CoroutineKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -45,10 +45,10 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - use AsyncGeneratorKind::{Block, Closure}; + use AsyncCoroutineKind::{Block, Closure}; // For functions, with explicitly defined types, don't warn. // XXXkhuey maybe we should? - if let Some(GeneratorKind::Async(Block | Closure)) = body.generator_kind { + if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind { if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { let body_id = BodyId { hir_id: body.value.hir_id, diff --git a/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs b/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs index accff9b0a34c6..60f9bbd7458b3 100644 --- a/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs +++ b/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs @@ -2,9 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; -use rustc_hir::{AsyncGeneratorKind, Body, GeneratorKind}; +use rustc_hir::{AsyncCoroutineKind, Body, CoroutineKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::GeneratorLayout; +use rustc_middle::mir::CoroutineLayout; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -195,26 +195,26 @@ impl LateLintPass<'_> for AwaitHolding { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - use AsyncGeneratorKind::{Block, Closure, Fn}; - if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind { + use AsyncCoroutineKind::{Block, Closure, Fn}; + if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind { let def_id = cx.tcx.hir().body_owner_def_id(body.id()); - if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) { - self.check_interior_types(cx, generator_layout); + if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) { + self.check_interior_types(cx, coroutine_layout); } } } } impl AwaitHolding { - fn check_interior_types(&self, cx: &LateContext<'_>, generator: &GeneratorLayout<'_>) { - for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() { + fn check_interior_types(&self, cx: &LateContext<'_>, coroutine: &CoroutineLayout<'_>) { + for (ty_index, ty_cause) in coroutine.field_tys.iter_enumerated() { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { let await_points = || { - generator + coroutine .variant_source_info .iter_enumerated() .filter_map(|(variant, source_info)| { - generator.variant_fields[variant] + coroutine.variant_fields[variant] .raw .contains(&ty_index) .then_some(source_info.span) diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 5134cf66050c9..efe82036dc802 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -842,8 +842,8 @@ impl TyCoercionStability { | ty::Adt(..) | ty::Foreign(_) | ty::FnDef(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Closure(..) | ty::Never | ty::Tuple(_) diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index e789e0da6797a..fc9b381664a30 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -436,8 +436,8 @@ fn lint_for_missing_headers( let body = cx.tcx.hir().body(body_id); let ret_ty = typeck.expr_ty(body.value); if implements_trait(cx, ret_ty, future, &[]); - if let ty::Generator(_, subs, _) = ret_ty.kind(); - if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result); + if let ty::Coroutine(_, subs, _) = ret_ty.kind(); + if is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result); then { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/large_futures.rs b/src/tools/clippy/clippy_lints/src/large_futures.rs index 19f1e08b57ad1..90096f0f506d7 100644 --- a/src/tools/clippy/clippy_lints/src/large_futures.rs +++ b/src/tools/clippy/clippy_lints/src/large_futures.rs @@ -12,7 +12,7 @@ declare_clippy_lint! { /// It checks for the size of a `Future` created by `async fn` or `async {}`. /// /// ### Why is this bad? - /// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Generator`, + /// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Coroutine`, /// large size of a `Future` may cause stack overflows. /// /// ### Example diff --git a/src/tools/clippy/clippy_lints/src/manual_async_fn.rs b/src/tools/clippy/clippy_lints/src/manual_async_fn.rs index 577bc1d661dbd..914ceca2995d4 100644 --- a/src/tools/clippy/clippy_lints/src/manual_async_fn.rs +++ b/src/tools/clippy/clippy_lints/src/manual_async_fn.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, + AsyncCoroutineKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, CoroutineKind, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -188,7 +188,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) .. } = block_expr; let closure_body = cx.tcx.hir().body(body); - if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block)); + if closure_body.coroutine_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block)); then { return Some(closure_body); } diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs b/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs index 674d345174819..b44a2716dde14 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( if_chain! { if !expr.span.from_expansion(); if let ExprKind::Closure(c) = m_arg.kind; - if let Body {params: [p], value: body_expr, generator_kind: _ } = cx.tcx.hir().body(c.body); + if let Body {params: [p], value: body_expr, coroutine_kind: _ } = cx.tcx.hir().body(c.body); if let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind; let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) { diff --git a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs index 0e834fb3ac768..d267b3de7f25a 100644 --- a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath}; +use rustc_hir::{AsyncCoroutineKind, Block, Body, Expr, ExprKind, CoroutineKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -87,7 +87,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(GeneratorKind::Async(AsyncGeneratorKind::Fn)) = body.generator_kind { + if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.coroutine_kind { if let ExprKind::Block( Block { expr: diff --git a/src/tools/clippy/clippy_lints/src/redundant_async_block.rs b/src/tools/clippy/clippy_lints/src/redundant_async_block.rs index 8193057a6eb27..b8f787e1f1fbd 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_async_block.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_async_block.rs @@ -5,7 +5,7 @@ use clippy_utils::peel_blocks; use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::visitors::for_each_expr; use rustc_errors::Applicability; -use rustc_hir::{AsyncGeneratorKind, Closure, Expr, ExprKind, GeneratorKind, MatchSource}; +use rustc_hir::{AsyncCoroutineKind, Closure, Expr, ExprKind, CoroutineKind, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::UpvarCapture; @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && let body = cx.tcx.hir().body(*body) && - matches!(body.generator_kind, Some(GeneratorKind::Async(AsyncGeneratorKind::Block))) + matches!(body.coroutine_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block))) { cx .typeck_results() diff --git a/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs b/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs index f42836611ca53..c18237e887db4 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { // without this check, we'd end up linting twice. && !matches!(recv.kind, hir::ExprKind::Call(..)) && let (full_expr, call_depth) = get_parent_call_exprs(cx, expr) - && let Some((body, fn_decl, generator_kind)) = find_innermost_closure(cx, recv, call_depth) + && let Some((body, fn_decl, coroutine_kind)) = find_innermost_closure(cx, recv, call_depth) { span_lint_and_then( cx, @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { let mut applicability = Applicability::MachineApplicable; let mut hint = Sugg::hir_with_context(cx, body, full_expr.span.ctxt(), "..", &mut applicability); - if generator_kind.is_async() + if coroutine_kind.is_async() && let hir::ExprKind::Closure(closure) = body.kind { let async_closure_body = cx.tcx.hir().body(closure.body); diff --git a/src/tools/clippy/clippy_lints/src/unused_async.rs b/src/tools/clippy/clippy_lints/src/unused_async.rs index bc7c3897a6e8d..3649f8792ae5f 100644 --- a/src/tools/clippy/clippy_lints/src/unused_async.rs +++ b/src/tools/clippy/clippy_lints/src/unused_async.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { } fn visit_body(&mut self, b: &'tcx Body<'tcx>) { - let is_async_block = matches!(b.generator_kind, Some(rustc_hir::GeneratorKind::Async(_))); + let is_async_block = matches!(b.coroutine_kind, Some(rustc_hir::CoroutineKind::Async(_))); if is_async_block { self.async_depth += 1; diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 55f9cb27ad4db..f6096ea546daa 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -305,8 +305,8 @@ fn check_terminator<'tcx>( Ok(()) }, TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body), - TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { - Err((span, "const fn generators are unstable".into())) + TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => { + Err((span, "const fn coroutines are unstable".into())) }, TerminatorKind::Call { func, diff --git a/src/tools/clippy/tests/ui/crashes/ice-5238.rs b/src/tools/clippy/tests/ui/crashes/ice-5238.rs index 989eb6d448557..b1fc3fb9d2511 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-5238.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-5238.rs @@ -1,6 +1,6 @@ // Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { let _ = || { diff --git a/src/tools/clippy/tests/ui/large_futures.fixed b/src/tools/clippy/tests/ui/large_futures.fixed index 4c192d1c8d1bd..aa8c3021b9708 100644 --- a/src/tools/clippy/tests/ui/large_futures.fixed +++ b/src/tools/clippy/tests/ui/large_futures.fixed @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![warn(clippy::large_futures)] #![allow(clippy::never_loop)] #![allow(clippy::future_not_send)] diff --git a/src/tools/clippy/tests/ui/large_futures.rs b/src/tools/clippy/tests/ui/large_futures.rs index 557d89a9cf99d..fc6ea458d3dbd 100644 --- a/src/tools/clippy/tests/ui/large_futures.rs +++ b/src/tools/clippy/tests/ui/large_futures.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![warn(clippy::large_futures)] #![allow(clippy::never_loop)] #![allow(clippy::future_not_send)] diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 5d972fdd270fa..bc3882bcf2b05 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -029d00c4a3176a705e0092de3e1739f8b7c32010 +249624b5043013d18c00f0401ca431c1a6baa8cd diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index fd75e8b0ca659..965cd534d1e5c 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -492,7 +492,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { // `Variants::Multiple`. match v.layout.variants { Variants::Multiple { .. } => { - // A multi-variant enum, or generator, or so. + // A multi-variant enum, or coroutine, or so. // Treat this like a union: without reading from memory, // we cannot determine the variant we are in. Reading from // memory would be subject to Stacked Borrows rules, leading diff --git a/src/tools/miri/tests/fail/coroutine-pinned-moved.rs b/src/tools/miri/tests/fail/coroutine-pinned-moved.rs new file mode 100644 index 0000000000000..005ae7e91323c --- /dev/null +++ b/src/tools/miri/tests/fail/coroutine-pinned-moved.rs @@ -0,0 +1,46 @@ +//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows +#![feature(coroutines, coroutine_trait)] + +use std::{ + ops::{Coroutine, CoroutineState}, + pin::Pin, +}; + +fn firstn() -> impl Coroutine { + static move || { + let mut num = 0; + let num = &mut num; + *num += 0; + + yield *num; + *num += 1; //~ERROR: has been freed + } +} + +struct CoroutineIteratorAdapter(G); + +impl Iterator for CoroutineIteratorAdapter +where + G: Coroutine, +{ + type Item = G::Yield; + + fn next(&mut self) -> Option { + let me = unsafe { Pin::new_unchecked(&mut self.0) }; + match me.resume(()) { + CoroutineState::Yielded(x) => Some(x), + CoroutineState::Complete(_) => None, + } + } +} + +fn main() { + let mut coroutine_iterator_2 = { + let mut coroutine_iterator = Box::new(CoroutineIteratorAdapter(firstn())); + coroutine_iterator.next(); // pin it + + Box::new(*coroutine_iterator) // move it + }; // *deallocate* coroutine_iterator + + coroutine_iterator_2.next(); // and use moved value +} diff --git a/src/tools/miri/tests/fail/generator-pinned-moved.stderr b/src/tools/miri/tests/fail/coroutine-pinned-moved.stderr similarity index 59% rename from src/tools/miri/tests/fail/generator-pinned-moved.stderr rename to src/tools/miri/tests/fail/coroutine-pinned-moved.stderr index 8ad0ce8cc32af..919fa87f9d7b3 100644 --- a/src/tools/miri/tests/fail/generator-pinned-moved.stderr +++ b/src/tools/miri/tests/fail/coroutine-pinned-moved.stderr @@ -1,5 +1,5 @@ error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling - --> $DIR/generator-pinned-moved.rs:LL:CC + --> $DIR/coroutine-pinned-moved.rs:LL:CC | LL | *num += 1; | ^^^^^^^^^ memory access failed: ALLOC has been freed, so this pointer is dangling @@ -7,27 +7,27 @@ LL | *num += 1; = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information help: ALLOC was allocated here: - --> $DIR/generator-pinned-moved.rs:LL:CC + --> $DIR/coroutine-pinned-moved.rs:LL:CC | -LL | let mut generator_iterator = Box::new(GeneratorIteratorAdapter(firstn())); +LL | let mut coroutine_iterator = Box::new(CoroutineIteratorAdapter(firstn())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: ALLOC was deallocated here: - --> $DIR/generator-pinned-moved.rs:LL:CC + --> $DIR/coroutine-pinned-moved.rs:LL:CC | -LL | }; // *deallocate* generator_iterator +LL | }; // *deallocate* coroutine_iterator | ^ = note: BACKTRACE (of the first span): - = note: inside closure at $DIR/generator-pinned-moved.rs:LL:CC -note: inside ` as std::iter::Iterator>::next` - --> $DIR/generator-pinned-moved.rs:LL:CC + = note: inside closure at $DIR/coroutine-pinned-moved.rs:LL:CC +note: inside ` as std::iter::Iterator>::next` + --> $DIR/coroutine-pinned-moved.rs:LL:CC | LL | match me.resume(()) { | ^^^^^^^^^^^^^ - = note: inside `> as std::iter::Iterator>::next` at RUSTLIB/alloc/src/boxed.rs:LL:CC + = note: inside `> as std::iter::Iterator>::next` at RUSTLIB/alloc/src/boxed.rs:LL:CC note: inside `main` - --> $DIR/generator-pinned-moved.rs:LL:CC + --> $DIR/coroutine-pinned-moved.rs:LL:CC | -LL | generator_iterator_2.next(); // and use moved value +LL | coroutine_iterator_2.next(); // and use moved value | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/generator-pinned-moved.rs b/src/tools/miri/tests/fail/generator-pinned-moved.rs deleted file mode 100644 index 33348ace9c41d..0000000000000 --- a/src/tools/miri/tests/fail/generator-pinned-moved.rs +++ /dev/null @@ -1,46 +0,0 @@ -//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -#![feature(generators, generator_trait)] - -use std::{ - ops::{Generator, GeneratorState}, - pin::Pin, -}; - -fn firstn() -> impl Generator { - static move || { - let mut num = 0; - let num = &mut num; - *num += 0; - - yield *num; - *num += 1; //~ERROR: has been freed - } -} - -struct GeneratorIteratorAdapter(G); - -impl Iterator for GeneratorIteratorAdapter -where - G: Generator, -{ - type Item = G::Yield; - - fn next(&mut self) -> Option { - let me = unsafe { Pin::new_unchecked(&mut self.0) }; - match me.resume(()) { - GeneratorState::Yielded(x) => Some(x), - GeneratorState::Complete(_) => None, - } - } -} - -fn main() { - let mut generator_iterator_2 = { - let mut generator_iterator = Box::new(GeneratorIteratorAdapter(firstn())); - generator_iterator.next(); // pin it - - Box::new(*generator_iterator) // move it - }; // *deallocate* generator_iterator - - generator_iterator_2.next(); // and use moved value -} diff --git a/src/tools/miri/tests/pass/generator.rs b/src/tools/miri/tests/pass/coroutine.rs similarity index 88% rename from src/tools/miri/tests/pass/generator.rs rename to src/tools/miri/tests/pass/coroutine.rs index 20099603455d4..49bfa92a0529b 100644 --- a/src/tools/miri/tests/pass/generator.rs +++ b/src/tools/miri/tests/pass/coroutine.rs @@ -1,12 +1,12 @@ //@revisions: stack tree //@[tree]compile-flags: -Zmiri-tree-borrows -#![feature(generators, generator_trait, never_type)] +#![feature(coroutines, coroutine_trait, never_type)] use std::fmt::Debug; use std::mem::ManuallyDrop; use std::ops::{ - Generator, - GeneratorState::{self, *}, + Coroutine, + CoroutineState::{self, *}, }; use std::pin::Pin; use std::ptr; @@ -15,22 +15,22 @@ use std::sync::atomic::{AtomicUsize, Ordering}; fn basic() { fn finish(mut amt: usize, self_referential: bool, mut t: T) -> T::Return where - T: Generator, + T: Coroutine, { // We are not moving the `t` around until it gets dropped, so this is okay. let mut t = unsafe { Pin::new_unchecked(&mut t) }; loop { let state = t.as_mut().resume(()); - // Test if the generator is valid (according to type invariants). - // For self-referential generators however this is UB! + // Test if the coroutine is valid (according to type invariants). + // For self-referential coroutines however this is UB! if !self_referential { let _ = unsafe { ManuallyDrop::new(ptr::read(t.as_mut().get_unchecked_mut())) }; } match state { - GeneratorState::Yielded(y) => { + CoroutineState::Yielded(y) => { amt -= y; } - GeneratorState::Complete(ret) => { + CoroutineState::Complete(ret) => { assert_eq!(amt, 0); return ret; } @@ -86,7 +86,7 @@ fn basic() { yield 1; }); - // also test self-referential generators + // also test self-referential coroutines assert_eq!( finish(5, true, static || { let mut x = 5; @@ -134,9 +134,9 @@ fn basic() { } fn smoke_resume_arg() { - fn drain + Unpin, R, Y>( + fn drain + Unpin, R, Y>( gen: &mut G, - inout: Vec<(R, GeneratorState)>, + inout: Vec<(R, CoroutineState)>, ) where Y: Debug + PartialEq, G::Return: Debug + PartialEq, @@ -145,7 +145,7 @@ fn smoke_resume_arg() { for (input, out) in inout { assert_eq!(gen.as_mut().resume(input), out); - // Test if the generator is valid (according to type invariants). + // Test if the coroutine is valid (according to type invariants). let _ = unsafe { ManuallyDrop::new(ptr::read(gen.as_mut().get_unchecked_mut())) }; } } diff --git a/src/tools/miri/tests/pass/move-data-across-await-point.rs b/src/tools/miri/tests/pass/move-data-across-await-point.rs index 489fae66ffb2b..5990d66fbddbd 100644 --- a/src/tools/miri/tests/pass/move-data-across-await-point.rs +++ b/src/tools/miri/tests/pass/move-data-across-await-point.rs @@ -15,7 +15,7 @@ async fn data_moved_async() { // `raw_pointer` points to the original location where the Vec was stored in the caller. // `data` is where that Vec (to be precise, its ptr+capacity+len on-stack data) // got moved to. Those will usually not be the same since the Vec got moved twice - // (into the function call, and then into the generator upvar). + // (into the function call, and then into the coroutine upvar). assert_ne!(raw_pointer, raw_pointer2); unsafe { // This writes into the `x` in `data_moved_async`, re-initializing it. diff --git a/src/tools/miri/tests/pass/stacked-borrows/generators-self-referential.rs b/src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs similarity index 61% rename from src/tools/miri/tests/pass/stacked-borrows/generators-self-referential.rs rename to src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs index b71912882dd2a..c4b15c8758bef 100644 --- a/src/tools/miri/tests/pass/stacked-borrows/generators-self-referential.rs +++ b/src/tools/miri/tests/pass/stacked-borrows/coroutine-self-referential.rs @@ -1,13 +1,13 @@ // See https://github.com/rust-lang/unsafe-code-guidelines/issues/148: // this fails when Stacked Borrows is strictly applied even to `!Unpin` types. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::{ - ops::{Generator, GeneratorState}, + ops::{Coroutine, CoroutineState}, pin::Pin, }; -fn firstn() -> impl Generator { +fn firstn() -> impl Coroutine { static move || { let mut num = 0; let num = &mut num; @@ -24,10 +24,10 @@ fn firstn() -> impl Generator { } fn main() { - let mut generator_iterator = firstn(); - let mut pin = unsafe { Pin::new_unchecked(&mut generator_iterator) }; + let mut coroutine_iterator = firstn(); + let mut pin = unsafe { Pin::new_unchecked(&mut coroutine_iterator) }; let mut sum = 0; - while let GeneratorState::Yielded(x) = pin.as_mut().resume(()) { + while let CoroutineState::Yielded(x) = pin.as_mut().resume(()) { sum += x; } assert_eq!(sum, 3); diff --git a/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs b/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs index d2ba184184485..dd3ee36f988db 100644 --- a/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs +++ b/src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs @@ -223,7 +223,7 @@ fn wide_raw_ptr_in_tuple() { fn not_unpin_not_protected() { // `&mut !Unpin`, at least for now, does not get `noalias` nor `dereferenceable`, so we also // don't add protectors. (We could, but until we have a better idea for where we want to go with - // the self-referential-generator situation, it does not seem worth the potential trouble.) + // the self-referential-coroutine situation, it does not seem worth the potential trouble.) use std::marker::PhantomPinned; pub struct NotUnpin(i32, PhantomPinned); diff --git a/src/tools/miri/tests/pass/track-caller-attribute.rs b/src/tools/miri/tests/pass/track-caller-attribute.rs index 1b0226e61b57c..d88bcc98858f5 100644 --- a/src/tools/miri/tests/pass/track-caller-attribute.rs +++ b/src/tools/miri/tests/pass/track-caller-attribute.rs @@ -1,10 +1,10 @@ #![feature(core_intrinsics)] #![feature(stmt_expr_attributes)] #![feature(closure_track_caller)] -#![feature(generator_trait)] -#![feature(generators)] +#![feature(coroutine_trait)] +#![feature(coroutines)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::panic::Location; use std::pin::Pin; @@ -210,55 +210,55 @@ fn test_closure() { assert_eq!(non_tracked_loc.column(), 33); } -fn test_generator() { +fn test_coroutine() { #[track_caller] - fn mono_generator>( + fn mono_coroutine>( val: Pin<&mut F>, ) -> (&'static str, String, Loc) { match val.resume("Mono".to_string()) { - GeneratorState::Yielded(val) => val, + CoroutineState::Yielded(val) => val, _ => unreachable!(), } } #[track_caller] - fn dyn_generator( - val: Pin<&mut dyn Generator>, + fn dyn_coroutine( + val: Pin<&mut dyn Coroutine>, ) -> (&'static str, String, Loc) { match val.resume("Dyn".to_string()) { - GeneratorState::Yielded(val) => val, + CoroutineState::Yielded(val) => val, _ => unreachable!(), } } #[rustfmt::skip] - let generator = #[track_caller] |arg: String| { + let coroutine = #[track_caller] |arg: String| { yield ("first", arg.clone(), Location::caller()); yield ("second", arg.clone(), Location::caller()); }; - let mut pinned = Box::pin(generator); - let (dyn_ret, dyn_arg, dyn_loc) = dyn_generator(pinned.as_mut()); + let mut pinned = Box::pin(coroutine); + let (dyn_ret, dyn_arg, dyn_loc) = dyn_coroutine(pinned.as_mut()); assert_eq!(dyn_ret, "first"); assert_eq!(dyn_arg, "Dyn".to_string()); - // The `Generator` trait does not have `#[track_caller]` on `resume`, so + // The `Coroutine` trait does not have `#[track_caller]` on `resume`, so // this will not match. assert_ne!(dyn_loc.file(), file!()); - let (mono_ret, mono_arg, mono_loc) = mono_generator(pinned.as_mut()); + let (mono_ret, mono_arg, mono_loc) = mono_coroutine(pinned.as_mut()); let mono_line = line!() - 1; assert_eq!(mono_ret, "second"); - // The generator ignores the argument to the second `resume` call + // The coroutine ignores the argument to the second `resume` call assert_eq!(mono_arg, "Dyn".to_string()); assert_eq!(mono_loc.file(), file!()); assert_eq!(mono_loc.line(), mono_line); assert_eq!(mono_loc.column(), 42); #[rustfmt::skip] - let non_tracked_generator = || { yield Location::caller(); }; - let non_tracked_line = line!() - 1; // This is the line of the generator, not its caller - let non_tracked_loc = match Box::pin(non_tracked_generator).as_mut().resume(()) { - GeneratorState::Yielded(val) => val, + let non_tracked_coroutine = || { yield Location::caller(); }; + let non_tracked_line = line!() - 1; // This is the line of the coroutine, not its caller + let non_tracked_loc = match Box::pin(non_tracked_coroutine).as_mut().resume(()) { + CoroutineState::Yielded(val) => val, _ => unreachable!(), }; assert_eq!(non_tracked_loc.file(), file!()); @@ -272,5 +272,5 @@ fn main() { test_trait_obj(); test_trait_obj2(); test_closure(); - test_generator(); + test_coroutine(); } diff --git a/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs b/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs index 89752bffe9f9d..d45be91afccb6 100644 --- a/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs +++ b/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs @@ -315,7 +315,7 @@ fn wide_raw_ptr_in_tuple() { fn not_unpin_not_protected() { // `&mut !Unpin`, at least for now, does not get `noalias` nor `dereferenceable`, so we also // don't add protectors. (We could, but until we have a better idea for where we want to go with - // the self-referential-generator situation, it does not seem worth the potential trouble.) + // the self-referential-coroutine situation, it does not seem worth the potential trouble.) use std::marker::PhantomPinned; pub struct NotUnpin(i32, PhantomPinned); diff --git a/src/tools/rustfmt/tests/source/immovable_generators.rs b/src/tools/rustfmt/tests/source/immovable_coroutines.rs similarity index 75% rename from src/tools/rustfmt/tests/source/immovable_generators.rs rename to src/tools/rustfmt/tests/source/immovable_coroutines.rs index c57a1e1448349..3b94af0c96ce4 100644 --- a/src/tools/rustfmt/tests/source/immovable_generators.rs +++ b/src/tools/rustfmt/tests/source/immovable_coroutines.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] unsafe fn foo() { let mut ga = static || { diff --git a/src/tools/rustfmt/tests/target/immovable_generators.rs b/src/tools/rustfmt/tests/target/immovable_coroutines.rs similarity index 75% rename from src/tools/rustfmt/tests/target/immovable_generators.rs rename to src/tools/rustfmt/tests/target/immovable_coroutines.rs index 0bf7a2d91ba15..f52cfa00f9783 100644 --- a/src/tools/rustfmt/tests/target/immovable_generators.rs +++ b/src/tools/rustfmt/tests/target/immovable_coroutines.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] unsafe fn foo() { let mut ga = static || { diff --git a/src/tools/rustfmt/tests/target/issue_4110.rs b/src/tools/rustfmt/tests/target/issue_4110.rs index d3734e90b7ffa..ea8fa3b73d284 100644 --- a/src/tools/rustfmt/tests/target/issue_4110.rs +++ b/src/tools/rustfmt/tests/target/issue_4110.rs @@ -12,7 +12,7 @@ fn bindings() { span, .. }, - ) if borrow_spans.for_generator() | borrow_spans.for_closure() => self + ) if borrow_spans.for_coroutine() | borrow_spans.for_closure() => self .report_escaping_closure_capture( borrow_spans, borrow_span, diff --git a/tests/codegen/async-fn-debug-awaitee-field.rs b/tests/codegen/async-fn-debug-awaitee-field.rs index 29defe68f8b8d..03cc46cdcde55 100644 --- a/tests/codegen/async-fn-debug-awaitee-field.rs +++ b/tests/codegen/async-fn-debug-awaitee-field.rs @@ -1,4 +1,4 @@ -// This test makes sure that the generator field capturing the awaitee in a `.await` expression +// This test makes sure that the coroutine field capturing the awaitee in a `.await` expression // is called "__awaitee" in debuginfo. This name must not be changed since debuggers and debugger // extensions rely on the field having this name. diff --git a/tests/codegen/async-fn-debug-msvc.rs b/tests/codegen/async-fn-debug-msvc.rs index 73c652c9dd15e..707a0d2774079 100644 --- a/tests/codegen/async-fn-debug-msvc.rs +++ b/tests/codegen/async-fn-debug-msvc.rs @@ -1,4 +1,4 @@ -// Verify debuginfo for generators: +// Verify debuginfo for coroutines: // - Each variant points to the file and line of its yield point // - The discriminants are marked artificial // - Other fields are not marked artificial diff --git a/tests/codegen/generator-debug-msvc.rs b/tests/codegen/coroutine-debug-msvc.rs similarity index 88% rename from tests/codegen/generator-debug-msvc.rs rename to tests/codegen/coroutine-debug-msvc.rs index 9d70ccdef032f..6d16e7576c1ad 100644 --- a/tests/codegen/generator-debug-msvc.rs +++ b/tests/codegen/coroutine-debug-msvc.rs @@ -1,4 +1,4 @@ -// Verify debuginfo for generators: +// Verify debuginfo for coroutines: // - Each variant points to the file and line of its yield point // - The discriminants are marked artificial // - Other fields are not marked artificial @@ -7,10 +7,10 @@ // compile-flags: -C debuginfo=2 // only-msvc -#![feature(generators, generator_trait)] -use std::ops::Generator; +#![feature(coroutines, coroutine_trait)] +use std::ops::Coroutine; -fn generator_test() -> impl Generator { +fn coroutine_test() -> impl Coroutine { || { yield 0; let s = String::from("foo"); @@ -20,7 +20,7 @@ fn generator_test() -> impl Generator { // FIXME: No way to reliably check the filename. -// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "enum2$" +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "enum2$" // CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "variant0", scope: [[GEN]], // For brevity, we only check the struct name and members of the last variant. // CHECK-SAME: file: [[FILE:![0-9]*]], line: 14, @@ -55,5 +55,5 @@ fn generator_test() -> impl Generator { // CHECK-NOT: flags: DIFlagArtificial fn main() { - let _dummy = generator_test(); + let _dummy = coroutine_test(); } diff --git a/tests/codegen/generator-debug.rs b/tests/codegen/coroutine-debug.rs similarity index 87% rename from tests/codegen/generator-debug.rs rename to tests/codegen/coroutine-debug.rs index 3ec860f2cbc06..b060f3bfac7a5 100644 --- a/tests/codegen/generator-debug.rs +++ b/tests/codegen/coroutine-debug.rs @@ -1,4 +1,4 @@ -// Verify debuginfo for generators: +// Verify debuginfo for coroutines: // - Each variant points to the file and line of its yield point // - The discriminants are marked artificial // - Other fields are not marked artificial @@ -7,10 +7,10 @@ // compile-flags: -C debuginfo=2 --edition=2018 // ignore-msvc -#![feature(generators, generator_trait)] -use std::ops::Generator; +#![feature(coroutines, coroutine_trait)] +use std::ops::Coroutine; -fn generator_test() -> impl Generator { +fn coroutine_test() -> impl Coroutine { || { yield 0; let s = String::from("foo"); @@ -20,8 +20,8 @@ fn generator_test() -> impl Generator { // FIXME: No way to reliably check the filename. -// CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "generator_test" -// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "{generator_env#0}", scope: [[GEN_FN]] +// CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "coroutine_test" +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "{coroutine_env#0}", scope: [[GEN_FN]] // CHECK: [[VARIANT:!.*]] = !DICompositeType(tag: DW_TAG_variant_part, scope: [[GEN]], // CHECK-NOT: flags: DIFlagArtificial // CHECK-SAME: discriminator: [[DISC:![0-9]*]] @@ -58,5 +58,5 @@ fn generator_test() -> impl Generator { // CHECK-SAME: flags: DIFlagArtificial fn main() { - let _dummy = generator_test(); + let _dummy = coroutine_test(); } diff --git a/tests/coverage-map/status-quo/generator.cov-map b/tests/coverage-map/status-quo/coroutine.cov-map similarity index 95% rename from tests/coverage-map/status-quo/generator.cov-map rename to tests/coverage-map/status-quo/coroutine.cov-map index 75704bcc2238a..2f4936d9ab88c 100644 --- a/tests/coverage-map/status-quo/generator.cov-map +++ b/tests/coverage-map/status-quo/coroutine.cov-map @@ -1,4 +1,4 @@ -Function name: generator::get_u32 +Function name: coroutine::get_u32 Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0b, 01, 01, 0b, 05, 01, 0e, 00, 13, 02, 00, 1d, 00, 3c, 07, 01, 01, 00, 02] Number of files: 1 - file 0 => global file 1 @@ -13,7 +13,7 @@ Number of file 0 mappings: 4 - Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) = (c1 + (c0 - c1)) -Function name: generator::main +Function name: coroutine::main Raw bytes (65): 0x[01, 01, 08, 05, 07, 09, 0d, 11, 15, 1e, 19, 11, 15, 15, 19, 1e, 19, 11, 15, 09, 01, 0f, 01, 02, 16, 01, 07, 0b, 00, 2e, 11, 01, 2b, 00, 2d, 03, 01, 0e, 00, 35, 11, 02, 0b, 00, 2e, 1e, 01, 22, 00, 27, 1a, 00, 2c, 00, 2e, 17, 01, 0e, 00, 35, 1a, 02, 01, 00, 02] Number of files: 1 - file 0 => global file 1 @@ -42,7 +42,7 @@ Number of file 0 mappings: 9 - Code(Expression(6, Sub)) at (prev + 2, 1) to (start + 0, 2) = ((c4 - c5) - c6) -Function name: generator::main::{closure#0} +Function name: coroutine::main::{closure#0} Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 1c, 01, 1f, 05, 02, 10, 01, 06] Number of files: 1 - file 0 => global file 1 diff --git a/tests/coverage-map/status-quo/generator.rs b/tests/coverage-map/status-quo/coroutine.rs similarity index 65% rename from tests/coverage-map/status-quo/generator.rs rename to tests/coverage-map/status-quo/coroutine.rs index 4319991021e78..86d19af6f4f08 100644 --- a/tests/coverage-map/status-quo/generator.rs +++ b/tests/coverage-map/status-quo/coroutine.rs @@ -1,11 +1,11 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; // The following implementation of a function called from a `yield` statement // (apparently requiring the Result and the `String` type or constructor) -// creates conditions where the `generator::StateTransform` MIR transform will +// creates conditions where the `coroutine::StateTransform` MIR transform will // drop all `Counter` `Coverage` statements from a MIR. `simplify.rs` has logic // to handle this condition, and still report dead block coverage. fn get_u32(val: bool) -> Result { @@ -14,17 +14,17 @@ fn get_u32(val: bool) -> Result { fn main() { let is_true = std::env::args().len() == 1; - let mut generator = || { + let mut coroutine = || { yield get_u32(is_true); return "foo"; }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(Ok(1)) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(Ok(1)) => {} _ => panic!("unexpected return from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Complete("foo") => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Complete("foo") => {} _ => panic!("unexpected return from resume"), } } diff --git a/tests/coverage-map/status-quo/yield.rs b/tests/coverage-map/status-quo/yield.rs index 361275c921585..b7e2ba31b59c1 100644 --- a/tests/coverage-map/status-quo/yield.rs +++ b/tests/coverage-map/status-quo/yield.rs @@ -1,37 +1,37 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] #![allow(unused_assignments)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn main() { - let mut generator = || { + let mut coroutine = || { yield 1; return "foo"; }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(1) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(1) => {} _ => panic!("unexpected value from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Complete("foo") => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Complete("foo") => {} _ => panic!("unexpected value from resume"), } - let mut generator = || { + let mut coroutine = || { yield 1; yield 2; yield 3; return "foo"; }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(1) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(1) => {} _ => panic!("unexpected value from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(2) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(2) => {} _ => panic!("unexpected value from resume"), } } diff --git a/tests/debuginfo/generator-locals.rs b/tests/debuginfo/coroutine-locals.rs similarity index 95% rename from tests/debuginfo/generator-locals.rs rename to tests/debuginfo/coroutine-locals.rs index fd46c1a8b4db7..e5eb1022ff49b 100644 --- a/tests/debuginfo/generator-locals.rs +++ b/tests/debuginfo/coroutine-locals.rs @@ -54,10 +54,10 @@ // lldbg-check:(int) $7 = 6 // lldbr-check:(int) c = 6 -#![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] +#![feature(omit_gdb_pretty_printer_section, coroutines, coroutine_trait)] #![omit_gdb_pretty_printer_section] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/debuginfo/generator-objects.rs b/tests/debuginfo/coroutine-objects.rs similarity index 67% rename from tests/debuginfo/generator-objects.rs rename to tests/debuginfo/coroutine-objects.rs index 11c4ae2f65929..3e658b2136e78 100644 --- a/tests/debuginfo/generator-objects.rs +++ b/tests/debuginfo/coroutine-objects.rs @@ -2,7 +2,7 @@ // min-gdb-version: 8.2 // LLDB without native Rust support cannot read DW_TAG_variant_part, -// so it prints nothing for generators. But those tests are kept to +// so it prints nothing for coroutines. But those tests are kept to // ensure that LLDB won't crash at least (like #57822). // compile-flags:-g @@ -11,62 +11,62 @@ // gdb-command:run // gdb-command:print b -// gdb-check:$1 = generator_objects::main::{generator_env#0}::Unresumed{_ref__a: 0x[...]} +// gdb-check:$1 = coroutine_objects::main::{coroutine_env#0}::Unresumed{_ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$2 = generator_objects::main::{generator_env#0}::Suspend0{c: 6, d: 7, _ref__a: 0x[...]} +// gdb-check:$2 = coroutine_objects::main::{coroutine_env#0}::Suspend0{c: 6, d: 7, _ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$3 = generator_objects::main::{generator_env#0}::Suspend1{c: 7, d: 8, _ref__a: 0x[...]} +// gdb-check:$3 = coroutine_objects::main::{coroutine_env#0}::Suspend1{c: 7, d: 8, _ref__a: 0x[...]} // gdb-command:continue // gdb-command:print b -// gdb-check:$4 = generator_objects::main::{generator_env#0}::Returned{_ref__a: 0x[...]} +// gdb-check:$4 = coroutine_objects::main::{coroutine_env#0}::Returned{_ref__a: 0x[...]} // === LLDB TESTS ================================================================================== // lldb-command:run // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator_env#0}) $0 = +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $0 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator_env#0}) $1 = +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $1 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator_env#0}) $2 = +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $2 = // lldb-command:continue // lldb-command:print b -// lldbg-check:(generator_objects::main::{generator_env#0}) $3 = +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $3 = // === CDB TESTS =================================================================================== // cdb-command: g // cdb-command: dx b -// cdb-check: b : Unresumed [Type: enum2$] +// cdb-check: b : Unresumed [Type: enum2$] // cdb-check: [+0x[...]] _ref__a : 0x[...] : 5 [Type: int *] // cdb-command: g // cdb-command: dx b -// cdb-check: b : Suspend0 [Type: enum2$] +// cdb-check: b : Suspend0 [Type: enum2$] // cdb-check: [+0x[...]] c : 6 [Type: int] // cdb-check: [+0x[...]] d : 7 [Type: int] // cdb-check: [+0x[...]] _ref__a : 0x[...] : 5 [Type: int *] // cdb-command: g // cdb-command: dx b -// cdb-check: b : Suspend1 [Type: enum2$] +// cdb-check: b : Suspend1 [Type: enum2$] // cdb-check: [+0x[...]] c : 7 [Type: int] // cdb-check: [+0x[...]] d : 8 [Type: int] // cdb-check: [+0x[...]] _ref__a : 0x[...] : 6 [Type: int *] // cdb-command: g // cdb-command: dx b -// cdb-check: b : Returned [Type: enum2$] +// cdb-check: b : Returned [Type: enum2$] // cdb-check: [+0x[...]] _ref__a : 0x[...] : 6 [Type: int *] -#![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] +#![feature(omit_gdb_pretty_printer_section, coroutines, coroutine_trait)] #![omit_gdb_pretty_printer_section] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/debuginfo/function-names.rs b/tests/debuginfo/function-names.rs index d9aa03fee6243..d29b3ea76b700 100644 --- a/tests/debuginfo/function-names.rs +++ b/tests/debuginfo/function-names.rs @@ -31,8 +31,8 @@ // gdb-check:[...]static fn function_names::main::{closure#0}(*mut function_names::main::{closure_env#0}); // gdb-check:[...]static fn function_names::{impl#2}::impl_function::{closure#0}(*mut function_names::{impl#2}::impl_function::{closure_env#0}); -// Generator -// Generators don't seem to appear in GDB's symbol table. +// Coroutine +// Coroutines don't seem to appear in GDB's symbol table. // Const generic parameter // gdb-command:info functions -q function_names::const_generic_fn.* @@ -69,9 +69,9 @@ // cdb-check:[...] a!function_names::main::closure$0 (void) // cdb-check:[...] a!function_names::generic_func::closure$0 (void) -// Generator -// cdb-command:x a!function_names::*::generator* -// cdb-check:[...] a!function_names::main::generator$1 (void) +// Coroutine +// cdb-command:x a!function_names::*::coroutine* +// cdb-check:[...] a!function_names::main::coroutine$1 (void) // Const generic parameter // cdb-command:x a!function_names::const_generic_fn* @@ -83,10 +83,10 @@ #![allow(unused_variables)] #![feature(omit_gdb_pretty_printer_section)] #![omit_gdb_pretty_printer_section] -#![feature(adt_const_params, generators, generator_trait)] +#![feature(adt_const_params, coroutines, coroutine_trait)] #![allow(incomplete_features)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; use Mod1::TestTrait2; @@ -110,12 +110,12 @@ fn main() { let closure = || TestStruct1; closure(); - // Generator - let mut generator = || { + // Coroutine + let mut coroutine = || { yield; return; }; - Pin::new(&mut generator).resume(()); + Pin::new(&mut coroutine).resume(()); // Const generic functions const_generic_fn_bool::(); diff --git a/tests/debuginfo/issue-57822.rs b/tests/debuginfo/issue-57822.rs index 62e7eb13c2dc9..a12a562a033d9 100644 --- a/tests/debuginfo/issue-57822.rs +++ b/tests/debuginfo/issue-57822.rs @@ -1,5 +1,5 @@ // This test makes sure that the LLDB pretty printer does not throw an exception -// for nested closures and generators. +// for nested closures and coroutines. // Require a gdb that can read DW_TAG_variant_part. // min-gdb-version: 8.2 @@ -14,7 +14,7 @@ // gdb-check:$1 = issue_57822::main::{closure_env#1} {f: issue_57822::main::{closure_env#0} {x: 1}} // gdb-command:print b -// gdb-check:$2 = issue_57822::main::{generator_env#3}::Unresumed{a: issue_57822::main::{generator_env#2}::Unresumed{y: 2}} +// gdb-check:$2 = issue_57822::main::{coroutine_env#3}::Unresumed{a: issue_57822::main::{coroutine_env#2}::Unresumed{y: 2}} // === LLDB TESTS ================================================================================== @@ -24,12 +24,12 @@ // lldbg-check:(issue_57822::main::{closure_env#1}) $0 = { f = { x = 1 } } // lldb-command:print b -// lldbg-check:(issue_57822::main::{generator_env#3}) $1 = +// lldbg-check:(issue_57822::main::{coroutine_env#3}) $1 = -#![feature(omit_gdb_pretty_printer_section, generators, generator_trait)] +#![feature(omit_gdb_pretty_printer_section, coroutines, coroutine_trait)] #![omit_gdb_pretty_printer_section] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/mir-opt/building/async_await.a-{closure#0}.generator_resume.0.mir b/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir similarity index 92% rename from tests/mir-opt/building/async_await.a-{closure#0}.generator_resume.0.mir rename to tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir index bc4ca06c11358..8b22743d2b066 100644 --- a/tests/mir-opt/building/async_await.a-{closure#0}.generator_resume.0.mir +++ b/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir @@ -1,5 +1,5 @@ -// MIR for `a::{closure#0}` 0 generator_resume -/* generator_layout = GeneratorLayout { +// MIR for `a::{closure#0}` 0 coroutine_resume +/* coroutine_layout = CoroutineLayout { field_tys: {}, variant_fields: { Unresumed(0): [], diff --git a/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir similarity index 96% rename from tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir rename to tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir index 4a60e353bf276..f64b540c3a5ef 100644 --- a/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir +++ b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir @@ -1,14 +1,14 @@ -// MIR for `b::{closure#0}` 0 generator_resume -/* generator_layout = GeneratorLayout { +// MIR for `b::{closure#0}` 0 coroutine_resume +/* coroutine_layout = CoroutineLayout { field_tys: { - _0: GeneratorSavedTy { - ty: Generator( + _0: CoroutineSavedTy { + ty: Coroutine( DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), [ std::future::ResumeTy, (), (), - GeneratorWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []), + CoroutineWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []), (), ], Static, @@ -19,14 +19,14 @@ }, ignore_for_traits: false, }, - _1: GeneratorSavedTy { - ty: Generator( + _1: CoroutineSavedTy { + ty: Coroutine( DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), [ std::future::ResumeTy, (), (), - GeneratorWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []), + CoroutineWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []), (), ], Static, diff --git a/tests/mir-opt/building/async_await.rs b/tests/mir-opt/building/async_await.rs index 74b15f2b98ffb..abdeafef6e445 100644 --- a/tests/mir-opt/building/async_await.rs +++ b/tests/mir-opt/building/async_await.rs @@ -1,5 +1,5 @@ // skip-filecheck -// This test makes sure that the generator MIR pass eliminates all calls to +// This test makes sure that the coroutine MIR pass eliminates all calls to // `get_context`, and that the MIR argument type for an async fn and all locals // related to `yield` are `&mut Context`, and its return type is `Poll`. @@ -8,10 +8,10 @@ #![crate_type = "lib"] -// EMIT_MIR async_await.a-{closure#0}.generator_resume.0.mir +// EMIT_MIR async_await.a-{closure#0}.coroutine_resume.0.mir async fn a() {} -// EMIT_MIR async_await.b-{closure#0}.generator_resume.0.mir +// EMIT_MIR async_await.b-{closure#0}.coroutine_resume.0.mir pub async fn b() { a().await; a().await diff --git a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir similarity index 84% rename from tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir rename to tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir index 524fbeb0fead7..25bffbe248820 100644 --- a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir +++ b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir @@ -1,10 +1,10 @@ -// MIR for `main::{closure#0}` 0 generator_drop -/* generator_layout = GeneratorLayout { +// MIR for `main::{closure#0}` 0 coroutine_drop +/* coroutine_layout = CoroutineLayout { field_tys: { - _0: GeneratorSavedTy { + _0: CoroutineSavedTy { ty: std::string::String, source_info: SourceInfo { - span: $DIR/generator_drop_cleanup.rs:12:13: 12:15 (#0), + span: $DIR/coroutine_drop_cleanup.rs:12:13: 12:15 (#0), scope: scope[0], }, ignore_for_traits: false, @@ -21,7 +21,7 @@ }, } */ -fn main::{closure#0}(_1: *mut {generator@$DIR/generator_drop_cleanup.rs:11:15: 11:17}) -> () { +fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:11:15: 11:17}) -> () { let mut _0: (); let mut _2: (); let _3: std::string::String; diff --git a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir similarity index 85% rename from tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir rename to tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir index c3f61169bfbb0..2eac754b15ccd 100644 --- a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir +++ b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir @@ -1,10 +1,10 @@ -// MIR for `main::{closure#0}` 0 generator_drop -/* generator_layout = GeneratorLayout { +// MIR for `main::{closure#0}` 0 coroutine_drop +/* coroutine_layout = CoroutineLayout { field_tys: { - _0: GeneratorSavedTy { + _0: CoroutineSavedTy { ty: std::string::String, source_info: SourceInfo { - span: $DIR/generator_drop_cleanup.rs:12:13: 12:15 (#0), + span: $DIR/coroutine_drop_cleanup.rs:12:13: 12:15 (#0), scope: scope[0], }, ignore_for_traits: false, @@ -21,7 +21,7 @@ }, } */ -fn main::{closure#0}(_1: *mut {generator@$DIR/generator_drop_cleanup.rs:11:15: 11:17}) -> () { +fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:11:15: 11:17}) -> () { let mut _0: (); let mut _2: (); let _3: std::string::String; diff --git a/tests/mir-opt/generator_drop_cleanup.rs b/tests/mir-opt/coroutine_drop_cleanup.rs similarity index 53% rename from tests/mir-opt/generator_drop_cleanup.rs rename to tests/mir-opt/coroutine_drop_cleanup.rs index fb67031f774b5..69984c737fed6 100644 --- a/tests/mir-opt/generator_drop_cleanup.rs +++ b/tests/mir-opt/coroutine_drop_cleanup.rs @@ -1,12 +1,12 @@ // skip-filecheck -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// Regression test for #58892, generator drop shims should not have blocks +// Regression test for #58892, coroutine drop shims should not have blocks // spuriously marked as cleanup -// EMIT_MIR generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir +// EMIT_MIR coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.mir fn main() { let gen = || { let _s = String::new(); diff --git a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir similarity index 94% rename from tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir rename to tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir index 169d817675e20..8369a3e60dd9a 100644 --- a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir +++ b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir @@ -1,6 +1,6 @@ // MIR for `main::{closure#0}` before StateTransform -fn main::{closure#0}(_1: {generator@$DIR/generator_storage_dead_unwind.rs:23:16: 23:18}, _2: ()) -> () +fn main::{closure#0}(_1: {coroutine@$DIR/coroutine_storage_dead_unwind.rs:23:16: 23:18}, _2: ()) -> () yields () { let mut _0: (); @@ -78,6 +78,6 @@ yields () } bb8: { - generator_drop; + coroutine_drop; } } diff --git a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir similarity index 96% rename from tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir rename to tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir index 45e9c01b931af..1773db1abffe3 100644 --- a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir +++ b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir @@ -1,6 +1,6 @@ // MIR for `main::{closure#0}` before StateTransform -fn main::{closure#0}(_1: {generator@$DIR/generator_storage_dead_unwind.rs:23:16: 23:18}, _2: ()) -> () +fn main::{closure#0}(_1: {coroutine@$DIR/coroutine_storage_dead_unwind.rs:23:16: 23:18}, _2: ()) -> () yields () { let mut _0: (); @@ -78,7 +78,7 @@ yields () } bb8: { - generator_drop; + coroutine_drop; } bb9 (cleanup): { diff --git a/tests/mir-opt/generator_storage_dead_unwind.rs b/tests/mir-opt/coroutine_storage_dead_unwind.rs similarity index 71% rename from tests/mir-opt/generator_storage_dead_unwind.rs rename to tests/mir-opt/coroutine_storage_dead_unwind.rs index 91f3a20befd18..253be1ff698d1 100644 --- a/tests/mir-opt/generator_storage_dead_unwind.rs +++ b/tests/mir-opt/coroutine_storage_dead_unwind.rs @@ -1,12 +1,12 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// Test that we generate StorageDead on unwind paths for generators. +// Test that we generate StorageDead on unwind paths for coroutines. // // Basic block and local names can safely change, but the StorageDead statements // should not go away. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] struct Foo(i32); @@ -18,7 +18,7 @@ struct Bar(i32); fn take(_x: T) {} -// EMIT_MIR generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.mir +// EMIT_MIR coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.mir fn main() { let _gen = || { let a = Foo(5); diff --git a/tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir b/tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir similarity index 67% rename from tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir rename to tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir index 7047a5baae586..17b99c87c3986 100644 --- a/tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir +++ b/tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir @@ -1,10 +1,10 @@ -// MIR for `main::{closure#0}` 0 generator_resume -/* generator_layout = GeneratorLayout { +// MIR for `main::{closure#0}` 0 coroutine_resume +/* coroutine_layout = CoroutineLayout { field_tys: { - _0: GeneratorSavedTy { + _0: CoroutineSavedTy { ty: HasDrop, source_info: SourceInfo { - span: $DIR/generator_tiny.rs:21:13: 21:15 (#0), + span: $DIR/coroutine_tiny.rs:21:13: 21:15 (#0), scope: scope[0], }, ignore_for_traits: false, @@ -21,9 +21,9 @@ }, } */ -fn main::{closure#0}(_1: Pin<&mut {generator@$DIR/generator_tiny.rs:20:16: 20:24}>, _2: u8) -> GeneratorState<(), ()> { +fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine_tiny.rs:20:16: 20:24}>, _2: u8) -> CoroutineState<(), ()> { debug _x => _10; - let mut _0: std::ops::GeneratorState<(), ()>; + let mut _0: std::ops::CoroutineState<(), ()>; let _3: HasDrop; let mut _4: !; let mut _5: (); @@ -34,18 +34,18 @@ fn main::{closure#0}(_1: Pin<&mut {generator@$DIR/generator_tiny.rs:20:16: 20:24 let _10: u8; let mut _11: u32; scope 1 { - debug _d => (((*(_1.0: &mut {generator@$DIR/generator_tiny.rs:20:16: 20:24})) as variant#3).0: HasDrop); + debug _d => (((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:20:16: 20:24})) as variant#3).0: HasDrop); } bb0: { - _11 = discriminant((*(_1.0: &mut {generator@$DIR/generator_tiny.rs:20:16: 20:24}))); + _11 = discriminant((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:20:16: 20:24}))); switchInt(move _11) -> [0: bb1, 3: bb5, otherwise: bb6]; } bb1: { _10 = move _2; nop; - (((*(_1.0: &mut {generator@$DIR/generator_tiny.rs:20:16: 20:24})) as variant#3).0: HasDrop) = HasDrop; + (((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:20:16: 20:24})) as variant#3).0: HasDrop) = HasDrop; StorageLive(_4); goto -> bb2; } @@ -54,8 +54,8 @@ fn main::{closure#0}(_1: Pin<&mut {generator@$DIR/generator_tiny.rs:20:16: 20:24 StorageLive(_6); StorageLive(_7); _7 = (); - _0 = GeneratorState::<(), ()>::Yielded(move _7); - discriminant((*(_1.0: &mut {generator@$DIR/generator_tiny.rs:20:16: 20:24}))) = 3; + _0 = CoroutineState::<(), ()>::Yielded(move _7); + discriminant((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:20:16: 20:24}))) = 3; return; } diff --git a/tests/mir-opt/generator_tiny.rs b/tests/mir-opt/coroutine_tiny.rs similarity index 66% rename from tests/mir-opt/generator_tiny.rs rename to tests/mir-opt/coroutine_tiny.rs index e5570d74bbb4f..0fd785b28f876 100644 --- a/tests/mir-opt/generator_tiny.rs +++ b/tests/mir-opt/coroutine_tiny.rs @@ -1,11 +1,11 @@ // skip-filecheck -//! Tests that generators that cannot return or unwind don't have unnecessary +//! Tests that coroutines that cannot return or unwind don't have unnecessary //! panic branches. // compile-flags: -C panic=abort // no-prefer-dynamic -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] struct HasDrop; @@ -15,7 +15,7 @@ impl Drop for HasDrop { fn callee() {} -// EMIT_MIR generator_tiny.main-{closure#0}.generator_resume.0.mir +// EMIT_MIR coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir fn main() { let _gen = |_x: u8| { let _d = HasDrop; diff --git a/tests/mir-opt/inline/inline_async.rs b/tests/mir-opt/inline/inline_async.rs index 932dc5635f0d7..1de87e1e43cf6 100644 --- a/tests/mir-opt/inline/inline_async.rs +++ b/tests/mir-opt/inline/inline_async.rs @@ -1,5 +1,5 @@ // skip-filecheck -// Checks that inliner doesn't introduce cycles when optimizing generators. +// Checks that inliner doesn't introduce cycles when optimizing coroutines. // The outcome of optimization is not verfied, just the absence of the cycle. // Regression test for #76181. // diff --git a/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff similarity index 67% rename from tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff rename to tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff index 48d908fad8890..357d95f7c22d9 100644 --- a/tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff @@ -3,27 +3,27 @@ fn main() -> () { let mut _0: (); - let _1: std::ops::GeneratorState; - let mut _2: std::pin::Pin<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>; - let mut _3: &mut {generator@$DIR/inline_generator.rs:17:5: 17:8}; - let mut _4: {generator@$DIR/inline_generator.rs:17:5: 17:8}; + let _1: std::ops::CoroutineState; + let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>; + let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}; + let mut _4: {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}; + let mut _5: bool; scope 1 { debug _r => _1; } + scope 2 (inlined g) { + } -+ scope 3 (inlined Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>::new) { ++ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new) { + debug pointer => _3; + scope 4 { -+ scope 5 (inlined Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>::new_unchecked) { ++ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new_unchecked) { + debug pointer => _3; + } + } + } + scope 6 (inlined g::{closure#0}) { + debug a => _5; -+ let mut _6: &mut {generator@$DIR/inline_generator.rs:17:5: 17:8}; ++ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}; + let mut _7: u32; + let mut _8: i32; + } @@ -34,22 +34,22 @@ StorageLive(_3); StorageLive(_4); - _4 = g() -> [return: bb1, unwind unreachable]; -+ _4 = {generator@$DIR/inline_generator.rs:17:5: 17:8 (#0)}; ++ _4 = {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8 (#0)}; + _3 = &mut _4; -+ _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}> { pointer: move _3 }; ++ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}> { pointer: move _3 }; + StorageDead(_3); + StorageLive(_5); + _5 = const false; + StorageLive(_6); + StorageLive(_7); -+ _6 = (_2.0: &mut {generator@$DIR/inline_generator.rs:17:5: 17:8}); ++ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}); + _7 = discriminant((*_6)); + switchInt(move _7) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9]; } bb1: { - _3 = &mut _4; -- _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind unreachable]; +- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind unreachable]; + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); @@ -59,7 +59,7 @@ bb2: { - StorageDead(_3); -- _1 = <{generator@$DIR/inline_generator.rs:17:5: 17:8} as Generator>::resume(move _2, const false) -> [return: bb3, unwind unreachable]; +- _1 = <{coroutine@$DIR/inline_coroutine.rs:17:5: 17:8} as Coroutine>::resume(move _2, const false) -> [return: bb3, unwind unreachable]; + StorageDead(_4); + _0 = const (); + StorageDead(_1); @@ -88,19 +88,19 @@ + } + + bb6: { -+ _1 = GeneratorState::::Yielded(move _8); ++ _1 = CoroutineState::::Yielded(move _8); + discriminant((*_6)) = 3; + goto -> bb1; + } + + bb7: { -+ assert(const false, "generator resumed after completion") -> [success: bb7, unwind unreachable]; ++ assert(const false, "coroutine resumed after completion") -> [success: bb7, unwind unreachable]; + } + + bb8: { + StorageLive(_8); + StorageDead(_8); -+ _1 = GeneratorState::::Complete(_5); ++ _1 = CoroutineState::::Complete(_5); + discriminant((*_6)) = 1; + goto -> bb1; + } diff --git a/tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff similarity index 68% rename from tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff rename to tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff index 9cb84b314de94..e7d020968389f 100644 --- a/tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff @@ -3,27 +3,27 @@ fn main() -> () { let mut _0: (); - let _1: std::ops::GeneratorState; - let mut _2: std::pin::Pin<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>; - let mut _3: &mut {generator@$DIR/inline_generator.rs:17:5: 17:8}; - let mut _4: {generator@$DIR/inline_generator.rs:17:5: 17:8}; + let _1: std::ops::CoroutineState; + let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>; + let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}; + let mut _4: {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}; + let mut _5: bool; scope 1 { debug _r => _1; } + scope 2 (inlined g) { + } -+ scope 3 (inlined Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>::new) { ++ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new) { + debug pointer => _3; + scope 4 { -+ scope 5 (inlined Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>::new_unchecked) { ++ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new_unchecked) { + debug pointer => _3; + } + } + } + scope 6 (inlined g::{closure#0}) { + debug a => _5; -+ let mut _6: &mut {generator@$DIR/inline_generator.rs:17:5: 17:8}; ++ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}; + let mut _7: u32; + let mut _8: i32; + } @@ -37,20 +37,20 @@ - } - - bb1: { -+ _4 = {generator@$DIR/inline_generator.rs:17:5: 17:8 (#0)}; ++ _4 = {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8 (#0)}; _3 = &mut _4; -- _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind: bb5]; +- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind: bb5]; - } - - bb2: { -+ _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:17:5: 17:8}> { pointer: move _3 }; ++ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}> { pointer: move _3 }; StorageDead(_3); -- _1 = <{generator@$DIR/inline_generator.rs:17:5: 17:8} as Generator>::resume(move _2, const false) -> [return: bb3, unwind: bb5]; +- _1 = <{coroutine@$DIR/inline_coroutine.rs:17:5: 17:8} as Coroutine>::resume(move _2, const false) -> [return: bb3, unwind: bb5]; + StorageLive(_5); + _5 = const false; + StorageLive(_6); + StorageLive(_7); -+ _6 = (_2.0: &mut {generator@$DIR/inline_generator.rs:17:5: 17:8}); ++ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}); + _7 = discriminant((*_6)); + switchInt(move _7) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11]; } @@ -100,19 +100,19 @@ + } + + bb8: { -+ _1 = GeneratorState::::Yielded(move _8); ++ _1 = CoroutineState::::Yielded(move _8); + discriminant((*_6)) = 3; + goto -> bb1; + } + + bb9: { -+ assert(const false, "generator resumed after completion") -> [success: bb9, unwind: bb3]; ++ assert(const false, "coroutine resumed after completion") -> [success: bb9, unwind: bb3]; + } + + bb10: { + StorageLive(_8); + StorageDead(_8); -+ _1 = GeneratorState::::Complete(_5); ++ _1 = CoroutineState::::Complete(_5); + discriminant((*_6)) = 1; + goto -> bb1; + } diff --git a/tests/mir-opt/inline/inline_generator.rs b/tests/mir-opt/inline/inline_coroutine.rs similarity index 63% rename from tests/mir-opt/inline/inline_generator.rs rename to tests/mir-opt/inline/inline_coroutine.rs index d96d1f98f149e..d021cdac28efa 100644 --- a/tests/mir-opt/inline/inline_generator.rs +++ b/tests/mir-opt/inline/inline_coroutine.rs @@ -1,18 +1,18 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // compile-flags: -Zinline-mir-hint-threshold=1000 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; -// EMIT_MIR inline_generator.main.Inline.diff +// EMIT_MIR inline_coroutine.main.Inline.diff fn main() { let _r = Pin::new(&mut g()).resume(false); } #[inline] -pub fn g() -> impl Generator { +pub fn g() -> impl Coroutine { #[inline] |a| { yield if a { 7 } else { 13 } } } diff --git a/tests/run-coverage/generator.coverage b/tests/run-coverage/coroutine.coverage similarity index 69% rename from tests/run-coverage/generator.coverage rename to tests/run-coverage/coroutine.coverage index daba2bea8b866..3a9791a0dbd8e 100644 --- a/tests/run-coverage/generator.coverage +++ b/tests/run-coverage/coroutine.coverage @@ -1,11 +1,11 @@ - LL| |#![feature(generators, generator_trait)] + LL| |#![feature(coroutines, coroutine_trait)] LL| | - LL| |use std::ops::{Generator, GeneratorState}; + LL| |use std::ops::{Coroutine, CoroutineState}; LL| |use std::pin::Pin; LL| | LL| |// The following implementation of a function called from a `yield` statement LL| |// (apparently requiring the Result and the `String` type or constructor) - LL| |// creates conditions where the `generator::StateTransform` MIR transform will + LL| |// creates conditions where the `coroutine::StateTransform` MIR transform will LL| |// drop all `Counter` `Coverage` statements from a MIR. `simplify.rs` has logic LL| |// to handle this condition, and still report dead block coverage. LL| 1|fn get_u32(val: bool) -> Result { @@ -15,17 +15,17 @@ LL| | LL| 1|fn main() { LL| 1| let is_true = std::env::args().len() == 1; - LL| 1| let mut generator = || { + LL| 1| let mut coroutine = || { LL| 1| yield get_u32(is_true); LL| 1| return "foo"; LL| 1| }; LL| | - LL| 1| match Pin::new(&mut generator).resume(()) { - LL| 1| GeneratorState::Yielded(Ok(1)) => {} + LL| 1| match Pin::new(&mut coroutine).resume(()) { + LL| 1| CoroutineState::Yielded(Ok(1)) => {} LL| 0| _ => panic!("unexpected return from resume"), LL| | } - LL| 1| match Pin::new(&mut generator).resume(()) { - LL| 1| GeneratorState::Complete("foo") => {} + LL| 1| match Pin::new(&mut coroutine).resume(()) { + LL| 1| CoroutineState::Complete("foo") => {} LL| 0| _ => panic!("unexpected return from resume"), LL| | } LL| 1|} diff --git a/tests/run-coverage/generator.rs b/tests/run-coverage/coroutine.rs similarity index 65% rename from tests/run-coverage/generator.rs rename to tests/run-coverage/coroutine.rs index 4319991021e78..86d19af6f4f08 100644 --- a/tests/run-coverage/generator.rs +++ b/tests/run-coverage/coroutine.rs @@ -1,11 +1,11 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; // The following implementation of a function called from a `yield` statement // (apparently requiring the Result and the `String` type or constructor) -// creates conditions where the `generator::StateTransform` MIR transform will +// creates conditions where the `coroutine::StateTransform` MIR transform will // drop all `Counter` `Coverage` statements from a MIR. `simplify.rs` has logic // to handle this condition, and still report dead block coverage. fn get_u32(val: bool) -> Result { @@ -14,17 +14,17 @@ fn get_u32(val: bool) -> Result { fn main() { let is_true = std::env::args().len() == 1; - let mut generator = || { + let mut coroutine = || { yield get_u32(is_true); return "foo"; }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(Ok(1)) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(Ok(1)) => {} _ => panic!("unexpected return from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Complete("foo") => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Complete("foo") => {} _ => panic!("unexpected return from resume"), } } diff --git a/tests/run-coverage/yield.coverage b/tests/run-coverage/yield.coverage index 90c2641a7d661..d7e455f211e45 100644 --- a/tests/run-coverage/yield.coverage +++ b/tests/run-coverage/yield.coverage @@ -1,37 +1,37 @@ - LL| |#![feature(generators, generator_trait)] + LL| |#![feature(coroutines, coroutine_trait)] LL| |#![allow(unused_assignments)] LL| | - LL| |use std::ops::{Generator, GeneratorState}; + LL| |use std::ops::{Coroutine, CoroutineState}; LL| |use std::pin::Pin; LL| | LL| 1|fn main() { - LL| 1| let mut generator = || { + LL| 1| let mut coroutine = || { LL| 1| yield 1; LL| 1| return "foo"; LL| 1| }; LL| | - LL| 1| match Pin::new(&mut generator).resume(()) { - LL| 1| GeneratorState::Yielded(1) => {} + LL| 1| match Pin::new(&mut coroutine).resume(()) { + LL| 1| CoroutineState::Yielded(1) => {} LL| 0| _ => panic!("unexpected value from resume"), LL| | } - LL| 1| match Pin::new(&mut generator).resume(()) { - LL| 1| GeneratorState::Complete("foo") => {} + LL| 1| match Pin::new(&mut coroutine).resume(()) { + LL| 1| CoroutineState::Complete("foo") => {} LL| 0| _ => panic!("unexpected value from resume"), LL| | } LL| | - LL| 1| let mut generator = || { + LL| 1| let mut coroutine = || { LL| 1| yield 1; LL| 1| yield 2; LL| 0| yield 3; LL| 0| return "foo"; LL| 0| }; LL| | - LL| 1| match Pin::new(&mut generator).resume(()) { - LL| 1| GeneratorState::Yielded(1) => {} + LL| 1| match Pin::new(&mut coroutine).resume(()) { + LL| 1| CoroutineState::Yielded(1) => {} LL| 0| _ => panic!("unexpected value from resume"), LL| | } - LL| 1| match Pin::new(&mut generator).resume(()) { - LL| 1| GeneratorState::Yielded(2) => {} + LL| 1| match Pin::new(&mut coroutine).resume(()) { + LL| 1| CoroutineState::Yielded(2) => {} LL| 0| _ => panic!("unexpected value from resume"), LL| | } LL| 1|} diff --git a/tests/run-coverage/yield.rs b/tests/run-coverage/yield.rs index 361275c921585..b7e2ba31b59c1 100644 --- a/tests/run-coverage/yield.rs +++ b/tests/run-coverage/yield.rs @@ -1,37 +1,37 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] #![allow(unused_assignments)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn main() { - let mut generator = || { + let mut coroutine = || { yield 1; return "foo"; }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(1) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(1) => {} _ => panic!("unexpected value from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Complete("foo") => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Complete("foo") => {} _ => panic!("unexpected value from resume"), } - let mut generator = || { + let mut coroutine = || { yield 1; yield 2; yield 3; return "foo"; }; - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(1) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(1) => {} _ => panic!("unexpected value from resume"), } - match Pin::new(&mut generator).resume(()) { - GeneratorState::Yielded(2) => {} + match Pin::new(&mut coroutine).resume(()) { + CoroutineState::Yielded(2) => {} _ => panic!("unexpected value from resume"), } } diff --git a/tests/rustdoc-ui/error-in-impl-trait/closure.rs b/tests/rustdoc-ui/error-in-impl-trait/closure.rs index f1fd85bb23cb6..628c61a6a1a8b 100644 --- a/tests/rustdoc-ui/error-in-impl-trait/closure.rs +++ b/tests/rustdoc-ui/error-in-impl-trait/closure.rs @@ -1,5 +1,5 @@ // check-pass -// manually desugared version of an `async fn` (but with a closure instead of a generator) +// manually desugared version of an `async fn` (but with a closure instead of a coroutine) pub fn a() -> impl Fn() -> u32 { || content::doesnt::matter() } diff --git a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs index 3f7429a5fccf8..ae7f341fe4e33 100644 --- a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs +++ b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs @@ -29,8 +29,8 @@ fn main() { TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::` - TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::` - TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Coroutine(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::CoroutineWitness(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Never => (), //~ ERROR usage of `ty::TyKind::` TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Alias(..) => (), //~ ERROR usage of `ty::TyKind::` diff --git a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr index 1f49d6b64646f..45b7c26faad07 100644 --- a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr +++ b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr @@ -109,13 +109,13 @@ LL | TyKind::Closure(..) => (), error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:32:9 | -LL | TyKind::Generator(..) => (), +LL | TyKind::Coroutine(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:33:9 | -LL | TyKind::GeneratorWitness(..) => (), +LL | TyKind::CoroutineWitness(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` diff --git a/tests/ui/async-await/generator-desc.rs b/tests/ui/async-await/coroutine-desc.rs similarity index 100% rename from tests/ui/async-await/generator-desc.rs rename to tests/ui/async-await/coroutine-desc.rs diff --git a/tests/ui/async-await/generator-desc.stderr b/tests/ui/async-await/coroutine-desc.stderr similarity index 79% rename from tests/ui/async-await/generator-desc.stderr rename to tests/ui/async-await/coroutine-desc.stderr index d3e951cfe49f5..e4cb0915a1090 100644 --- a/tests/ui/async-await/generator-desc.stderr +++ b/tests/ui/async-await/coroutine-desc.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/generator-desc.rs:10:19 + --> $DIR/coroutine-desc.rs:10:19 | LL | fun(async {}, async {}); | --- -------- ^^^^^^^^ expected `async` block, found a different `async` block @@ -7,16 +7,16 @@ LL | fun(async {}, async {}); | | the expected `async` block | arguments to this function are incorrect | - = note: expected `async` block `{async block@$DIR/generator-desc.rs:10:9: 10:17}` - found `async` block `{async block@$DIR/generator-desc.rs:10:19: 10:27}` + = note: expected `async` block `{async block@$DIR/coroutine-desc.rs:10:9: 10:17}` + found `async` block `{async block@$DIR/coroutine-desc.rs:10:19: 10:27}` note: function defined here - --> $DIR/generator-desc.rs:8:4 + --> $DIR/coroutine-desc.rs:8:4 | LL | fn fun>(f1: F, f2: F) {} | ^^^ ----- error[E0308]: mismatched types - --> $DIR/generator-desc.rs:12:16 + --> $DIR/coroutine-desc.rs:12:16 | LL | fun(one(), two()); | --- ^^^^^ expected future, found a different future @@ -26,13 +26,13 @@ LL | fun(one(), two()); = help: consider `await`ing on both `Future`s = note: distinct uses of `impl Trait` result in different opaque types note: function defined here - --> $DIR/generator-desc.rs:8:4 + --> $DIR/coroutine-desc.rs:8:4 | LL | fn fun>(f1: F, f2: F) {} | ^^^ ----- error[E0308]: mismatched types - --> $DIR/generator-desc.rs:14:26 + --> $DIR/coroutine-desc.rs:14:26 | LL | fun((async || {})(), (async || {})()); | --- -- ^^^^^^^^^^^^^^^ expected `async` closure body, found a different `async` closure body @@ -40,10 +40,10 @@ LL | fun((async || {})(), (async || {})()); | | the expected `async` closure body | arguments to this function are incorrect | - = note: expected `async` closure body `{async closure body@$DIR/generator-desc.rs:14:19: 14:21}` - found `async` closure body `{async closure body@$DIR/generator-desc.rs:14:36: 14:38}` + = note: expected `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:19: 14:21}` + found `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:36: 14:38}` note: function defined here - --> $DIR/generator-desc.rs:8:4 + --> $DIR/coroutine-desc.rs:8:4 | LL | fn fun>(f1: F, f2: F) {} | ^^^ ----- diff --git a/tests/ui/async-await/generator-not-future.rs b/tests/ui/async-await/coroutine-not-future.rs similarity index 57% rename from tests/ui/async-await/generator-not-future.rs rename to tests/ui/async-await/coroutine-not-future.rs index 37d7cfa6fb7a3..b18635fea3974 100644 --- a/tests/ui/async-await/generator-not-future.rs +++ b/tests/ui/async-await/coroutine-not-future.rs @@ -1,42 +1,42 @@ // edition:2018 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::future::Future; -use std::ops::Generator; +use std::ops::Coroutine; async fn async_fn() {} fn returns_async_block() -> impl Future { async {} } -fn returns_generator() -> impl Generator<(), Yield = (), Return = ()> { +fn returns_coroutine() -> impl Coroutine<(), Yield = (), Return = ()> { || { let _: () = yield (); } } fn takes_future(_f: impl Future) {} -fn takes_generator(_g: impl Generator) {} +fn takes_coroutine(_g: impl Coroutine) {} fn main() { // okay: takes_future(async_fn()); takes_future(returns_async_block()); takes_future(async {}); - takes_generator(returns_generator()); - takes_generator(|| { + takes_coroutine(returns_coroutine()); + takes_coroutine(|| { let _: () = yield (); }); - // async futures are not generators: - takes_generator(async_fn()); + // async futures are not coroutines: + takes_coroutine(async_fn()); //~^ ERROR the trait bound - takes_generator(returns_async_block()); + takes_coroutine(returns_async_block()); //~^ ERROR the trait bound - takes_generator(async {}); + takes_coroutine(async {}); //~^ ERROR the trait bound - // generators are not futures: - takes_future(returns_generator()); + // coroutines are not futures: + takes_future(returns_coroutine()); //~^ ERROR is not a future takes_future(|ctx| { //~^ ERROR is not a future diff --git a/tests/ui/async-await/coroutine-not-future.stderr b/tests/ui/async-await/coroutine-not-future.stderr new file mode 100644 index 0000000000000..130c5ef526b39 --- /dev/null +++ b/tests/ui/async-await/coroutine-not-future.stderr @@ -0,0 +1,81 @@ +error[E0277]: the trait bound `impl Future: Coroutine<_>` is not satisfied + --> $DIR/coroutine-not-future.rs:31:21 + | +LL | takes_coroutine(async_fn()); + | --------------- ^^^^^^^^^^ the trait `Coroutine<_>` is not implemented for `impl Future` + | | + | required by a bound introduced by this call + | +note: required by a bound in `takes_coroutine` + --> $DIR/coroutine-not-future.rs:18:39 + | +LL | fn takes_coroutine(_g: impl Coroutine) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_coroutine` + +error[E0277]: the trait bound `impl Future: Coroutine<_>` is not satisfied + --> $DIR/coroutine-not-future.rs:33:21 + | +LL | takes_coroutine(returns_async_block()); + | --------------- ^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine<_>` is not implemented for `impl Future` + | | + | required by a bound introduced by this call + | +note: required by a bound in `takes_coroutine` + --> $DIR/coroutine-not-future.rs:18:39 + | +LL | fn takes_coroutine(_g: impl Coroutine) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_coroutine` + +error[E0277]: the trait bound `{async block@$DIR/coroutine-not-future.rs:35:21: 35:29}: Coroutine<_>` is not satisfied + --> $DIR/coroutine-not-future.rs:35:21 + | +LL | takes_coroutine(async {}); + | --------------- ^^^^^^^^ the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:35:21: 35:29}` + | | + | required by a bound introduced by this call + | +note: required by a bound in `takes_coroutine` + --> $DIR/coroutine-not-future.rs:18:39 + | +LL | fn takes_coroutine(_g: impl Coroutine) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_coroutine` + +error[E0277]: `impl Coroutine` is not a future + --> $DIR/coroutine-not-future.rs:39:18 + | +LL | takes_future(returns_coroutine()); + | ------------ ^^^^^^^^^^^^^^^^^^^ `impl Coroutine` is not a future + | | + | required by a bound introduced by this call + | + = help: the trait `Future` is not implemented for `impl Coroutine` + = note: impl Coroutine must be a future or must implement `IntoFuture` to be awaited +note: required by a bound in `takes_future` + --> $DIR/coroutine-not-future.rs:17:26 + | +LL | fn takes_future(_f: impl Future) {} + | ^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_future` + +error[E0277]: `{coroutine@$DIR/coroutine-not-future.rs:41:18: 41:23}` is not a future + --> $DIR/coroutine-not-future.rs:41:18 + | +LL | takes_future(|ctx| { + | _____------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | ctx = yield (); +LL | | }); + | |_____^ `{coroutine@$DIR/coroutine-not-future.rs:41:18: 41:23}` is not a future + | + = help: the trait `Future` is not implemented for `{coroutine@$DIR/coroutine-not-future.rs:41:18: 41:23}` + = note: {coroutine@$DIR/coroutine-not-future.rs:41:18: 41:23} must be a future or must implement `IntoFuture` to be awaited +note: required by a bound in `takes_future` + --> $DIR/coroutine-not-future.rs:17:26 + | +LL | fn takes_future(_f: impl Future) {} + | ^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_future` + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout b/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout index d63911b0d3c19..b0447a5826119 100644 --- a/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout +++ b/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout @@ -19,18 +19,18 @@ print-type-size variant `Suspend0`: 2052 bytes print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes print-type-size padding: 1 bytes print-type-size local `.fut`: 1025 bytes, alignment: 1 bytes -print-type-size local `..generator_field4`: 1 bytes +print-type-size local `..coroutine_field4`: 1 bytes print-type-size local `.__awaitee`: 1 bytes print-type-size variant `Suspend1`: 3076 bytes print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes print-type-size padding: 1026 bytes -print-type-size local `..generator_field4`: 1 bytes, alignment: 1 bytes +print-type-size local `..coroutine_field4`: 1 bytes, alignment: 1 bytes print-type-size local `.__awaitee`: 1025 bytes print-type-size variant `Suspend2`: 2052 bytes print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes print-type-size padding: 1 bytes print-type-size local `.fut`: 1025 bytes, alignment: 1 bytes -print-type-size local `..generator_field4`: 1 bytes +print-type-size local `..coroutine_field4`: 1 bytes print-type-size local `.__awaitee`: 1 bytes print-type-size variant `Returned`: 1025 bytes print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes diff --git a/tests/ui/async-await/generator-not-future.stderr b/tests/ui/async-await/generator-not-future.stderr deleted file mode 100644 index 540501b982668..0000000000000 --- a/tests/ui/async-await/generator-not-future.stderr +++ /dev/null @@ -1,81 +0,0 @@ -error[E0277]: the trait bound `impl Future: Generator<_>` is not satisfied - --> $DIR/generator-not-future.rs:31:21 - | -LL | takes_generator(async_fn()); - | --------------- ^^^^^^^^^^ the trait `Generator<_>` is not implemented for `impl Future` - | | - | required by a bound introduced by this call - | -note: required by a bound in `takes_generator` - --> $DIR/generator-not-future.rs:18:39 - | -LL | fn takes_generator(_g: impl Generator) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_generator` - -error[E0277]: the trait bound `impl Future: Generator<_>` is not satisfied - --> $DIR/generator-not-future.rs:33:21 - | -LL | takes_generator(returns_async_block()); - | --------------- ^^^^^^^^^^^^^^^^^^^^^ the trait `Generator<_>` is not implemented for `impl Future` - | | - | required by a bound introduced by this call - | -note: required by a bound in `takes_generator` - --> $DIR/generator-not-future.rs:18:39 - | -LL | fn takes_generator(_g: impl Generator) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_generator` - -error[E0277]: the trait bound `{async block@$DIR/generator-not-future.rs:35:21: 35:29}: Generator<_>` is not satisfied - --> $DIR/generator-not-future.rs:35:21 - | -LL | takes_generator(async {}); - | --------------- ^^^^^^^^ the trait `Generator<_>` is not implemented for `{async block@$DIR/generator-not-future.rs:35:21: 35:29}` - | | - | required by a bound introduced by this call - | -note: required by a bound in `takes_generator` - --> $DIR/generator-not-future.rs:18:39 - | -LL | fn takes_generator(_g: impl Generator) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_generator` - -error[E0277]: `impl Generator` is not a future - --> $DIR/generator-not-future.rs:39:18 - | -LL | takes_future(returns_generator()); - | ------------ ^^^^^^^^^^^^^^^^^^^ `impl Generator` is not a future - | | - | required by a bound introduced by this call - | - = help: the trait `Future` is not implemented for `impl Generator` - = note: impl Generator must be a future or must implement `IntoFuture` to be awaited -note: required by a bound in `takes_future` - --> $DIR/generator-not-future.rs:17:26 - | -LL | fn takes_future(_f: impl Future) {} - | ^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_future` - -error[E0277]: `{generator@$DIR/generator-not-future.rs:41:18: 41:23}` is not a future - --> $DIR/generator-not-future.rs:41:18 - | -LL | takes_future(|ctx| { - | _____------------_^ - | | | - | | required by a bound introduced by this call -LL | | -LL | | ctx = yield (); -LL | | }); - | |_____^ `{generator@$DIR/generator-not-future.rs:41:18: 41:23}` is not a future - | - = help: the trait `Future` is not implemented for `{generator@$DIR/generator-not-future.rs:41:18: 41:23}` - = note: {generator@$DIR/generator-not-future.rs:41:18: 41:23} must be a future or must implement `IntoFuture` to be awaited -note: required by a bound in `takes_future` - --> $DIR/generator-not-future.rs:17:26 - | -LL | fn takes_future(_f: impl Future) {} - | ^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_future` - -error: aborting due to 5 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/async-await/issue-60709.rs b/tests/ui/async-await/issue-60709.rs index 61f6ed1b7b2ce..2cda40e9e11ba 100644 --- a/tests/ui/async-await/issue-60709.rs +++ b/tests/ui/async-await/issue-60709.rs @@ -1,5 +1,5 @@ // This used to compile the future down to ud2, due to uninhabited types being -// handled incorrectly in generators. +// handled incorrectly in coroutines. // compile-flags: -Copt-level=z -Cdebuginfo=2 --edition=2018 // run-pass diff --git a/tests/ui/async-await/issue-61793.rs b/tests/ui/async-await/issue-61793.rs index 9180e1d811aa3..bb861cf60b114 100644 --- a/tests/ui/async-await/issue-61793.rs +++ b/tests/ui/async-await/issue-61793.rs @@ -1,5 +1,5 @@ // This testcase used to ICE in codegen due to inconsistent field reordering -// in the generator state, claiming a ZST field was after a non-ZST field, +// in the coroutine state, claiming a ZST field was after a non-ZST field, // while those two fields were at the same offset (which is impossible). // That is, memory ordering of `(X, ())`, but offsets of `((), X)`. diff --git a/tests/ui/async-await/issue-62658.rs b/tests/ui/async-await/issue-62658.rs index d0af01e0c009f..8e6d070ea3f6f 100644 --- a/tests/ui/async-await/issue-62658.rs +++ b/tests/ui/async-await/issue-62658.rs @@ -1,4 +1,4 @@ -// This test created a generator whose size was not rounded to a multiple of its +// This test created a coroutine whose size was not rounded to a multiple of its // alignment. This caused an assertion error in codegen. // build-pass diff --git a/tests/ui/async-await/issue-73137.rs b/tests/ui/async-await/issue-73137.rs index c43ce2cadba04..2d16f19364457 100644 --- a/tests/ui/async-await/issue-73137.rs +++ b/tests/ui/async-await/issue-73137.rs @@ -28,7 +28,7 @@ fn main() { a: async { 0 }.await, }; - // An error in the generator transform caused `b` to be overwritten with `a` when `b` was + // An error in the coroutine transform caused `b` to be overwritten with `a` when `b` was // borrowed. nop(&action.b); assert_ne!(0usize, unsafe { std::mem::transmute(action.b) }); diff --git a/tests/ui/async-await/issues/issue-51719.rs b/tests/ui/async-await/issues/issue-51719.rs index 09241f982aa8a..1cf388cd8ab6f 100644 --- a/tests/ui/async-await/issues/issue-51719.rs +++ b/tests/ui/async-await/issues/issue-51719.rs @@ -1,10 +1,10 @@ // edition:2018 // -// Tests that the .await syntax can't be used to make a generator +// Tests that the .await syntax can't be used to make a coroutine async fn foo() {} -fn make_generator() { +fn make_coroutine() { let _gen = || foo().await; //~^ ERROR `await` is only allowed inside `async` functions and blocks } diff --git a/tests/ui/async-await/issues/issue-59972.rs b/tests/ui/async-await/issues/issue-59972.rs index c2e24a96b1d93..f60ec04c31ebb 100644 --- a/tests/ui/async-await/issues/issue-59972.rs +++ b/tests/ui/async-await/issues/issue-59972.rs @@ -1,4 +1,4 @@ -// Incorrect handling of uninhabited types could cause us to mark generator +// Incorrect handling of uninhabited types could cause us to mark coroutine // types as entirely uninhabited, when they were in fact constructible. This // caused us to hit "unreachable" code (illegal instruction on x86). diff --git a/tests/ui/async-await/issues/issue-60655-latebound-regions.rs b/tests/ui/async-await/issues/issue-60655-latebound-regions.rs index 66a3b07c3bd96..ee28a2733adca 100644 --- a/tests/ui/async-await/issues/issue-60655-latebound-regions.rs +++ b/tests/ui/async-await/issues/issue-60655-latebound-regions.rs @@ -19,7 +19,7 @@ async fn async_nop(_: &u8) {} pub type ServeFut = impl Future; -// Late bound regions occur in the generator witness type here. +// Late bound regions occur in the coroutine witness type here. fn serve() -> ServeFut { async move { let x = 5; diff --git a/tests/ui/async-await/issues/issue-64477-2.rs b/tests/ui/async-await/issues/issue-64477-2.rs index 2360b57cc4544..53ec3b0656652 100644 --- a/tests/ui/async-await/issues/issue-64477-2.rs +++ b/tests/ui/async-await/issues/issue-64477-2.rs @@ -2,7 +2,7 @@ // // In the past, the code generated by `format!` produced temporaries in the surrounding scope that // borrowed the arguments through `&dyn Trait`. These temporaries do not implement `Send`, which -// meant that when `format!` was used in an async block, the resulting generator was not `Send`. +// meant that when `format!` was used in an async block, the resulting coroutine was not `Send`. // See https://github.com/rust-lang/rust/issues/64477#issuecomment-534669068 for details // and https://github.com/rust-lang/rust/issues/64477#issuecomment-531882958 for an example. // diff --git a/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-completion.rs b/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-completion.rs index 725caddae0b20..9ed7a5d210e6f 100644 --- a/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-completion.rs +++ b/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-completion.rs @@ -1,4 +1,4 @@ -// issue 65419 - Attempting to run an async fn after completion mentions generators when it should +// issue 65419 - Attempting to run an async fn after completion mentions coroutines when it should // be talking about `async fn`s instead. // run-fail @@ -8,7 +8,7 @@ // ignore-wasm no panic or subprocess support // ignore-emscripten no panic or subprocess support -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] async fn foo() { } diff --git a/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs b/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs index 5909c3a5ecc06..51e9a54e48aef 100644 --- a/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs +++ b/tests/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs @@ -1,4 +1,4 @@ -// issue 65419 - Attempting to run an async fn after completion mentions generators when it should +// issue 65419 - Attempting to run an async fn after completion mentions coroutines when it should // be talking about `async fn`s instead. Should also test what happens when it panics. // run-fail @@ -8,7 +8,7 @@ // edition:2018 // ignore-wasm no panic or subprocess support -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::panic; diff --git a/tests/ui/async-await/issues/issue-65419/issue-65419-generator-resume-after-completion.rs b/tests/ui/async-await/issues/issue-65419/issue-65419-coroutine-resume-after-completion.rs similarity index 74% rename from tests/ui/async-await/issues/issue-65419/issue-65419-generator-resume-after-completion.rs rename to tests/ui/async-await/issues/issue-65419/issue-65419-coroutine-resume-after-completion.rs index 9fc5667d6847e..e16b86f957920 100644 --- a/tests/ui/async-await/issues/issue-65419/issue-65419-generator-resume-after-completion.rs +++ b/tests/ui/async-await/issues/issue-65419/issue-65419-coroutine-resume-after-completion.rs @@ -1,17 +1,17 @@ -// issue 65419 - Attempting to run an `async fn` after completion mentions generators when it should -// be talking about `async fn`s instead. Regression test added to make sure generators still +// issue 65419 - Attempting to run an `async fn` after completion mentions coroutines when it should +// be talking about `async fn`s instead. Regression test added to make sure coroutines still // panic when resumed after completion. // run-fail -// error-pattern:generator resumed after completion +// error-pattern:coroutine resumed after completion // edition:2018 // ignore-wasm no panic or subprocess support // ignore-emscripten no panic or subprocess support -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::{ - ops::Generator, + ops::Coroutine, pin::Pin, }; diff --git a/tests/ui/async-await/non-trivial-drop.rs b/tests/ui/async-await/non-trivial-drop.rs index 3fed7c972a1a0..1004303d5c137 100644 --- a/tests/ui/async-await/non-trivial-drop.rs +++ b/tests/ui/async-await/non-trivial-drop.rs @@ -1,7 +1,7 @@ // build-pass // edition:2018 -#![feature(generators)] +#![feature(coroutines)] fn main() { foo(); diff --git a/tests/ui/async-await/send-bound-async-closure.rs b/tests/ui/async-await/send-bound-async-closure.rs index 4e9e7309be091..2ec006da359d1 100644 --- a/tests/ui/async-await/send-bound-async-closure.rs +++ b/tests/ui/async-await/send-bound-async-closure.rs @@ -2,7 +2,7 @@ // check-pass // This test verifies that we do not create a query cycle when typechecking has several inference -// variables that point to the same generator interior type. +// variables that point to the same coroutine interior type. use std::future::Future; use std::pin::Pin; diff --git a/tests/ui/async-await/task-context-arg.rs b/tests/ui/async-await/task-context-arg.rs index 937723ca743e9..45b18d56b1cf0 100644 --- a/tests/ui/async-await/task-context-arg.rs +++ b/tests/ui/async-await/task-context-arg.rs @@ -10,7 +10,7 @@ use std::future::Future; // The compiler produces a closure as part of this function. That closure initially takes an -// argument _task_context. Later, when the MIR for that closure is transformed into a generator +// argument _task_context. Later, when the MIR for that closure is transformed into a coroutine // state machine, _task_context is demoted to not be an argument, but just part of an unnamed // argument. If we emit debug info saying that both _task_context and the unnamed argument are both // argument number 2, then LLVM will fail with "conflicting debug info for argument". See diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs index d067ff44704c7..b52939ffc119c 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs @@ -13,10 +13,10 @@ impl MarketMultiplier { } } -async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { +async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument was supplied //~^^ ERROR struct takes 1 generic argument but 0 generic arguments were supplied - LockedMarket(generator.lock().unwrap().buy()) + LockedMarket(coroutine.lock().unwrap().buy()) } struct LockedMarket(T); diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index 73e0aaf1e45cc..516c1d065e670 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -1,7 +1,7 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | -LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { +LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { | ^^^^^^^^^^^^---- help: remove these generics | | | expected 0 lifetime arguments @@ -15,7 +15,7 @@ LL | struct LockedMarket(T); error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | -LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { +LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { | ^^^^^^^^^^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` @@ -25,7 +25,7 @@ LL | struct LockedMarket(T); | ^^^^^^^^^^^^ - help: add missing generic argument | -LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_, T> { +LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_, T> { | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/closures/infer-signature-from-impl.next.stderr b/tests/ui/closures/infer-signature-from-impl.next.stderr new file mode 100644 index 0000000000000..97351706699a6 --- /dev/null +++ b/tests/ui/closures/infer-signature-from-impl.next.stderr @@ -0,0 +1,16 @@ +error[E0282]: type annotations needed + --> $DIR/infer-signature-from-impl.rs:17:16 + | +LL | needs_foo(|x| { + | ^ +LL | x.to_string(); + | - type must be known at this point + | +help: consider giving this closure parameter an explicit type + | +LL | needs_foo(|x: /* Type */| { + | ++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/closures/infer-signature-from-impl.rs b/tests/ui/closures/infer-signature-from-impl.rs new file mode 100644 index 0000000000000..6e8c94177bf66 --- /dev/null +++ b/tests/ui/closures/infer-signature-from-impl.rs @@ -0,0 +1,20 @@ +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next +//[next] known-bug: trait-system-refactor-initiative#71 +//[current] check-pass + +trait Foo {} +fn needs_foo(_: T) +where + Wrap: Foo, +{ +} + +struct Wrap(T); +impl Foo for Wrap where T: Fn(i32) {} + +fn main() { + needs_foo(|x| { + x.to_string(); + }); +} diff --git a/tests/ui/closures/issue-25439.rs b/tests/ui/closures/issue-25439.rs index 4f73ff3e38b9e..0269270b1b045 100644 --- a/tests/ui/closures/issue-25439.rs +++ b/tests/ui/closures/issue-25439.rs @@ -5,5 +5,5 @@ fn fix(f: F) -> i32 where F: Fn(Helper, i32) -> i32 { } fn main() { - fix(|_, x| x); //~ ERROR closure/generator type that references itself [E0644] + fix(|_, x| x); //~ ERROR closure/coroutine type that references itself [E0644] } diff --git a/tests/ui/closures/issue-25439.stderr b/tests/ui/closures/issue-25439.stderr index dadae23fdf399..5e889e6c18442 100644 --- a/tests/ui/closures/issue-25439.stderr +++ b/tests/ui/closures/issue-25439.stderr @@ -1,4 +1,4 @@ -error[E0644]: closure/generator type that references itself +error[E0644]: closure/coroutine type that references itself --> $DIR/issue-25439.rs:8:9 | LL | fix(|_, x| x); diff --git a/tests/ui/coherence/coherence-with-generator.rs b/tests/ui/coherence/coherence-with-coroutine.rs similarity index 69% rename from tests/ui/coherence/coherence-with-generator.rs rename to tests/ui/coherence/coherence-with-coroutine.rs index 5eb8dc2a4687f..21857d7fe66ee 100644 --- a/tests/ui/coherence/coherence-with-generator.rs +++ b/tests/ui/coherence/coherence-with-coroutine.rs @@ -1,13 +1,13 @@ // Test that encountering closures during coherence does not cause issues. -#![feature(type_alias_impl_trait, generators)] +#![feature(type_alias_impl_trait, coroutines)] #![cfg_attr(specialized, feature(specialization))] #![allow(incomplete_features)] // revisions: stock specialized // [specialized]check-pass -type OpaqueGenerator = impl Sized; -fn defining_use() -> OpaqueGenerator { +type OpaqueCoroutine = impl Sized; +fn defining_use() -> OpaqueCoroutine { || { for i in 0..10 { yield i; @@ -17,8 +17,8 @@ fn defining_use() -> OpaqueGenerator { struct Wrapper(T); trait Trait {} -impl Trait for Wrapper {} +impl Trait for Wrapper {} impl Trait for Wrapper {} -//[stock]~^ ERROR conflicting implementations of trait `Trait` for type `Wrapper` +//[stock]~^ ERROR conflicting implementations of trait `Trait` for type `Wrapper` fn main() {} diff --git a/tests/ui/coherence/coherence-with-generator.stock.stderr b/tests/ui/coherence/coherence-with-coroutine.stock.stderr similarity index 69% rename from tests/ui/coherence/coherence-with-generator.stock.stderr rename to tests/ui/coherence/coherence-with-coroutine.stock.stderr index 478ac4912646d..b2a9135c542f8 100644 --- a/tests/ui/coherence/coherence-with-generator.stock.stderr +++ b/tests/ui/coherence/coherence-with-coroutine.stock.stderr @@ -1,10 +1,10 @@ -error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper` - --> $DIR/coherence-with-generator.rs:21:1 +error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper` + --> $DIR/coherence-with-coroutine.rs:21:1 | -LL | impl Trait for Wrapper {} +LL | impl Trait for Wrapper {} | --------------------------------------- first implementation here LL | impl Trait for Wrapper {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Wrapper` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Wrapper` error: aborting due to previous error diff --git a/tests/ui/generator/addassign-yield.rs b/tests/ui/coroutine/addassign-yield.rs similarity index 97% rename from tests/ui/generator/addassign-yield.rs rename to tests/ui/coroutine/addassign-yield.rs index 66f22bf31fc40..919a559f85b98 100644 --- a/tests/ui/generator/addassign-yield.rs +++ b/tests/ui/coroutine/addassign-yield.rs @@ -5,7 +5,7 @@ // is being used), we were failing to account for all types that might // possibly be live across a yield point. -#![feature(generators)] +#![feature(coroutines)] fn foo() { let _x = static || { diff --git a/tests/ui/coroutine/async-coroutine-issue-67158.rs b/tests/ui/coroutine/async-coroutine-issue-67158.rs new file mode 100644 index 0000000000000..420454656d457 --- /dev/null +++ b/tests/ui/coroutine/async-coroutine-issue-67158.rs @@ -0,0 +1,6 @@ +#![feature(coroutines)] +// edition:2018 +// Regression test for #67158. +fn main() { + async { yield print!(":C") }; //~ ERROR `async` coroutines are not yet supported +} diff --git a/tests/ui/generator/async-generator-issue-67158.stderr b/tests/ui/coroutine/async-coroutine-issue-67158.stderr similarity index 64% rename from tests/ui/generator/async-generator-issue-67158.stderr rename to tests/ui/coroutine/async-coroutine-issue-67158.stderr index 7270d188e8b88..d583d3d5ea0a6 100644 --- a/tests/ui/generator/async-generator-issue-67158.stderr +++ b/tests/ui/coroutine/async-coroutine-issue-67158.stderr @@ -1,5 +1,5 @@ -error[E0727]: `async` generators are not yet supported - --> $DIR/async-generator-issue-67158.rs:5:13 +error[E0727]: `async` coroutines are not yet supported + --> $DIR/async-coroutine-issue-67158.rs:5:13 | LL | async { yield print!(":C") }; | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/generator/auto-trait-regions.rs b/tests/ui/coroutine/auto-trait-regions.rs similarity index 87% rename from tests/ui/generator/auto-trait-regions.rs rename to tests/ui/coroutine/auto-trait-regions.rs index aa4218e13a46b..5fce70e8e54d2 100644 --- a/tests/ui/generator/auto-trait-regions.rs +++ b/tests/ui/coroutine/auto-trait-regions.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![feature(auto_traits)] #![feature(negative_impls)] @@ -21,7 +21,7 @@ impl<'a> Foo for &'a OnlyFooIfRef {} fn assert_foo(f: T) {} fn main() { - // Make sure 'static is erased for generator interiors so we can't match it in trait selection + // Make sure 'static is erased for coroutine interiors so we can't match it in trait selection let x: &'static _ = &OnlyFooIfStaticRef(No); let gen = move || { let x = x; @@ -40,7 +40,7 @@ fn main() { }; assert_foo(gen); // ok - // Disallow impls which relates lifetimes in the generator interior + // Disallow impls which relates lifetimes in the coroutine interior let gen = move || { let a = A(&mut true, &mut true, No); //~^ temporary value dropped while borrowed diff --git a/tests/ui/generator/auto-trait-regions.stderr b/tests/ui/coroutine/auto-trait-regions.stderr similarity index 100% rename from tests/ui/generator/auto-trait-regions.stderr rename to tests/ui/coroutine/auto-trait-regions.stderr diff --git a/tests/ui/coroutine/auxiliary/metadata-sufficient-for-layout.rs b/tests/ui/coroutine/auxiliary/metadata-sufficient-for-layout.rs new file mode 100644 index 0000000000000..dc0521853409e --- /dev/null +++ b/tests/ui/coroutine/auxiliary/metadata-sufficient-for-layout.rs @@ -0,0 +1,11 @@ +// compile-flags: --emit metadata +#![feature(coroutines, coroutine_trait)] + +use std::marker::Unpin; +use std::ops::Coroutine; + +pub fn g() -> impl Coroutine<(), Yield = (), Return = ()> { + || { + yield; + } +} diff --git a/tests/ui/coroutine/auxiliary/xcrate-reachable.rs b/tests/ui/coroutine/auxiliary/xcrate-reachable.rs new file mode 100644 index 0000000000000..673153f0619ea --- /dev/null +++ b/tests/ui/coroutine/auxiliary/xcrate-reachable.rs @@ -0,0 +1,14 @@ +#![feature(coroutines, coroutine_trait)] + +use std::ops::Coroutine; + +fn msg() -> u32 { + 0 +} + +pub fn foo() -> impl Coroutine<(), Yield = (), Return = u32> { + || { + yield; + return msg(); + } +} diff --git a/tests/ui/coroutine/auxiliary/xcrate.rs b/tests/ui/coroutine/auxiliary/xcrate.rs new file mode 100644 index 0000000000000..f749a95ad35a3 --- /dev/null +++ b/tests/ui/coroutine/auxiliary/xcrate.rs @@ -0,0 +1,18 @@ +#![feature(coroutines, coroutine_trait)] + +use std::marker::Unpin; +use std::ops::Coroutine; + +pub fn foo() -> impl Coroutine<(), Yield = (), Return = ()> { + || { + if false { + yield; + } + } +} + +pub fn bar(t: T) -> Box + Unpin> { + Box::new(|| { + yield t; + }) +} diff --git a/tests/ui/generator/borrow-in-tail-expr.rs b/tests/ui/coroutine/borrow-in-tail-expr.rs similarity index 82% rename from tests/ui/generator/borrow-in-tail-expr.rs rename to tests/ui/coroutine/borrow-in-tail-expr.rs index 540f5e3e1dd6b..c1497ad29118c 100644 --- a/tests/ui/generator/borrow-in-tail-expr.rs +++ b/tests/ui/coroutine/borrow-in-tail-expr.rs @@ -1,6 +1,6 @@ // run-pass -#![feature(generators)] +#![feature(coroutines)] fn main() { let _a = || { diff --git a/tests/ui/generator/borrowing.rs b/tests/ui/coroutine/borrowing.rs similarity index 82% rename from tests/ui/generator/borrowing.rs rename to tests/ui/coroutine/borrowing.rs index d36592583cdc5..778eed8bd0d9f 100644 --- a/tests/ui/generator/borrowing.rs +++ b/tests/ui/coroutine/borrowing.rs @@ -1,6 +1,6 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/ui/generator/borrowing.stderr b/tests/ui/coroutine/borrowing.stderr similarity index 89% rename from tests/ui/generator/borrowing.stderr rename to tests/ui/coroutine/borrowing.stderr index 03a69fe362313..192ffaaa26b3e 100644 --- a/tests/ui/generator/borrowing.stderr +++ b/tests/ui/coroutine/borrowing.stderr @@ -5,11 +5,11 @@ LL | Pin::new(&mut || yield &a).resume(()) | ----------^ | | | | | borrowed value does not live long enough - | value captured here by generator + | value captured here by coroutine | a temporary with access to the borrow is created here ... LL | LL | }; - | -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for generator + | -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for coroutine | | | `a` dropped here while still borrowed | @@ -27,7 +27,7 @@ LL | let _b = { | -- borrow later stored here LL | let a = 3; LL | || { - | -- value captured here by generator + | -- value captured here by coroutine LL | yield &a | ^ borrowed value does not live long enough ... diff --git a/tests/ui/generator/clone-impl-async.rs b/tests/ui/coroutine/clone-impl-async.rs similarity index 93% rename from tests/ui/generator/clone-impl-async.rs rename to tests/ui/coroutine/clone-impl-async.rs index 9e9b59d3633f2..e8e82f1994dea 100644 --- a/tests/ui/generator/clone-impl-async.rs +++ b/tests/ui/coroutine/clone-impl-async.rs @@ -1,8 +1,8 @@ // edition:2021 -// gate-test-generator_clone -// Verifies that feature(generator_clone) doesn't allow async blocks to be cloned/copied. +// gate-test-coroutine_clone +// Verifies that feature(coroutine_clone) doesn't allow async blocks to be cloned/copied. -#![feature(generators, generator_clone)] +#![feature(coroutines, coroutine_clone)] use std::future::ready; diff --git a/tests/ui/generator/clone-impl-async.stderr b/tests/ui/coroutine/clone-impl-async.stderr similarity index 100% rename from tests/ui/generator/clone-impl-async.stderr rename to tests/ui/coroutine/clone-impl-async.stderr diff --git a/tests/ui/generator/clone-impl-static.rs b/tests/ui/coroutine/clone-impl-static.rs similarity index 66% rename from tests/ui/generator/clone-impl-static.rs rename to tests/ui/coroutine/clone-impl-static.rs index 55ed0f281e050..9a165cf4672e6 100644 --- a/tests/ui/generator/clone-impl-static.rs +++ b/tests/ui/coroutine/clone-impl-static.rs @@ -1,7 +1,7 @@ -// gate-test-generator_clone -// Verifies that static generators cannot be cloned/copied. +// gate-test-coroutine_clone +// Verifies that static coroutines cannot be cloned/copied. -#![feature(generators, generator_clone)] +#![feature(coroutines, coroutine_clone)] fn main() { let gen = static move || { diff --git a/tests/ui/generator/clone-impl-static.stderr b/tests/ui/coroutine/clone-impl-static.stderr similarity index 80% rename from tests/ui/generator/clone-impl-static.stderr rename to tests/ui/coroutine/clone-impl-static.stderr index 8b51824c7d25a..8fa9fb12bf685 100644 --- a/tests/ui/generator/clone-impl-static.stderr +++ b/tests/ui/coroutine/clone-impl-static.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `{static generator@$DIR/clone-impl-static.rs:7:15: 7:29}: Copy` is not satisfied +error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:7:15: 7:29}: Copy` is not satisfied --> $DIR/clone-impl-static.rs:10:16 | LL | check_copy(&gen); - | ---------- ^^^^ the trait `Copy` is not implemented for `{static generator@$DIR/clone-impl-static.rs:7:15: 7:29}` + | ---------- ^^^^ the trait `Copy` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:7:15: 7:29}` | | | required by a bound introduced by this call | @@ -12,11 +12,11 @@ note: required by a bound in `check_copy` LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `{static generator@$DIR/clone-impl-static.rs:7:15: 7:29}: Clone` is not satisfied +error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:7:15: 7:29}: Clone` is not satisfied --> $DIR/clone-impl-static.rs:12:17 | LL | check_clone(&gen); - | ----------- ^^^^ the trait `Clone` is not implemented for `{static generator@$DIR/clone-impl-static.rs:7:15: 7:29}` + | ----------- ^^^^ the trait `Clone` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:7:15: 7:29}` | | | required by a bound introduced by this call | diff --git a/tests/ui/generator/clone-impl.rs b/tests/ui/coroutine/clone-impl.rs similarity index 93% rename from tests/ui/generator/clone-impl.rs rename to tests/ui/coroutine/clone-impl.rs index cbfd65a530998..eed6f851bd028 100644 --- a/tests/ui/generator/clone-impl.rs +++ b/tests/ui/coroutine/clone-impl.rs @@ -1,8 +1,8 @@ -// gate-test-generator_clone -// Verifies that non-static generators can be cloned/copied if all their upvars and locals held +// gate-test-coroutine_clone +// Verifies that non-static coroutines can be cloned/copied if all their upvars and locals held // across awaits can be cloned/copied. -#![feature(generators, generator_clone)] +#![feature(coroutines, coroutine_clone)] struct NonClone; diff --git a/tests/ui/generator/clone-impl.stderr b/tests/ui/coroutine/clone-impl.stderr similarity index 78% rename from tests/ui/generator/clone-impl.stderr rename to tests/ui/coroutine/clone-impl.stderr index 870216398b1a1..82a6d0495c003 100644 --- a/tests/ui/generator/clone-impl.stderr +++ b/tests/ui/coroutine/clone-impl.stderr @@ -1,11 +1,11 @@ -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{generator@$DIR/clone-impl.rs:36:23: 36:30}` +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:36:23: 36:30}` --> $DIR/clone-impl.rs:42:5 | LL | let gen_clone_0 = move || { - | ------- within this `{generator@$DIR/clone-impl.rs:36:23: 36:30}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:36:23: 36:30}` ... LL | check_copy(&gen_clone_0); - | ^^^^^^^^^^ within `{generator@$DIR/clone-impl.rs:36:23: 36:30}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:36:23: 36:30}`, the trait `Copy` is not implemented for `Vec` | note: captured value does not implement `Copy` --> $DIR/clone-impl.rs:40:14 @@ -18,16 +18,16 @@ note: required by a bound in `check_copy` LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{generator@$DIR/clone-impl.rs:36:23: 36:30}` +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:36:23: 36:30}` --> $DIR/clone-impl.rs:42:5 | LL | let gen_clone_0 = move || { - | ------- within this `{generator@$DIR/clone-impl.rs:36:23: 36:30}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:36:23: 36:30}` ... LL | check_copy(&gen_clone_0); - | ^^^^^^^^^^ within `{generator@$DIR/clone-impl.rs:36:23: 36:30}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:36:23: 36:30}`, the trait `Copy` is not implemented for `Vec` | -note: generator does not implement `Copy` as this value is used across a yield +note: coroutine does not implement `Copy` as this value is used across a yield --> $DIR/clone-impl.rs:38:9 | LL | let v = vec!['a']; @@ -40,14 +40,14 @@ note: required by a bound in `check_copy` LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{generator@$DIR/clone-impl.rs:46:23: 46:30}` +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:46:23: 46:30}` --> $DIR/clone-impl.rs:58:5 | LL | let gen_clone_1 = move || { - | ------- within this `{generator@$DIR/clone-impl.rs:46:23: 46:30}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:46:23: 46:30}` ... LL | check_copy(&gen_clone_1); - | ^^^^^^^^^^ within `{generator@$DIR/clone-impl.rs:46:23: 46:30}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:46:23: 46:30}`, the trait `Copy` is not implemented for `Vec` | note: captured value does not implement `Copy` --> $DIR/clone-impl.rs:56:14 @@ -60,16 +60,16 @@ note: required by a bound in `check_copy` LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{generator@$DIR/clone-impl.rs:46:23: 46:30}` +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:46:23: 46:30}` --> $DIR/clone-impl.rs:58:5 | LL | let gen_clone_1 = move || { - | ------- within this `{generator@$DIR/clone-impl.rs:46:23: 46:30}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:46:23: 46:30}` ... LL | check_copy(&gen_clone_1); - | ^^^^^^^^^^ within `{generator@$DIR/clone-impl.rs:46:23: 46:30}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:46:23: 46:30}`, the trait `Copy` is not implemented for `Vec` | -note: generator does not implement `Copy` as this value is used across a yield +note: coroutine does not implement `Copy` as this value is used across a yield --> $DIR/clone-impl.rs:52:9 | LL | let v = vec!['a']; @@ -83,14 +83,14 @@ note: required by a bound in `check_copy` LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `NonClone: Copy` is not satisfied in `{generator@$DIR/clone-impl.rs:62:25: 62:32}` +error[E0277]: the trait bound `NonClone: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:62:25: 62:32}` --> $DIR/clone-impl.rs:66:5 | LL | let gen_non_clone = move || { - | ------- within this `{generator@$DIR/clone-impl.rs:62:25: 62:32}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:62:25: 62:32}` ... LL | check_copy(&gen_non_clone); - | ^^^^^^^^^^ within `{generator@$DIR/clone-impl.rs:62:25: 62:32}`, the trait `Copy` is not implemented for `NonClone` + | ^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:62:25: 62:32}`, the trait `Copy` is not implemented for `NonClone` | note: captured value does not implement `Copy` --> $DIR/clone-impl.rs:64:14 @@ -108,14 +108,14 @@ LL + #[derive(Copy)] LL | struct NonClone; | -error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{generator@$DIR/clone-impl.rs:62:25: 62:32}` +error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{coroutine@$DIR/clone-impl.rs:62:25: 62:32}` --> $DIR/clone-impl.rs:68:5 | LL | let gen_non_clone = move || { - | ------- within this `{generator@$DIR/clone-impl.rs:62:25: 62:32}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:62:25: 62:32}` ... LL | check_clone(&gen_non_clone); - | ^^^^^^^^^^^ within `{generator@$DIR/clone-impl.rs:62:25: 62:32}`, the trait `Clone` is not implemented for `NonClone` + | ^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:62:25: 62:32}`, the trait `Clone` is not implemented for `NonClone` | note: captured value does not implement `Clone` --> $DIR/clone-impl.rs:64:14 diff --git a/tests/ui/generator/conditional-drop.rs b/tests/ui/coroutine/conditional-drop.rs similarity index 94% rename from tests/ui/generator/conditional-drop.rs rename to tests/ui/coroutine/conditional-drop.rs index 0927df86927e0..634095c7accbc 100644 --- a/tests/ui/generator/conditional-drop.rs +++ b/tests/ui/coroutine/conditional-drop.rs @@ -3,9 +3,9 @@ // revisions: default nomiropt //[nomiropt]compile-flags: -Z mir-opt-level=0 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/tests/ui/generator/control-flow.rs b/tests/ui/coroutine/control-flow.rs similarity index 76% rename from tests/ui/generator/control-flow.rs rename to tests/ui/coroutine/control-flow.rs index 4f69c7855605a..709b135b2ee5b 100644 --- a/tests/ui/generator/control-flow.rs +++ b/tests/ui/coroutine/control-flow.rs @@ -3,19 +3,19 @@ // revisions: default nomiropt //[nomiropt]compile-flags: -Z mir-opt-level=0 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::marker::Unpin; -use std::ops::{GeneratorState, Generator}; +use std::ops::{CoroutineState, Coroutine}; use std::pin::Pin; fn finish(mut amt: usize, mut t: T) -> T::Return - where T: Generator<(), Yield = ()> + Unpin, + where T: Coroutine<(), Yield = ()> + Unpin, { loop { match Pin::new(&mut t).resume(()) { - GeneratorState::Yielded(()) => amt = amt.checked_sub(1).unwrap(), - GeneratorState::Complete(ret) => { + CoroutineState::Yielded(()) => amt = amt.checked_sub(1).unwrap(), + CoroutineState::Complete(ret) => { assert_eq!(amt, 0); return ret } diff --git a/tests/ui/generator/generator-region-requirements.migrate.stderr b/tests/ui/coroutine/coroutine-region-requirements.migrate.stderr similarity index 100% rename from tests/ui/generator/generator-region-requirements.migrate.stderr rename to tests/ui/coroutine/coroutine-region-requirements.migrate.stderr diff --git a/tests/ui/generator/generator-region-requirements.rs b/tests/ui/coroutine/coroutine-region-requirements.rs similarity index 58% rename from tests/ui/generator/generator-region-requirements.rs rename to tests/ui/coroutine/coroutine-region-requirements.rs index 7269a79ca3f98..8bc34fdd2f053 100644 --- a/tests/ui/generator/generator-region-requirements.rs +++ b/tests/ui/coroutine/coroutine-region-requirements.rs @@ -1,5 +1,5 @@ -#![feature(generators, generator_trait)] -use std::ops::{Generator, GeneratorState}; +#![feature(coroutines, coroutine_trait)] +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn dangle(x: &mut i32) -> &'static mut i32 { @@ -9,9 +9,9 @@ fn dangle(x: &mut i32) -> &'static mut i32 { }; loop { match Pin::new(&mut g).resume(()) { - GeneratorState::Complete(c) => return c, + CoroutineState::Complete(c) => return c, //~^ ERROR lifetime may not live long enough - GeneratorState::Yielded(_) => (), + CoroutineState::Yielded(_) => (), } } } diff --git a/tests/ui/generator/generator-region-requirements.stderr b/tests/ui/coroutine/coroutine-region-requirements.stderr similarity index 75% rename from tests/ui/generator/generator-region-requirements.stderr rename to tests/ui/coroutine/coroutine-region-requirements.stderr index 87f60467287b6..ad3183e7612b3 100644 --- a/tests/ui/generator/generator-region-requirements.stderr +++ b/tests/ui/coroutine/coroutine-region-requirements.stderr @@ -1,10 +1,10 @@ error: lifetime may not live long enough - --> $DIR/generator-region-requirements.rs:12:51 + --> $DIR/coroutine-region-requirements.rs:12:51 | LL | fn dangle(x: &mut i32) -> &'static mut i32 { | - let's call the lifetime of this reference `'1` ... -LL | GeneratorState::Complete(c) => return c, +LL | CoroutineState::Complete(c) => return c, | ^ returning this value requires that `'1` must outlive `'static` error: aborting due to previous error diff --git a/tests/ui/generator/generator-resume-after-panic.rs b/tests/ui/coroutine/coroutine-resume-after-panic.rs similarity index 75% rename from tests/ui/generator/generator-resume-after-panic.rs rename to tests/ui/coroutine/coroutine-resume-after-panic.rs index f2e67f1f750cc..5915f5ad9a968 100644 --- a/tests/ui/generator/generator-resume-after-panic.rs +++ b/tests/ui/coroutine/coroutine-resume-after-panic.rs @@ -1,14 +1,14 @@ // run-fail // needs-unwind -// error-pattern:generator resumed after panicking +// error-pattern:coroutine resumed after panicking // ignore-emscripten no processes -// Test that we get the correct message for resuming a panicked generator. +// Test that we get the correct message for resuming a panicked coroutine. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::{ - ops::Generator, + ops::Coroutine, pin::Pin, panic, }; diff --git a/tests/ui/generator/generator-with-nll.rs b/tests/ui/coroutine/coroutine-with-nll.rs similarity index 71% rename from tests/ui/generator/generator-with-nll.rs rename to tests/ui/coroutine/coroutine-with-nll.rs index cee3e6d226c12..28a3643fbc9cd 100644 --- a/tests/ui/generator/generator-with-nll.rs +++ b/tests/ui/coroutine/coroutine-with-nll.rs @@ -1,11 +1,11 @@ -#![feature(generators)] +#![feature(coroutines)] fn main() { || { // The reference in `_a` is a Legal with NLL since it ends before the yield let _a = &mut true; let b = &mut true; - //~^ borrow may still be in use when generator yields + //~^ borrow may still be in use when coroutine yields yield (); println!("{}", b); }; diff --git a/tests/ui/generator/generator-with-nll.stderr b/tests/ui/coroutine/coroutine-with-nll.stderr similarity index 71% rename from tests/ui/generator/generator-with-nll.stderr rename to tests/ui/coroutine/coroutine-with-nll.stderr index 14199aeb93056..ed58debe2b4cb 100644 --- a/tests/ui/generator/generator-with-nll.stderr +++ b/tests/ui/coroutine/coroutine-with-nll.stderr @@ -1,5 +1,5 @@ -error[E0626]: borrow may still be in use when generator yields - --> $DIR/generator-with-nll.rs:7:17 +error[E0626]: borrow may still be in use when coroutine yields + --> $DIR/coroutine-with-nll.rs:7:17 | LL | let b = &mut true; | ^^^^^^^^^ diff --git a/tests/ui/coroutine/coroutine-yielding-or-returning-itself.rs b/tests/ui/coroutine/coroutine-yielding-or-returning-itself.rs new file mode 100644 index 0000000000000..3c91b3c932951 --- /dev/null +++ b/tests/ui/coroutine/coroutine-yielding-or-returning-itself.rs @@ -0,0 +1,35 @@ +#![feature(coroutine_trait)] +#![feature(coroutines)] + +// Test that we cannot create a coroutine that returns a value of its +// own type. + +use std::ops::Coroutine; + +pub fn want_cyclic_coroutine_return(_: T) + where T: Coroutine +{ +} + +fn supply_cyclic_coroutine_return() { + want_cyclic_coroutine_return(|| { + //~^ ERROR type mismatch + if false { yield None.unwrap(); } + None.unwrap() + }) +} + +pub fn want_cyclic_coroutine_yield(_: T) + where T: Coroutine +{ +} + +fn supply_cyclic_coroutine_yield() { + want_cyclic_coroutine_yield(|| { + //~^ ERROR type mismatch + if false { yield None.unwrap(); } + None.unwrap() + }) +} + +fn main() { } diff --git a/tests/ui/generator/generator-yielding-or-returning-itself.stderr b/tests/ui/coroutine/coroutine-yielding-or-returning-itself.stderr similarity index 57% rename from tests/ui/generator/generator-yielding-or-returning-itself.stderr rename to tests/ui/coroutine/coroutine-yielding-or-returning-itself.stderr index 7841a0854ca98..325030524ba8d 100644 --- a/tests/ui/generator/generator-yielding-or-returning-itself.stderr +++ b/tests/ui/coroutine/coroutine-yielding-or-returning-itself.stderr @@ -1,7 +1,7 @@ -error[E0271]: type mismatch resolving `<{generator@$DIR/generator-yielding-or-returning-itself.rs:15:34: 15:36} as Generator>::Return == {generator@$DIR/generator-yielding-or-returning-itself.rs:15:34: 15:36}` - --> $DIR/generator-yielding-or-returning-itself.rs:15:34 +error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine-yielding-or-returning-itself.rs:15:34: 15:36} as Coroutine>::Return == {coroutine@$DIR/coroutine-yielding-or-returning-itself.rs:15:34: 15:36}` + --> $DIR/coroutine-yielding-or-returning-itself.rs:15:34 | -LL | want_cyclic_generator_return(|| { +LL | want_cyclic_coroutine_return(|| { | _____----------------------------_^ | | | | | required by a bound introduced by this call @@ -15,18 +15,18 @@ LL | | }) this error may be the result of a recent compiler bug-fix, see issue #46062 for more information -note: required by a bound in `want_cyclic_generator_return` - --> $DIR/generator-yielding-or-returning-itself.rs:10:36 +note: required by a bound in `want_cyclic_coroutine_return` + --> $DIR/coroutine-yielding-or-returning-itself.rs:10:36 | -LL | pub fn want_cyclic_generator_return(_: T) +LL | pub fn want_cyclic_coroutine_return(_: T) | ---------------------------- required by a bound in this function -LL | where T: Generator - | ^^^^^^^^^^ required by this bound in `want_cyclic_generator_return` +LL | where T: Coroutine + | ^^^^^^^^^^ required by this bound in `want_cyclic_coroutine_return` -error[E0271]: type mismatch resolving `<{generator@$DIR/generator-yielding-or-returning-itself.rs:28:33: 28:35} as Generator>::Yield == {generator@$DIR/generator-yielding-or-returning-itself.rs:28:33: 28:35}` - --> $DIR/generator-yielding-or-returning-itself.rs:28:33 +error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine-yielding-or-returning-itself.rs:28:33: 28:35} as Coroutine>::Yield == {coroutine@$DIR/coroutine-yielding-or-returning-itself.rs:28:33: 28:35}` + --> $DIR/coroutine-yielding-or-returning-itself.rs:28:33 | -LL | want_cyclic_generator_yield(|| { +LL | want_cyclic_coroutine_yield(|| { | _____---------------------------_^ | | | | | required by a bound introduced by this call @@ -40,13 +40,13 @@ LL | | }) this error may be the result of a recent compiler bug-fix, see issue #46062 for more information -note: required by a bound in `want_cyclic_generator_yield` - --> $DIR/generator-yielding-or-returning-itself.rs:23:24 +note: required by a bound in `want_cyclic_coroutine_yield` + --> $DIR/coroutine-yielding-or-returning-itself.rs:23:24 | -LL | pub fn want_cyclic_generator_yield(_: T) +LL | pub fn want_cyclic_coroutine_yield(_: T) | --------------------------- required by a bound in this function -LL | where T: Generator - | ^^^^^^^^^ required by this bound in `want_cyclic_generator_yield` +LL | where T: Coroutine + | ^^^^^^^^^ required by this bound in `want_cyclic_coroutine_yield` error: aborting due to 2 previous errors diff --git a/tests/ui/generator/derived-drop-parent-expr.rs b/tests/ui/coroutine/derived-drop-parent-expr.rs similarity index 93% rename from tests/ui/generator/derived-drop-parent-expr.rs rename to tests/ui/coroutine/derived-drop-parent-expr.rs index e381924517d35..59a3e847838f0 100644 --- a/tests/ui/generator/derived-drop-parent-expr.rs +++ b/tests/ui/coroutine/derived-drop-parent-expr.rs @@ -1,7 +1,7 @@ // build-pass //! Like drop-tracking-parent-expression, but also tests that this doesn't ICE when building MIR -#![feature(generators)] +#![feature(coroutines)] fn assert_send(_thing: T) {} diff --git a/tests/ui/generator/discriminant.rs b/tests/ui/coroutine/discriminant.rs similarity index 88% rename from tests/ui/generator/discriminant.rs rename to tests/ui/coroutine/discriminant.rs index 195e77022992d..73bdd9c8671fc 100644 --- a/tests/ui/generator/discriminant.rs +++ b/tests/ui/coroutine/discriminant.rs @@ -1,12 +1,12 @@ -//! Tests that generator discriminant sizes and ranges are chosen optimally and that they are +//! Tests that coroutine discriminant sizes and ranges are chosen optimally and that they are //! reflected in the output of `mem::discriminant`. // run-pass -#![feature(generators, generator_trait, core_intrinsics, discriminant_kind)] +#![feature(coroutines, coroutine_trait, core_intrinsics, discriminant_kind)] use std::intrinsics::discriminant_value; -use std::marker::{Unpin, DiscriminantKind}; +use std::marker::{DiscriminantKind, Unpin}; use std::mem::size_of_val; use std::{cmp, ops::*}; @@ -66,16 +66,16 @@ macro_rules! yield250 { } fn cycle( - gen: impl Generator<()> + Unpin + DiscriminantKind, - expected_max_discr: u32 + gen: impl Coroutine<()> + Unpin + DiscriminantKind, + expected_max_discr: u32, ) { let mut gen = Box::pin(gen); let mut max_discr = 0; loop { max_discr = cmp::max(max_discr, discriminant_value(gen.as_mut().get_mut())); match gen.as_mut().resume(()) { - GeneratorState::Yielded(_) => {} - GeneratorState::Complete(_) => { + CoroutineState::Yielded(_) => {} + CoroutineState::Complete(_) => { assert_eq!(max_discr, expected_max_discr); return; } diff --git a/tests/ui/generator/drop-and-replace.rs b/tests/ui/coroutine/drop-and-replace.rs similarity index 77% rename from tests/ui/generator/drop-and-replace.rs rename to tests/ui/coroutine/drop-and-replace.rs index a9a50a122a19c..38b757fac29a8 100644 --- a/tests/ui/generator/drop-and-replace.rs +++ b/tests/ui/coroutine/drop-and-replace.rs @@ -1,19 +1,19 @@ // run-pass // Regression test for incorrect DropAndReplace behavior introduced in #60840 // and fixed in #61373. When combined with the optimization implemented in -// #60187, this produced incorrect code for generators when a saved local was +// #60187, this produced incorrect code for coroutines when a saved local was // re-assigned. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; #[derive(Debug, PartialEq)] struct Foo(i32); impl Drop for Foo { - fn drop(&mut self) { } + fn drop(&mut self) {} } fn main() { @@ -38,7 +38,7 @@ fn main() { loop { match Pin::new(&mut a).resume(()) { - GeneratorState::Complete(()) => break, + CoroutineState::Complete(()) => break, _ => (), } } diff --git a/tests/ui/generator/drop-control-flow.rs b/tests/ui/coroutine/drop-control-flow.rs similarity index 94% rename from tests/ui/generator/drop-control-flow.rs rename to tests/ui/coroutine/drop-control-flow.rs index 1c25c06ba4ccf..55d08b8d5b528 100644 --- a/tests/ui/generator/drop-control-flow.rs +++ b/tests/ui/coroutine/drop-control-flow.rs @@ -1,10 +1,10 @@ // build-pass -// A test to ensure generators capture values that were conditionally dropped, +// A test to ensure coroutines capture values that were conditionally dropped, // and also that values that are dropped along all paths to a yield do not get -// included in the generator type. +// included in the coroutine type. -#![feature(generators, negative_impls)] +#![feature(coroutines, negative_impls)] #![allow(unused_assignments, dead_code)] struct Ptr; diff --git a/tests/ui/generator/drop-env.rs b/tests/ui/coroutine/drop-env.rs similarity index 94% rename from tests/ui/generator/drop-env.rs rename to tests/ui/coroutine/drop-env.rs index 137a407931a17..404c043431daa 100644 --- a/tests/ui/generator/drop-env.rs +++ b/tests/ui/coroutine/drop-env.rs @@ -3,10 +3,10 @@ // revisions: default nomiropt //[nomiropt]compile-flags: -Z mir-opt-level=0 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] #![allow(dropping_copy_types)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/tests/ui/generator/drop-track-addassign-yield.rs b/tests/ui/coroutine/drop-track-addassign-yield.rs similarity index 97% rename from tests/ui/generator/drop-track-addassign-yield.rs rename to tests/ui/coroutine/drop-track-addassign-yield.rs index 1e64f1d2ec736..6c5897458ecc4 100644 --- a/tests/ui/generator/drop-track-addassign-yield.rs +++ b/tests/ui/coroutine/drop-track-addassign-yield.rs @@ -3,7 +3,7 @@ // Based on addassign-yield.rs, but with drop tracking enabled. Originally we did not implement // the fake_read callback on ExprUseVisitor which caused this case to break. -#![feature(generators)] +#![feature(coroutines)] fn foo() { let _y = static || { diff --git a/tests/ui/generator/drop-tracking-parent-expression.rs b/tests/ui/coroutine/drop-tracking-parent-expression.rs similarity index 97% rename from tests/ui/generator/drop-tracking-parent-expression.rs rename to tests/ui/coroutine/drop-tracking-parent-expression.rs index 198b14528aad5..4d40192c07a27 100644 --- a/tests/ui/generator/drop-tracking-parent-expression.rs +++ b/tests/ui/coroutine/drop-tracking-parent-expression.rs @@ -1,4 +1,4 @@ -#![feature(generators, negative_impls, rustc_attrs)] +#![feature(coroutines, negative_impls, rustc_attrs)] macro_rules! type_combinations { ( diff --git a/tests/ui/generator/drop-tracking-parent-expression.stderr b/tests/ui/coroutine/drop-tracking-parent-expression.stderr similarity index 86% rename from tests/ui/generator/drop-tracking-parent-expression.stderr rename to tests/ui/coroutine/drop-tracking-parent-expression.stderr index e85bb1347a798..6cd4ec83377d9 100644 --- a/tests/ui/generator/drop-tracking-parent-expression.stderr +++ b/tests/ui/coroutine/drop-tracking-parent-expression.stderr @@ -1,8 +1,8 @@ -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/drop-tracking-parent-expression.rs:23:13 | LL | assert_send(g); - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` ... LL | / type_combinations!( LL | | // OK @@ -13,8 +13,8 @@ LL | | }; LL | | ); | |_____- in this macro invocation | - = help: within `{generator@$DIR/drop-tracking-parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `derived_drop::Client` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/drop-tracking-parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `derived_drop::Client` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/drop-tracking-parent-expression.rs:21:22 | LL | let g = move || match drop($name::Client { ..$name::Client::default() }) { @@ -38,11 +38,11 @@ LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/drop-tracking-parent-expression.rs:23:13 | LL | assert_send(g); - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` ... LL | / type_combinations!( LL | | // OK @@ -53,8 +53,8 @@ LL | | }; LL | | ); | |_____- in this macro invocation | - = help: within `{generator@$DIR/drop-tracking-parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `significant_drop::Client` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/drop-tracking-parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `significant_drop::Client` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/drop-tracking-parent-expression.rs:21:22 | LL | let g = move || match drop($name::Client { ..$name::Client::default() }) { @@ -78,11 +78,11 @@ LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/drop-tracking-parent-expression.rs:23:13 | LL | assert_send(g); - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` ... LL | / type_combinations!( LL | | // OK @@ -93,8 +93,8 @@ LL | | }; LL | | ); | |_____- in this macro invocation | - = help: within `{generator@$DIR/drop-tracking-parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `insignificant_dtor::Client` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/drop-tracking-parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `insignificant_dtor::Client` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/drop-tracking-parent-expression.rs:21:22 | LL | let g = move || match drop($name::Client { ..$name::Client::default() }) { diff --git a/tests/ui/generator/drop-tracking-yielding-in-match-guards.rs b/tests/ui/coroutine/drop-tracking-yielding-in-match-guards.rs similarity index 85% rename from tests/ui/generator/drop-tracking-yielding-in-match-guards.rs rename to tests/ui/coroutine/drop-tracking-yielding-in-match-guards.rs index 92e0136d51b15..622765d82aa5b 100644 --- a/tests/ui/generator/drop-tracking-yielding-in-match-guards.rs +++ b/tests/ui/coroutine/drop-tracking-yielding-in-match-guards.rs @@ -1,7 +1,7 @@ // build-pass // edition:2018 -#![feature(generators)] +#![feature(coroutines)] fn main() { let _ = static |x: u8| match x { diff --git a/tests/ui/generator/drop-yield-twice.rs b/tests/ui/coroutine/drop-yield-twice.rs similarity index 64% rename from tests/ui/generator/drop-yield-twice.rs rename to tests/ui/coroutine/drop-yield-twice.rs index f484cbb8d67d5..015343a277626 100644 --- a/tests/ui/generator/drop-yield-twice.rs +++ b/tests/ui/coroutine/drop-yield-twice.rs @@ -1,10 +1,10 @@ -#![feature(negative_impls, generators)] +#![feature(negative_impls, coroutines)] struct Foo(i32); impl !Send for Foo {} fn main() { - assert_send(|| { //~ ERROR generator cannot be sent between threads safely + assert_send(|| { //~ ERROR coroutine cannot be sent between threads safely let guard = Foo(42); yield; drop(guard); diff --git a/tests/ui/generator/drop-yield-twice.stderr b/tests/ui/coroutine/drop-yield-twice.stderr similarity index 71% rename from tests/ui/generator/drop-yield-twice.stderr rename to tests/ui/coroutine/drop-yield-twice.stderr index 39a906f0bf4c0..fbbedac5775a4 100644 --- a/tests/ui/generator/drop-yield-twice.stderr +++ b/tests/ui/coroutine/drop-yield-twice.stderr @@ -1,11 +1,11 @@ -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/drop-yield-twice.rs:7:5 | LL | assert_send(|| { - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` | - = help: within `{generator@$DIR/drop-yield-twice.rs:7:17: 7:19}`, the trait `Send` is not implemented for `Foo` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/drop-yield-twice.rs:7:17: 7:19}`, the trait `Send` is not implemented for `Foo` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/drop-yield-twice.rs:9:9 | LL | let guard = Foo(42); diff --git a/tests/ui/generator/dropck-resume.rs b/tests/ui/coroutine/dropck-resume.rs similarity index 77% rename from tests/ui/generator/dropck-resume.rs rename to tests/ui/coroutine/dropck-resume.rs index 4c18077f33573..07ca4d37aba69 100644 --- a/tests/ui/generator/dropck-resume.rs +++ b/tests/ui/coroutine/dropck-resume.rs @@ -1,6 +1,6 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; struct SetToNone<'a: 'b, 'b>(&'b mut Option<&'a i32>); @@ -11,7 +11,7 @@ impl<'a, 'b> Drop for SetToNone<'a, 'b> { } } -fn drop_using_generator() -> i32 { +fn drop_using_coroutine() -> i32 { let mut y = Some(&0); let z = &mut y; let r; @@ -29,5 +29,5 @@ fn drop_using_generator() -> i32 { } fn main() { - println!("{}", drop_using_generator()); + println!("{}", drop_using_coroutine()); } diff --git a/tests/ui/generator/dropck-resume.stderr b/tests/ui/coroutine/dropck-resume.stderr similarity index 92% rename from tests/ui/generator/dropck-resume.stderr rename to tests/ui/coroutine/dropck-resume.stderr index ecf92e7e3ae79..028523978f9b8 100644 --- a/tests/ui/generator/dropck-resume.stderr +++ b/tests/ui/coroutine/dropck-resume.stderr @@ -8,7 +8,7 @@ LL | r = y.as_ref().unwrap(); | ^ immutable borrow occurs here LL | LL | } - | - mutable borrow might be used here, when `g` is dropped and runs the destructor for generator + | - mutable borrow might be used here, when `g` is dropped and runs the destructor for coroutine error: aborting due to previous error diff --git a/tests/ui/generator/dropck.rs b/tests/ui/coroutine/dropck.rs similarity index 80% rename from tests/ui/generator/dropck.rs rename to tests/ui/coroutine/dropck.rs index f82111a76b18f..450361c8dd03b 100644 --- a/tests/ui/generator/dropck.rs +++ b/tests/ui/coroutine/dropck.rs @@ -1,7 +1,7 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::cell::RefCell; -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { @@ -11,7 +11,7 @@ fn main() { //~^ ERROR `*cell` does not live long enough [E0597] // the upvar is the non-dropck `&mut Option>`. gen = || { - // but the generator can use it to drop a `Ref<'a, i32>`. + // but the coroutine can use it to drop a `Ref<'a, i32>`. let _d = ref_.take(); //~ ERROR `ref_` does not live long enough yield; }; diff --git a/tests/ui/generator/dropck.stderr b/tests/ui/coroutine/dropck.stderr similarity index 86% rename from tests/ui/generator/dropck.stderr rename to tests/ui/coroutine/dropck.stderr index 246ac99f83fed..241d6dfe0a169 100644 --- a/tests/ui/generator/dropck.stderr +++ b/tests/ui/coroutine/dropck.stderr @@ -11,7 +11,7 @@ LL | } | - | | | `*cell` dropped here while still borrowed - | borrow might be used here, when `gen` is dropped and runs the destructor for generator + | borrow might be used here, when `gen` is dropped and runs the destructor for coroutine | = note: values in a scope are dropped in the opposite order they are defined @@ -19,8 +19,8 @@ error[E0597]: `ref_` does not live long enough --> $DIR/dropck.rs:15:18 | LL | gen = || { - | -- value captured here by generator -LL | // but the generator can use it to drop a `Ref<'a, i32>`. + | -- value captured here by coroutine +LL | // but the coroutine can use it to drop a `Ref<'a, i32>`. LL | let _d = ref_.take(); | ^^^^ borrowed value does not live long enough ... @@ -28,7 +28,7 @@ LL | } | - | | | `ref_` dropped here while still borrowed - | borrow might be used here, when `gen` is dropped and runs the destructor for generator + | borrow might be used here, when `gen` is dropped and runs the destructor for coroutine | = note: values in a scope are dropped in the opposite order they are defined diff --git a/tests/ui/generator/issue-102645.rs b/tests/ui/coroutine/issue-102645.rs similarity index 83% rename from tests/ui/generator/issue-102645.rs rename to tests/ui/coroutine/issue-102645.rs index 677cc69d3f2db..a0263510e1368 100644 --- a/tests/ui/generator/issue-102645.rs +++ b/tests/ui/coroutine/issue-102645.rs @@ -1,6 +1,6 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/ui/generator/issue-102645.stderr b/tests/ui/coroutine/issue-102645.stderr similarity index 90% rename from tests/ui/generator/issue-102645.stderr rename to tests/ui/coroutine/issue-102645.stderr index 5d28dfc45b313..3db090346cde1 100644 --- a/tests/ui/generator/issue-102645.stderr +++ b/tests/ui/coroutine/issue-102645.stderr @@ -5,7 +5,7 @@ LL | Pin::new(&mut b).resume(); | ^^^^^^-- an argument of type `()` is missing | note: method defined here - --> $SRC_DIR/core/src/ops/generator.rs:LL:COL + --> $SRC_DIR/core/src/ops/coroutine.rs:LL:COL help: provide the argument | LL | Pin::new(&mut b).resume(()); diff --git a/tests/ui/generator/issue-105084.rs b/tests/ui/coroutine/issue-105084.rs similarity index 84% rename from tests/ui/generator/issue-105084.rs rename to tests/ui/coroutine/issue-105084.rs index 50b5da6e6adfd..7801f1bcea0db 100644 --- a/tests/ui/generator/issue-105084.rs +++ b/tests/ui/coroutine/issue-105084.rs @@ -1,9 +1,9 @@ -#![feature(generators)] -#![feature(generator_clone)] -#![feature(generator_trait)] +#![feature(coroutines)] +#![feature(coroutine_clone)] +#![feature(coroutine_trait)] #![feature(rustc_attrs, stmt_expr_attributes)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn copy(x: T) -> T { @@ -25,9 +25,9 @@ fn main() { // Allocate the temporary box. Pin::new(&mut g).resume(()); - // The temporary box is in generator locals. + // The temporary box is in coroutine locals. // As it is not taken into account for trait computation, - // the generator is `Copy`. + // the coroutine is `Copy`. let mut h = copy(g); //~^ ERROR the trait bound `Box<(i32, ())>: Copy` is not satisfied in diff --git a/tests/ui/generator/issue-105084.stderr b/tests/ui/coroutine/issue-105084.stderr similarity index 84% rename from tests/ui/generator/issue-105084.stderr rename to tests/ui/coroutine/issue-105084.stderr index 573c31f113402..38f114ff7747f 100644 --- a/tests/ui/generator/issue-105084.stderr +++ b/tests/ui/coroutine/issue-105084.stderr @@ -2,7 +2,7 @@ error[E0382]: borrow of moved value: `g` --> $DIR/issue-105084.rs:37:14 | LL | let mut g = || { - | ----- move occurs because `g` has type `{generator@$DIR/issue-105084.rs:14:17: 14:19}`, which does not implement the `Copy` trait + | ----- move occurs because `g` has type `{coroutine@$DIR/issue-105084.rs:14:17: 14:19}`, which does not implement the `Copy` trait ... LL | let mut h = copy(g); | - value moved here @@ -22,16 +22,16 @@ help: consider cloning the value if the performance cost is acceptable LL | let mut h = copy(g.clone()); | ++++++++ -error[E0277]: the trait bound `Box<(i32, ())>: Copy` is not satisfied in `{generator@$DIR/issue-105084.rs:14:17: 14:19}` +error[E0277]: the trait bound `Box<(i32, ())>: Copy` is not satisfied in `{coroutine@$DIR/issue-105084.rs:14:17: 14:19}` --> $DIR/issue-105084.rs:31:17 | LL | let mut g = || { - | -- within this `{generator@$DIR/issue-105084.rs:14:17: 14:19}` + | -- within this `{coroutine@$DIR/issue-105084.rs:14:17: 14:19}` ... LL | let mut h = copy(g); - | ^^^^ within `{generator@$DIR/issue-105084.rs:14:17: 14:19}`, the trait `Copy` is not implemented for `Box<(i32, ())>` + | ^^^^ within `{coroutine@$DIR/issue-105084.rs:14:17: 14:19}`, the trait `Copy` is not implemented for `Box<(i32, ())>` | -note: generator does not implement `Copy` as this value is used across a yield +note: coroutine does not implement `Copy` as this value is used across a yield --> $DIR/issue-105084.rs:21:22 | LL | Box::new((5, yield)); diff --git a/tests/ui/generator/issue-110929-generator-conflict-error-ice.rs b/tests/ui/coroutine/issue-110929-coroutine-conflict-error-ice.rs similarity index 89% rename from tests/ui/generator/issue-110929-generator-conflict-error-ice.rs rename to tests/ui/coroutine/issue-110929-coroutine-conflict-error-ice.rs index a45479e5300d8..feaaa71ea9c4e 100644 --- a/tests/ui/generator/issue-110929-generator-conflict-error-ice.rs +++ b/tests/ui/coroutine/issue-110929-coroutine-conflict-error-ice.rs @@ -1,5 +1,5 @@ // edition:2021 -#![feature(generators)] +#![feature(coroutines)] fn main() { let x = &mut (); diff --git a/tests/ui/generator/issue-110929-generator-conflict-error-ice.stderr b/tests/ui/coroutine/issue-110929-coroutine-conflict-error-ice.stderr similarity index 82% rename from tests/ui/generator/issue-110929-generator-conflict-error-ice.stderr rename to tests/ui/coroutine/issue-110929-coroutine-conflict-error-ice.stderr index 66f0e3d94bdab..77da6c4cdc941 100644 --- a/tests/ui/generator/issue-110929-generator-conflict-error-ice.stderr +++ b/tests/ui/coroutine/issue-110929-coroutine-conflict-error-ice.stderr @@ -1,8 +1,8 @@ error[E0499]: cannot borrow `*x` as mutable more than once at a time - --> $DIR/issue-110929-generator-conflict-error-ice.rs:8:9 + --> $DIR/issue-110929-coroutine-conflict-error-ice.rs:8:9 | LL | let _c = || yield *&mut *x; - | -- -- first borrow occurs due to use of `*x` in generator + | -- -- first borrow occurs due to use of `*x` in coroutine | | | first mutable borrow occurs here LL | || _ = &mut *x; @@ -11,7 +11,7 @@ LL | || _ = &mut *x; | second mutable borrow occurs here LL | LL | }; - | - first borrow might be used here, when `_c` is dropped and runs the destructor for generator + | - first borrow might be used here, when `_c` is dropped and runs the destructor for coroutine error: aborting due to previous error diff --git a/tests/ui/generator/issue-113279.rs b/tests/ui/coroutine/issue-113279.rs similarity index 84% rename from tests/ui/generator/issue-113279.rs rename to tests/ui/coroutine/issue-113279.rs index f69f804b716d5..f251c924c1331 100644 --- a/tests/ui/generator/issue-113279.rs +++ b/tests/ui/coroutine/issue-113279.rs @@ -1,10 +1,10 @@ -#![feature(generators)] +#![feature(coroutines)] // `foo` attempts to dereference `""`, which results in an error being reported. Later, the -// generator transform for `foo` then produces a union which contains a `str` type - unions should +// coroutine transform for `foo` then produces a union which contains a `str` type - unions should // not contain unsized types, but this is okay because an error has been reported already. // When const propagation happens later in compilation, it attempts to compute the layout of the -// generator (as part of checking whether something can be const propagated) and in turn attempts +// coroutine (as part of checking whether something can be const propagated) and in turn attempts // to compute the layout of `str` in the context of a union - where this caused an ICE. This test // makes sure that doesn't happen again. diff --git a/tests/ui/generator/issue-113279.stderr b/tests/ui/coroutine/issue-113279.stderr similarity index 100% rename from tests/ui/generator/issue-113279.stderr rename to tests/ui/coroutine/issue-113279.stderr diff --git a/tests/ui/generator/issue-44197.rs b/tests/ui/coroutine/issue-44197.rs similarity index 52% rename from tests/ui/generator/issue-44197.rs rename to tests/ui/coroutine/issue-44197.rs index 389b9d1396941..c0326bdae4e30 100644 --- a/tests/ui/generator/issue-44197.rs +++ b/tests/ui/coroutine/issue-44197.rs @@ -1,15 +1,15 @@ // run-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn foo(_: &str) -> String { String::new() } -fn bar(baz: String) -> impl Generator<(), Yield = String, Return = ()> { +fn bar(baz: String) -> impl Coroutine<(), Yield = String, Return = ()> { move || { yield foo(&baz); } @@ -19,7 +19,7 @@ fn foo2(_: &str) -> Result { Err(()) } -fn bar2(baz: String) -> impl Generator<(), Yield = String, Return = ()> { +fn bar2(baz: String) -> impl Coroutine<(), Yield = String, Return = ()> { move || { if let Ok(quux) = foo2(&baz) { yield quux; @@ -30,7 +30,7 @@ fn bar2(baz: String) -> impl Generator<(), Yield = String, Return = ()> { fn main() { assert_eq!( Pin::new(&mut bar(String::new())).resume(()), - GeneratorState::Yielded(String::new()) + CoroutineState::Yielded(String::new()) ); - assert_eq!(Pin::new(&mut bar2(String::new())).resume(()), GeneratorState::Complete(())); + assert_eq!(Pin::new(&mut bar2(String::new())).resume(()), CoroutineState::Complete(())); } diff --git a/tests/ui/generator/issue-45729-unsafe-in-generator.mir.stderr b/tests/ui/coroutine/issue-45729-unsafe-in-coroutine.mir.stderr similarity index 90% rename from tests/ui/generator/issue-45729-unsafe-in-generator.mir.stderr rename to tests/ui/coroutine/issue-45729-unsafe-in-coroutine.mir.stderr index 3afbea07931d4..a9a0d6296065b 100644 --- a/tests/ui/generator/issue-45729-unsafe-in-generator.mir.stderr +++ b/tests/ui/coroutine/issue-45729-unsafe-in-coroutine.mir.stderr @@ -1,5 +1,5 @@ error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/issue-45729-unsafe-in-generator.rs:8:9 + --> $DIR/issue-45729-unsafe-in-coroutine.rs:8:9 | LL | *(1 as *mut u32) = 42; | ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer diff --git a/tests/ui/generator/issue-45729-unsafe-in-generator.rs b/tests/ui/coroutine/issue-45729-unsafe-in-coroutine.rs similarity index 89% rename from tests/ui/generator/issue-45729-unsafe-in-generator.rs rename to tests/ui/coroutine/issue-45729-unsafe-in-coroutine.rs index 379c36d2ca321..7961b58597c4a 100644 --- a/tests/ui/generator/issue-45729-unsafe-in-generator.rs +++ b/tests/ui/coroutine/issue-45729-unsafe-in-coroutine.rs @@ -1,7 +1,7 @@ // revisions: mir thir // [thir]compile-flags: -Z thir-unsafeck -#![feature(generators)] +#![feature(coroutines)] fn main() { let _ = || { diff --git a/tests/ui/generator/issue-45729-unsafe-in-generator.thir.stderr b/tests/ui/coroutine/issue-45729-unsafe-in-coroutine.thir.stderr similarity index 90% rename from tests/ui/generator/issue-45729-unsafe-in-generator.thir.stderr rename to tests/ui/coroutine/issue-45729-unsafe-in-coroutine.thir.stderr index 10d768f19fc72..22c83e9a3d5a3 100644 --- a/tests/ui/generator/issue-45729-unsafe-in-generator.thir.stderr +++ b/tests/ui/coroutine/issue-45729-unsafe-in-coroutine.thir.stderr @@ -1,5 +1,5 @@ error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/issue-45729-unsafe-in-generator.rs:8:9 + --> $DIR/issue-45729-unsafe-in-coroutine.rs:8:9 | LL | *(1 as *mut u32) = 42; | ^^^^^^^^^^^^^^^^ dereference of raw pointer diff --git a/tests/ui/generator/issue-48048.rs b/tests/ui/coroutine/issue-48048.rs similarity index 52% rename from tests/ui/generator/issue-48048.rs rename to tests/ui/coroutine/issue-48048.rs index 992bbc97a9f17..b61b7c7707235 100644 --- a/tests/ui/generator/issue-48048.rs +++ b/tests/ui/coroutine/issue-48048.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] fn main() { let x = (|_| {},); @@ -6,7 +6,7 @@ fn main() { || { let x = x; - x.0({ //~ ERROR borrow may still be in use when generator yields + x.0({ //~ ERROR borrow may still be in use when coroutine yields yield; }); }; diff --git a/tests/ui/generator/issue-48048.stderr b/tests/ui/coroutine/issue-48048.stderr similarity index 80% rename from tests/ui/generator/issue-48048.stderr rename to tests/ui/coroutine/issue-48048.stderr index 234235839164c..bb9f189fa7c62 100644 --- a/tests/ui/generator/issue-48048.stderr +++ b/tests/ui/coroutine/issue-48048.stderr @@ -1,4 +1,4 @@ -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/issue-48048.rs:9:9 | LL | x.0({ diff --git a/tests/ui/coroutine/issue-52304.rs b/tests/ui/coroutine/issue-52304.rs new file mode 100644 index 0000000000000..fed3a5f19b3ac --- /dev/null +++ b/tests/ui/coroutine/issue-52304.rs @@ -0,0 +1,11 @@ +// check-pass + +#![feature(coroutines, coroutine_trait)] + +use std::ops::Coroutine; + +pub fn example() -> impl Coroutine { + || yield &1 +} + +fn main() {} diff --git a/tests/ui/generator/issue-52398.rs b/tests/ui/coroutine/issue-52398.rs similarity index 76% rename from tests/ui/generator/issue-52398.rs rename to tests/ui/coroutine/issue-52398.rs index ada380d116cab..8d651d0e2ce77 100644 --- a/tests/ui/generator/issue-52398.rs +++ b/tests/ui/coroutine/issue-52398.rs @@ -1,7 +1,7 @@ // run-pass #![allow(unused_variables)] -#![feature(generators)] +#![feature(coroutines)] use std::cell::RefCell; @@ -14,14 +14,14 @@ impl A { fn main() { // Test that the MIR local with type &A created for the auto-borrow adjustment // is caught by typeck - move || { //~ WARN unused generator that must be used + move || { //~ WARN unused coroutine that must be used A.test(yield); }; // Test that the std::cell::Ref temporary returned from the `borrow` call // is caught by typeck let y = RefCell::new(true); - static move || { //~ WARN unused generator that must be used + static move || { //~ WARN unused coroutine that must be used yield *y.borrow(); return "Done"; }; diff --git a/tests/ui/generator/issue-52398.stderr b/tests/ui/coroutine/issue-52398.stderr similarity index 63% rename from tests/ui/generator/issue-52398.stderr rename to tests/ui/coroutine/issue-52398.stderr index 539343275df60..18d816da4c611 100644 --- a/tests/ui/generator/issue-52398.stderr +++ b/tests/ui/coroutine/issue-52398.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/issue-52398.rs:17:5 | LL | / move || { @@ -6,10 +6,10 @@ LL | | A.test(yield); LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/issue-52398.rs:24:5 | LL | / static move || { @@ -18,7 +18,7 @@ LL | | return "Done"; LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed warning: 2 warnings emitted diff --git a/tests/ui/generator/issue-53548-1.rs b/tests/ui/coroutine/issue-53548-1.rs similarity index 84% rename from tests/ui/generator/issue-53548-1.rs rename to tests/ui/coroutine/issue-53548-1.rs index 173ae3c6fb6b7..4be8e95f3e744 100644 --- a/tests/ui/generator/issue-53548-1.rs +++ b/tests/ui/coroutine/issue-53548-1.rs @@ -1,4 +1,4 @@ -// A variant of #53548 that does not actually require generators, +// A variant of #53548 that does not actually require coroutines, // but which encountered the same ICE/error. See `issue-53548.rs` // for details. // diff --git a/tests/ui/generator/issue-53548.rs b/tests/ui/coroutine/issue-53548.rs similarity index 93% rename from tests/ui/generator/issue-53548.rs rename to tests/ui/coroutine/issue-53548.rs index 3ebabb914622c..bb267f74ae287 100644 --- a/tests/ui/generator/issue-53548.rs +++ b/tests/ui/coroutine/issue-53548.rs @@ -1,5 +1,5 @@ // Regression test for #53548. The `Box` type below is -// expanded to `Box`, but the generator "witness" +// expanded to `Box`, but the coroutine "witness" // that results is `for<'r> { Box }`. The WF code was // encountering an ICE (when debug-assertions were enabled) and an // unexpected compilation error (without debug-asserions) when trying @@ -17,7 +17,7 @@ // // check-pass -#![feature(generators)] +#![feature(coroutines)] use std::cell::RefCell; use std::rc::Rc; diff --git a/tests/ui/generator/issue-57017.rs b/tests/ui/coroutine/issue-57017.rs similarity index 97% rename from tests/ui/generator/issue-57017.rs rename to tests/ui/coroutine/issue-57017.rs index bb2d6679b6763..4f63abbdb1072 100644 --- a/tests/ui/generator/issue-57017.rs +++ b/tests/ui/coroutine/issue-57017.rs @@ -1,5 +1,5 @@ // build-pass -#![feature(generators, negative_impls)] +#![feature(coroutines, negative_impls)] #![allow(dropping_references, dropping_copy_types)] macro_rules! type_combinations { diff --git a/tests/ui/generator/issue-57084.rs b/tests/ui/coroutine/issue-57084.rs similarity index 73% rename from tests/ui/generator/issue-57084.rs rename to tests/ui/coroutine/issue-57084.rs index fbed78ff28047..95bed5b151ea3 100644 --- a/tests/ui/generator/issue-57084.rs +++ b/tests/ui/coroutine/issue-57084.rs @@ -2,10 +2,10 @@ // "cannot relate bound region: ReLateBound(DebruijnIndex(1), BrAnon(1)) <= '?1" // run-pass // edition:2018 -#![feature(generators,generator_trait)] -use std::ops::Generator; +#![feature(coroutines,coroutine_trait)] +use std::ops::Coroutine; -fn with(f: F) -> impl Generator +fn with(f: F) -> impl Coroutine where F: Fn() -> () { move || { @@ -19,7 +19,7 @@ where F: Fn() -> () fn main() { let data = &vec![1]; - || { //~ WARN unused generator that must be used + || { //~ WARN unused coroutine that must be used let _to_pin = with(move || println!("{:p}", data)); loop { yield diff --git a/tests/ui/generator/issue-57084.stderr b/tests/ui/coroutine/issue-57084.stderr similarity index 73% rename from tests/ui/generator/issue-57084.stderr rename to tests/ui/coroutine/issue-57084.stderr index 8f1fc5e803194..9f5b79a6ae8af 100644 --- a/tests/ui/generator/issue-57084.stderr +++ b/tests/ui/coroutine/issue-57084.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/issue-57084.rs:22:5 | LL | / || { @@ -9,7 +9,7 @@ LL | | } LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/generator/issue-57478.rs b/tests/ui/coroutine/issue-57478.rs similarity index 82% rename from tests/ui/generator/issue-57478.rs rename to tests/ui/coroutine/issue-57478.rs index 39710febdb95c..716e4c67b8727 100644 --- a/tests/ui/generator/issue-57478.rs +++ b/tests/ui/coroutine/issue-57478.rs @@ -1,6 +1,6 @@ // check-pass -#![feature(negative_impls, generators)] +#![feature(negative_impls, coroutines)] struct Foo; impl !Send for Foo {} diff --git a/tests/ui/generator/issue-58888.rs b/tests/ui/coroutine/issue-58888.rs similarity index 76% rename from tests/ui/generator/issue-58888.rs rename to tests/ui/coroutine/issue-58888.rs index d42d09d401e87..af8e60ce460cd 100644 --- a/tests/ui/generator/issue-58888.rs +++ b/tests/ui/coroutine/issue-58888.rs @@ -2,9 +2,9 @@ // compile-flags: -g // ignore-asmjs wasm2js does not support source maps yet -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; struct Database; @@ -13,7 +13,7 @@ impl Database { Some(()).into_iter() } - fn check_connection(&self) -> impl Generator + '_ { + fn check_connection(&self) -> impl Coroutine + '_ { move || { let iter = self.get_connection(); for i in iter { diff --git a/tests/ui/generator/issue-61442-stmt-expr-with-drop.rs b/tests/ui/coroutine/issue-61442-stmt-expr-with-drop.rs similarity index 87% rename from tests/ui/generator/issue-61442-stmt-expr-with-drop.rs rename to tests/ui/coroutine/issue-61442-stmt-expr-with-drop.rs index 187c374021dca..cff6c24a83fbd 100644 --- a/tests/ui/generator/issue-61442-stmt-expr-with-drop.rs +++ b/tests/ui/coroutine/issue-61442-stmt-expr-with-drop.rs @@ -4,9 +4,9 @@ // check-pass // edition:2018 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; async fn drop_and_await() { async {}; diff --git a/tests/ui/generator/issue-62506-two_awaits.rs b/tests/ui/coroutine/issue-62506-two_awaits.rs similarity index 85% rename from tests/ui/generator/issue-62506-two_awaits.rs rename to tests/ui/coroutine/issue-62506-two_awaits.rs index 672e16b780d03..b50e2a45c588f 100644 --- a/tests/ui/generator/issue-62506-two_awaits.rs +++ b/tests/ui/coroutine/issue-62506-two_awaits.rs @@ -1,5 +1,5 @@ // Output = String caused an ICE whereas Output = &'static str compiled successfully. -// Broken MIR: generator contains type std::string::String in MIR, +// Broken MIR: coroutine contains type std::string::String in MIR, // but typeck only knows about {::Future, ()} // check-pass // edition:2018 diff --git a/tests/ui/coroutine/issue-64620-yield-array-element.rs b/tests/ui/coroutine/issue-64620-yield-array-element.rs new file mode 100644 index 0000000000000..a9307d306a617 --- /dev/null +++ b/tests/ui/coroutine/issue-64620-yield-array-element.rs @@ -0,0 +1,9 @@ +// Regression test for #64620 + +#![feature(coroutines)] + +pub fn crash(arr: [usize; 1]) { + yield arr[0]; //~ ERROR: yield expression outside of coroutine literal +} + +fn main() {} diff --git a/tests/ui/generator/issue-64620-yield-array-element.stderr b/tests/ui/coroutine/issue-64620-yield-array-element.stderr similarity index 77% rename from tests/ui/generator/issue-64620-yield-array-element.stderr rename to tests/ui/coroutine/issue-64620-yield-array-element.stderr index 48383c2ed0824..47632d083ea32 100644 --- a/tests/ui/generator/issue-64620-yield-array-element.stderr +++ b/tests/ui/coroutine/issue-64620-yield-array-element.stderr @@ -1,4 +1,4 @@ -error[E0627]: yield expression outside of generator literal +error[E0627]: yield expression outside of coroutine literal --> $DIR/issue-64620-yield-array-element.rs:6:5 | LL | yield arr[0]; diff --git a/tests/ui/generator/issue-68112.rs b/tests/ui/coroutine/issue-68112.rs similarity index 64% rename from tests/ui/generator/issue-68112.rs rename to tests/ui/coroutine/issue-68112.rs index 9dd68726f9288..e2be704dab738 100644 --- a/tests/ui/generator/issue-68112.rs +++ b/tests/ui/coroutine/issue-68112.rs @@ -1,18 +1,18 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::{ cell::RefCell, sync::Arc, pin::Pin, - ops::{Generator, GeneratorState}, + ops::{Coroutine, CoroutineState}, }; pub struct Ready(Option); -impl Generator<()> for Ready { +impl Coroutine<()> for Ready { type Return = T; type Yield = (); - fn resume(mut self: Pin<&mut Self>, _args: ()) -> GeneratorState<(), T> { - GeneratorState::Complete(self.0.take().unwrap()) + fn resume(mut self: Pin<&mut Self>, _args: ()) -> CoroutineState<(), T> { + CoroutineState::Complete(self.0.take().unwrap()) } } pub fn make_gen1(t: T) -> Ready { @@ -25,40 +25,40 @@ fn require_send(_: impl Send) {} //~| NOTE required by this bound //~| NOTE required by this bound -fn make_non_send_generator() -> impl Generator>> { +fn make_non_send_coroutine() -> impl Coroutine>> { make_gen1(Arc::new(RefCell::new(0))) } fn test1() { let send_gen = || { - let _non_send_gen = make_non_send_generator(); + let _non_send_gen = make_non_send_coroutine(); //~^ NOTE not `Send` yield; //~^ NOTE yield occurs here //~| NOTE value is used across a yield }; require_send(send_gen); - //~^ ERROR generator cannot be sent between threads + //~^ ERROR coroutine cannot be sent between threads //~| NOTE not `Send` //~| NOTE use `std::sync::RwLock` instead } -pub fn make_gen2(t: T) -> impl Generator { +pub fn make_gen2(t: T) -> impl Coroutine { //~^ NOTE appears within the type //~| NOTE expansion of desugaring - || { //~ NOTE used within this generator + || { //~ NOTE used within this coroutine yield; t } } -fn make_non_send_generator2() -> impl Generator>> { //~ NOTE appears within the type +fn make_non_send_coroutine2() -> impl Coroutine>> { //~ NOTE appears within the type //~^ NOTE expansion of desugaring make_gen2(Arc::new(RefCell::new(0))) } fn test2() { - let send_gen = || { //~ NOTE used within this generator - let _non_send_gen = make_non_send_generator2(); + let send_gen = || { //~ NOTE used within this coroutine + let _non_send_gen = make_non_send_coroutine2(); yield; }; require_send(send_gen); diff --git a/tests/ui/generator/issue-68112.stderr b/tests/ui/coroutine/issue-68112.stderr similarity index 70% rename from tests/ui/generator/issue-68112.stderr rename to tests/ui/coroutine/issue-68112.stderr index 8080048222ffb..5efa72ad5fe02 100644 --- a/tests/ui/generator/issue-68112.stderr +++ b/tests/ui/coroutine/issue-68112.stderr @@ -1,16 +1,16 @@ -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/issue-68112.rs:40:5 | LL | require_send(send_gen); - | ^^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^^ coroutine is not `Send` | = help: the trait `Sync` is not implemented for `RefCell` = note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead -note: generator is not `Send` as this value is used across a yield +note: coroutine is not `Send` as this value is used across a yield --> $DIR/issue-68112.rs:36:9 | -LL | let _non_send_gen = make_non_send_generator(); - | ------------- has type `impl Generator>>` which is not `Send` +LL | let _non_send_gen = make_non_send_coroutine(); + | ------------- has type `impl Coroutine>>` which is not `Send` LL | LL | yield; | ^^^^^ yield occurs here, with `_non_send_gen` maybe used later @@ -29,23 +29,23 @@ LL | require_send(send_gen); = help: the trait `Sync` is not implemented for `RefCell` = note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead = note: required for `Arc>` to implement `Send` -note: required because it's used within this generator +note: required because it's used within this coroutine --> $DIR/issue-68112.rs:49:5 | LL | || { | ^^ -note: required because it appears within the type `impl Generator>>` +note: required because it appears within the type `impl Coroutine>>` --> $DIR/issue-68112.rs:46:30 | -LL | pub fn make_gen2(t: T) -> impl Generator { +LL | pub fn make_gen2(t: T) -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: required because it appears within the type `impl Generator>>` +note: required because it appears within the type `impl Coroutine>>` --> $DIR/issue-68112.rs:54:34 | -LL | fn make_non_send_generator2() -> impl Generator>> { +LL | fn make_non_send_coroutine2() -> impl Coroutine>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `impl Generator>>` -note: required because it's used within this generator + = note: required because it captures the following types: `impl Coroutine>>` +note: required because it's used within this coroutine --> $DIR/issue-68112.rs:60:20 | LL | let send_gen = || { diff --git a/tests/ui/generator/issue-69017.rs b/tests/ui/coroutine/issue-69017.rs similarity index 70% rename from tests/ui/generator/issue-69017.rs rename to tests/ui/coroutine/issue-69017.rs index 511deb60e4553..7aaa1ee03c4bc 100644 --- a/tests/ui/generator/issue-69017.rs +++ b/tests/ui/coroutine/issue-69017.rs @@ -4,12 +4,12 @@ // // check-pass -#![feature(generator_trait)] -#![feature(generators)] +#![feature(coroutine_trait)] +#![feature(coroutines)] -use std::ops::Generator; +use std::ops::Coroutine; -fn gen() -> impl Generator { +fn gen() -> impl Coroutine { |_: usize| { println!("-> {}", yield); } diff --git a/tests/ui/generator/issue-69039.rs b/tests/ui/coroutine/issue-69039.rs similarity index 66% rename from tests/ui/generator/issue-69039.rs rename to tests/ui/coroutine/issue-69039.rs index ccc141860aa5f..041985e15a332 100644 --- a/tests/ui/generator/issue-69039.rs +++ b/tests/ui/coroutine/issue-69039.rs @@ -1,14 +1,14 @@ // run-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; fn mkstr(my_name: String, my_mood: String) -> String { format!("{} is {}", my_name.trim(), my_mood.trim()) } -fn my_scenario() -> impl Generator { +fn my_scenario() -> impl Coroutine { |_arg: String| { let my_name = yield "What is your name?"; let my_mood = yield "How are you feeling?"; @@ -21,14 +21,14 @@ fn main() { assert_eq!( my_session.as_mut().resume("_arg".to_string()), - GeneratorState::Yielded("What is your name?") + CoroutineState::Yielded("What is your name?") ); assert_eq!( my_session.as_mut().resume("Your Name".to_string()), - GeneratorState::Yielded("How are you feeling?") + CoroutineState::Yielded("How are you feeling?") ); assert_eq!( my_session.as_mut().resume("Sensory Organs".to_string()), - GeneratorState::Complete("Your Name is Sensory Organs".to_string()) + CoroutineState::Complete("Your Name is Sensory Organs".to_string()) ); } diff --git a/tests/ui/coroutine/issue-87142.rs b/tests/ui/coroutine/issue-87142.rs new file mode 100644 index 0000000000000..b5708c4b385d0 --- /dev/null +++ b/tests/ui/coroutine/issue-87142.rs @@ -0,0 +1,32 @@ +// compile-flags: -Cdebuginfo=2 +// build-pass + +// Regression test for #87142 +// This test needs the above flags and the "lib" crate type. + +#![feature(impl_trait_in_assoc_type, coroutine_trait, coroutines)] +#![crate_type = "lib"] + +use std::ops::Coroutine; + +pub trait CoroutineProviderAlt: Sized { + type Coro: Coroutine<(), Return = (), Yield = ()>; + + fn start(ctx: Context) -> Self::Coro; +} + +pub struct Context { + pub link: Box, +} + +impl CoroutineProviderAlt for () { + type Coro = impl Coroutine<(), Return = (), Yield = ()>; + fn start(ctx: Context) -> Self::Coro { + move || { + match ctx { + _ => (), + } + yield (); + } + } +} diff --git a/tests/ui/generator/issue-88653.rs b/tests/ui/coroutine/issue-88653.rs similarity index 55% rename from tests/ui/generator/issue-88653.rs rename to tests/ui/coroutine/issue-88653.rs index 1d9377bcef4de..ec4c205475877 100644 --- a/tests/ui/generator/issue-88653.rs +++ b/tests/ui/coroutine/issue-88653.rs @@ -1,14 +1,14 @@ // Regression test for #88653, where a confusing warning about a -// type mismatch in generator arguments was issued. +// type mismatch in coroutine arguments was issued. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; -fn foo(bar: bool) -> impl Generator<(bool,)> { - //~^ ERROR: type mismatch in generator arguments [E0631] +fn foo(bar: bool) -> impl Coroutine<(bool,)> { + //~^ ERROR: type mismatch in coroutine arguments [E0631] //~| NOTE: expected due to this - //~| NOTE: expected generator signature `fn((bool,)) -> _` + //~| NOTE: expected coroutine signature `fn((bool,)) -> _` //~| NOTE: in this expansion of desugaring of `impl Trait` //~| NOTE: in this expansion of desugaring of `impl Trait` |bar| { diff --git a/tests/ui/generator/issue-88653.stderr b/tests/ui/coroutine/issue-88653.stderr similarity index 56% rename from tests/ui/generator/issue-88653.stderr rename to tests/ui/coroutine/issue-88653.stderr index b742c6e2f1c08..3ae50b5aff284 100644 --- a/tests/ui/generator/issue-88653.stderr +++ b/tests/ui/coroutine/issue-88653.stderr @@ -1,14 +1,14 @@ -error[E0631]: type mismatch in generator arguments +error[E0631]: type mismatch in coroutine arguments --> $DIR/issue-88653.rs:8:22 | -LL | fn foo(bar: bool) -> impl Generator<(bool,)> { +LL | fn foo(bar: bool) -> impl Coroutine<(bool,)> { | ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this ... LL | |bar| { | ----- found signature defined here | - = note: expected generator signature `fn((bool,)) -> _` - found generator signature `fn(bool) -> _` + = note: expected coroutine signature `fn((bool,)) -> _` + found coroutine signature `fn(bool) -> _` error: aborting due to previous error diff --git a/tests/ui/generator/issue-91477.rs b/tests/ui/coroutine/issue-91477.rs similarity index 74% rename from tests/ui/generator/issue-91477.rs rename to tests/ui/coroutine/issue-91477.rs index 6c027feb422d1..c98546f7971cf 100644 --- a/tests/ui/generator/issue-91477.rs +++ b/tests/ui/coroutine/issue-91477.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] fn foo() -> impl Sized { yield 1; //~ ERROR E0627 diff --git a/tests/ui/generator/issue-91477.stderr b/tests/ui/coroutine/issue-91477.stderr similarity index 74% rename from tests/ui/generator/issue-91477.stderr rename to tests/ui/coroutine/issue-91477.stderr index 4597dc1bcdfa5..0ab3c1fbabc5f 100644 --- a/tests/ui/generator/issue-91477.stderr +++ b/tests/ui/coroutine/issue-91477.stderr @@ -1,4 +1,4 @@ -error[E0627]: yield expression outside of generator literal +error[E0627]: yield expression outside of coroutine literal --> $DIR/issue-91477.rs:4:5 | LL | yield 1; diff --git a/tests/ui/generator/issue-93161.rs b/tests/ui/coroutine/issue-93161.rs similarity index 100% rename from tests/ui/generator/issue-93161.rs rename to tests/ui/coroutine/issue-93161.rs diff --git a/tests/ui/generator/iterator-count.rs b/tests/ui/coroutine/iterator-count.rs similarity index 60% rename from tests/ui/generator/iterator-count.rs rename to tests/ui/coroutine/iterator-count.rs index 90eefe02f664e..322e56f8a8b32 100644 --- a/tests/ui/generator/iterator-count.rs +++ b/tests/ui/coroutine/iterator-count.rs @@ -1,27 +1,27 @@ // run-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::marker::Unpin; -use std::ops::{GeneratorState, Generator}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; struct W(T); -// This impl isn't safe in general, but the generator used in this test is movable +// This impl isn't safe in general, but the coroutine used in this test is movable // so it won't cause problems. -impl + Unpin> Iterator for W { +impl + Unpin> Iterator for W { type Item = T::Yield; fn next(&mut self) -> Option { match Pin::new(&mut self.0).resume(()) { - GeneratorState::Complete(..) => None, - GeneratorState::Yielded(v) => Some(v), + CoroutineState::Complete(..) => None, + CoroutineState::Yielded(v) => Some(v), } } } -fn test() -> impl Generator<(), Return=(), Yield=u8> + Unpin { +fn test() -> impl Coroutine<(), Return = (), Yield = u8> + Unpin { || { for i in 1..6 { yield i diff --git a/tests/ui/generator/layout-error.rs b/tests/ui/coroutine/layout-error.rs similarity index 90% rename from tests/ui/generator/layout-error.rs rename to tests/ui/coroutine/layout-error.rs index 7c3d187409a2f..87da60700a4be 100644 --- a/tests/ui/generator/layout-error.rs +++ b/tests/ui/coroutine/layout-error.rs @@ -1,4 +1,4 @@ -// Verifies that computing a layout of a generator tainted by type errors +// Verifies that computing a layout of a coroutine tainted by type errors // doesn't ICE. Regression test for #80998. // // edition:2018 diff --git a/tests/ui/generator/layout-error.stderr b/tests/ui/coroutine/layout-error.stderr similarity index 100% rename from tests/ui/generator/layout-error.stderr rename to tests/ui/coroutine/layout-error.stderr diff --git a/tests/ui/generator/live-upvar-across-yield.rs b/tests/ui/coroutine/live-upvar-across-yield.rs similarity index 68% rename from tests/ui/generator/live-upvar-across-yield.rs rename to tests/ui/coroutine/live-upvar-across-yield.rs index 6a2e42a5573a8..740a446e737ef 100644 --- a/tests/ui/generator/live-upvar-across-yield.rs +++ b/tests/ui/coroutine/live-upvar-across-yield.rs @@ -1,8 +1,8 @@ // run-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/ui/generator/match-bindings.rs b/tests/ui/coroutine/match-bindings.rs similarity index 80% rename from tests/ui/generator/match-bindings.rs rename to tests/ui/coroutine/match-bindings.rs index 865904a57d41c..1a5b3cdb0268e 100644 --- a/tests/ui/generator/match-bindings.rs +++ b/tests/ui/coroutine/match-bindings.rs @@ -1,7 +1,7 @@ // run-pass #![allow(dead_code)] -#![feature(generators)] +#![feature(coroutines)] enum Enum { A(String), @@ -9,7 +9,7 @@ enum Enum { } fn main() { - || { //~ WARN unused generator that must be used + || { //~ WARN unused coroutine that must be used loop { if let true = true { match Enum::A(String::new()) { diff --git a/tests/ui/generator/match-bindings.stderr b/tests/ui/coroutine/match-bindings.stderr similarity index 74% rename from tests/ui/generator/match-bindings.stderr rename to tests/ui/coroutine/match-bindings.stderr index 3dd2d595445aa..a7aa6eadb95f1 100644 --- a/tests/ui/generator/match-bindings.stderr +++ b/tests/ui/coroutine/match-bindings.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/match-bindings.rs:12:5 | LL | / || { @@ -10,7 +10,7 @@ LL | | } LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/generator/metadata-sufficient-for-layout.rs b/tests/ui/coroutine/metadata-sufficient-for-layout.rs similarity index 61% rename from tests/ui/generator/metadata-sufficient-for-layout.rs rename to tests/ui/coroutine/metadata-sufficient-for-layout.rs index d0e648ee775fa..434a2801597af 100644 --- a/tests/ui/generator/metadata-sufficient-for-layout.rs +++ b/tests/ui/coroutine/metadata-sufficient-for-layout.rs @@ -1,4 +1,4 @@ -// Check that the layout of a generator is available when auxiliary crate +// Check that the layout of a coroutine is available when auxiliary crate // is compiled with --emit metadata. // // Regression test for #80998. @@ -6,15 +6,15 @@ // aux-build:metadata-sufficient-for-layout.rs #![feature(type_alias_impl_trait, rustc_attrs)] -#![feature(generator_trait)] +#![feature(coroutine_trait)] extern crate metadata_sufficient_for_layout; -use std::ops::Generator; +use std::ops::Coroutine; -type F = impl Generator<(), Yield = (), Return = ()>; +type F = impl Coroutine<(), Yield = (), Return = ()>; -// Static queries the layout of the generator. +// Static queries the layout of the coroutine. static A: Option = None; fn f() -> F { diff --git a/tests/ui/generator/metadata-sufficient-for-layout.stderr b/tests/ui/coroutine/metadata-sufficient-for-layout.stderr similarity index 100% rename from tests/ui/generator/metadata-sufficient-for-layout.stderr rename to tests/ui/coroutine/metadata-sufficient-for-layout.stderr diff --git a/tests/ui/coroutine/nested_coroutine.rs b/tests/ui/coroutine/nested_coroutine.rs new file mode 100644 index 0000000000000..04f4aa7715356 --- /dev/null +++ b/tests/ui/coroutine/nested_coroutine.rs @@ -0,0 +1,21 @@ +// run-pass + +#![feature(coroutines, coroutine_trait)] + +use std::ops::{Coroutine, CoroutineState}; +use std::pin::Pin; + +fn main() { + let _coroutine = || { + let mut sub_coroutine = || { + yield 2; + }; + + match Pin::new(&mut sub_coroutine).resume(()) { + CoroutineState::Yielded(x) => { + yield x; + } + _ => panic!(), + }; + }; +} diff --git a/tests/ui/generator/niche-in-generator.rs b/tests/ui/coroutine/niche-in-coroutine.rs similarity index 71% rename from tests/ui/generator/niche-in-generator.rs rename to tests/ui/coroutine/niche-in-coroutine.rs index 42bee81f524c5..7ad4c6bc98aca 100644 --- a/tests/ui/generator/niche-in-generator.rs +++ b/tests/ui/coroutine/niche-in-coroutine.rs @@ -1,8 +1,8 @@ -// Test that niche finding works with captured generator upvars. +// Test that niche finding works with captured coroutine upvars. // run-pass -#![feature(generators)] +#![feature(coroutines)] use std::mem::size_of_val; diff --git a/tests/ui/generator/non-static-is-unpin.rs b/tests/ui/coroutine/non-static-is-unpin.rs similarity index 77% rename from tests/ui/generator/non-static-is-unpin.rs rename to tests/ui/coroutine/non-static-is-unpin.rs index a5dde3912cc00..d6ded53ae5a29 100644 --- a/tests/ui/generator/non-static-is-unpin.rs +++ b/tests/ui/coroutine/non-static-is-unpin.rs @@ -2,7 +2,7 @@ //[next] compile-flags: -Ztrait-solver=next // run-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] #![allow(dropping_copy_types)] use std::marker::{PhantomPinned, Unpin}; @@ -11,7 +11,7 @@ fn assert_unpin(_: G) { } fn main() { - // Even though this generator holds a `PhantomPinned` in its environment, it + // Even though this coroutine holds a `PhantomPinned` in its environment, it // remains `Unpin`. assert_unpin(|| { let pinned = PhantomPinned; diff --git a/tests/ui/generator/not-send-sync.rs b/tests/ui/coroutine/not-send-sync.rs similarity index 71% rename from tests/ui/generator/not-send-sync.rs rename to tests/ui/coroutine/not-send-sync.rs index 16c8cd476291c..dd6182c10de09 100644 --- a/tests/ui/generator/not-send-sync.rs +++ b/tests/ui/coroutine/not-send-sync.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![feature(negative_impls)] struct NotSend; @@ -12,14 +12,14 @@ fn main() { fn assert_send(_: T) {} assert_sync(|| { - //~^ ERROR: generator cannot be shared between threads safely + //~^ ERROR: coroutine cannot be shared between threads safely let a = NotSync; yield; drop(a); }); assert_send(|| { - //~^ ERROR: generator cannot be sent between threads safely + //~^ ERROR: coroutine cannot be sent between threads safely let a = NotSend; yield; drop(a); diff --git a/tests/ui/generator/not-send-sync.stderr b/tests/ui/coroutine/not-send-sync.stderr similarity index 70% rename from tests/ui/generator/not-send-sync.stderr rename to tests/ui/coroutine/not-send-sync.stderr index 13ce687e0bb45..b33a1e63aafd2 100644 --- a/tests/ui/generator/not-send-sync.stderr +++ b/tests/ui/coroutine/not-send-sync.stderr @@ -1,11 +1,11 @@ -error: generator cannot be shared between threads safely +error: coroutine cannot be shared between threads safely --> $DIR/not-send-sync.rs:14:5 | LL | assert_sync(|| { - | ^^^^^^^^^^^ generator is not `Sync` + | ^^^^^^^^^^^ coroutine is not `Sync` | - = help: within `{generator@$DIR/not-send-sync.rs:14:17: 14:19}`, the trait `Sync` is not implemented for `NotSync` -note: generator is not `Sync` as this value is used across a yield + = help: within `{coroutine@$DIR/not-send-sync.rs:14:17: 14:19}`, the trait `Sync` is not implemented for `NotSync` +note: coroutine is not `Sync` as this value is used across a yield --> $DIR/not-send-sync.rs:17:9 | LL | let a = NotSync; @@ -18,14 +18,14 @@ note: required by a bound in `assert_sync` LL | fn assert_sync(_: T) {} | ^^^^ required by this bound in `assert_sync` -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/not-send-sync.rs:21:5 | LL | assert_send(|| { - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` | - = help: within `{generator@$DIR/not-send-sync.rs:21:17: 21:19}`, the trait `Send` is not implemented for `NotSend` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/not-send-sync.rs:21:17: 21:19}`, the trait `Send` is not implemented for `NotSend` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/not-send-sync.rs:24:9 | LL | let a = NotSend; diff --git a/tests/ui/generator/overlap-locals.rs b/tests/ui/coroutine/overlap-locals.rs similarity index 95% rename from tests/ui/generator/overlap-locals.rs rename to tests/ui/coroutine/overlap-locals.rs index 101c8714fa870..7c151270bb55d 100644 --- a/tests/ui/generator/overlap-locals.rs +++ b/tests/ui/coroutine/overlap-locals.rs @@ -1,6 +1,6 @@ // run-pass -#![feature(generators)] +#![feature(coroutines)] fn main() { let a = || { diff --git a/tests/ui/generator/panic-drops-resume.rs b/tests/ui/coroutine/panic-drops-resume.rs similarity index 84% rename from tests/ui/generator/panic-drops-resume.rs rename to tests/ui/coroutine/panic-drops-resume.rs index 4c3caeb14d67e..e866f216a247f 100644 --- a/tests/ui/generator/panic-drops-resume.rs +++ b/tests/ui/coroutine/panic-drops-resume.rs @@ -1,11 +1,11 @@ -//! Tests that panics inside a generator will correctly drop the initial resume argument. +//! Tests that panics inside a coroutine will correctly drop the initial resume argument. // run-pass // needs-unwind -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/tests/ui/generator/panic-drops.rs b/tests/ui/coroutine/panic-drops.rs similarity index 93% rename from tests/ui/generator/panic-drops.rs rename to tests/ui/coroutine/panic-drops.rs index 65001fd879bb0..7e37279b9eb8d 100644 --- a/tests/ui/generator/panic-drops.rs +++ b/tests/ui/coroutine/panic-drops.rs @@ -2,9 +2,9 @@ // needs-unwind -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::panic; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/tests/ui/generator/panic-safe.rs b/tests/ui/coroutine/panic-safe.rs similarity index 88% rename from tests/ui/generator/panic-safe.rs rename to tests/ui/coroutine/panic-safe.rs index 3db80bb582151..9aa427565449f 100644 --- a/tests/ui/generator/panic-safe.rs +++ b/tests/ui/coroutine/panic-safe.rs @@ -2,9 +2,9 @@ // needs-unwind -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; use std::panic; diff --git a/tests/ui/generator/parent-expression.rs b/tests/ui/coroutine/parent-expression.rs similarity index 97% rename from tests/ui/generator/parent-expression.rs rename to tests/ui/coroutine/parent-expression.rs index 198b14528aad5..4d40192c07a27 100644 --- a/tests/ui/generator/parent-expression.rs +++ b/tests/ui/coroutine/parent-expression.rs @@ -1,4 +1,4 @@ -#![feature(generators, negative_impls, rustc_attrs)] +#![feature(coroutines, negative_impls, rustc_attrs)] macro_rules! type_combinations { ( diff --git a/tests/ui/generator/parent-expression.stderr b/tests/ui/coroutine/parent-expression.stderr similarity index 86% rename from tests/ui/generator/parent-expression.stderr rename to tests/ui/coroutine/parent-expression.stderr index 25a3b051b1f0a..6b611bc3f103e 100644 --- a/tests/ui/generator/parent-expression.stderr +++ b/tests/ui/coroutine/parent-expression.stderr @@ -1,8 +1,8 @@ -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/parent-expression.rs:23:13 | LL | assert_send(g); - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` ... LL | / type_combinations!( LL | | // OK @@ -13,8 +13,8 @@ LL | | }; LL | | ); | |_____- in this macro invocation | - = help: within `{generator@$DIR/parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `derived_drop::Client` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `derived_drop::Client` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/parent-expression.rs:21:22 | LL | let g = move || match drop($name::Client { ..$name::Client::default() }) { @@ -38,11 +38,11 @@ LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/parent-expression.rs:23:13 | LL | assert_send(g); - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` ... LL | / type_combinations!( LL | | // OK @@ -53,8 +53,8 @@ LL | | }; LL | | ); | |_____- in this macro invocation | - = help: within `{generator@$DIR/parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `significant_drop::Client` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `significant_drop::Client` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/parent-expression.rs:21:22 | LL | let g = move || match drop($name::Client { ..$name::Client::default() }) { @@ -78,11 +78,11 @@ LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/parent-expression.rs:23:13 | LL | assert_send(g); - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` ... LL | / type_combinations!( LL | | // OK @@ -93,8 +93,8 @@ LL | | }; LL | | ); | |_____- in this macro invocation | - = help: within `{generator@$DIR/parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `insignificant_dtor::Client` -note: generator is not `Send` as this value is used across a yield + = help: within `{coroutine@$DIR/parent-expression.rs:17:21: 17:28}`, the trait `Send` is not implemented for `insignificant_dtor::Client` +note: coroutine is not `Send` as this value is used across a yield --> $DIR/parent-expression.rs:21:22 | LL | let g = move || match drop($name::Client { ..$name::Client::default() }) { diff --git a/tests/ui/generator/partial-drop.rs b/tests/ui/coroutine/partial-drop.rs similarity index 93% rename from tests/ui/generator/partial-drop.rs rename to tests/ui/coroutine/partial-drop.rs index 868f36adce2c2..a4347f52a707d 100644 --- a/tests/ui/generator/partial-drop.rs +++ b/tests/ui/coroutine/partial-drop.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(negative_impls, generators)] +#![feature(negative_impls, coroutines)] struct Foo; impl !Send for Foo {} diff --git a/tests/ui/generator/partial-initialization-across-yield.rs b/tests/ui/coroutine/partial-initialization-across-yield.rs similarity index 87% rename from tests/ui/generator/partial-initialization-across-yield.rs rename to tests/ui/coroutine/partial-initialization-across-yield.rs index 65d9e6d39ca5a..75ad5a2280403 100644 --- a/tests/ui/generator/partial-initialization-across-yield.rs +++ b/tests/ui/coroutine/partial-initialization-across-yield.rs @@ -1,7 +1,7 @@ -// Test that we don't allow yielding from a generator while a local is partially +// Test that we don't allow yielding from a coroutine while a local is partially // initialized. -#![feature(generators)] +#![feature(coroutines)] struct S { x: i32, y: i32 } struct T(i32, i32); diff --git a/tests/ui/generator/partial-initialization-across-yield.stderr b/tests/ui/coroutine/partial-initialization-across-yield.stderr similarity index 100% rename from tests/ui/generator/partial-initialization-across-yield.stderr rename to tests/ui/coroutine/partial-initialization-across-yield.stderr diff --git a/tests/ui/generator/pattern-borrow.rs b/tests/ui/coroutine/pattern-borrow.rs similarity index 83% rename from tests/ui/generator/pattern-borrow.rs rename to tests/ui/coroutine/pattern-borrow.rs index d193637081938..76084433d4705 100644 --- a/tests/ui/generator/pattern-borrow.rs +++ b/tests/ui/coroutine/pattern-borrow.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] enum Test { A(i32), B, } @@ -6,7 +6,7 @@ fn main() { } fn fun(test: Test) { move || { - if let Test::A(ref _a) = test { //~ ERROR borrow may still be in use when generator yields + if let Test::A(ref _a) = test { //~ ERROR borrow may still be in use when coroutine yields yield (); _a.use_ref(); } diff --git a/tests/ui/generator/pattern-borrow.stderr b/tests/ui/coroutine/pattern-borrow.stderr similarity index 82% rename from tests/ui/generator/pattern-borrow.stderr rename to tests/ui/coroutine/pattern-borrow.stderr index d78da51049150..ddb3bf66214f8 100644 --- a/tests/ui/generator/pattern-borrow.stderr +++ b/tests/ui/coroutine/pattern-borrow.stderr @@ -1,4 +1,4 @@ -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/pattern-borrow.rs:9:24 | LL | if let Test::A(ref _a) = test { diff --git a/tests/ui/coroutine/pin-box-coroutine.rs b/tests/ui/coroutine/pin-box-coroutine.rs new file mode 100644 index 0000000000000..e348551a642fe --- /dev/null +++ b/tests/ui/coroutine/pin-box-coroutine.rs @@ -0,0 +1,13 @@ +// run-pass + +#![feature(coroutines, coroutine_trait)] + +use std::ops::Coroutine; + +fn assert_coroutine(_: G) { +} + +fn main() { + assert_coroutine(static || yield); + assert_coroutine(Box::pin(static || yield)); +} diff --git a/tests/ui/generator/print/generator-print-verbose-1.rs b/tests/ui/coroutine/print/coroutine-print-verbose-1.rs similarity index 52% rename from tests/ui/generator/print/generator-print-verbose-1.rs rename to tests/ui/coroutine/print/coroutine-print-verbose-1.rs index e52234c08a352..c47d7572ca77b 100644 --- a/tests/ui/generator/print/generator-print-verbose-1.rs +++ b/tests/ui/coroutine/print/coroutine-print-verbose-1.rs @@ -1,22 +1,22 @@ // compile-flags: -Zverbose -// Same as: tests/ui/generator/issue-68112.stderr +// Same as: tests/ui/coroutine/issue-68112.stderr -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::{ cell::RefCell, sync::Arc, pin::Pin, - ops::{Generator, GeneratorState}, + ops::{Coroutine, CoroutineState}, }; pub struct Ready(Option); -impl Generator<()> for Ready { +impl Coroutine<()> for Ready { type Return = T; type Yield = (); - fn resume(mut self: Pin<&mut Self>, _args: ()) -> GeneratorState<(), T> { - GeneratorState::Complete(self.0.take().unwrap()) + fn resume(mut self: Pin<&mut Self>, _args: ()) -> CoroutineState<(), T> { + CoroutineState::Complete(self.0.take().unwrap()) } } pub fn make_gen1(t: T) -> Ready { @@ -25,32 +25,32 @@ pub fn make_gen1(t: T) -> Ready { fn require_send(_: impl Send) {} -fn make_non_send_generator() -> impl Generator>> { +fn make_non_send_coroutine() -> impl Coroutine>> { make_gen1(Arc::new(RefCell::new(0))) } fn test1() { let send_gen = || { - let _non_send_gen = make_non_send_generator(); + let _non_send_gen = make_non_send_coroutine(); yield; }; require_send(send_gen); - //~^ ERROR generator cannot be sent between threads + //~^ ERROR coroutine cannot be sent between threads } -pub fn make_gen2(t: T) -> impl Generator { +pub fn make_gen2(t: T) -> impl Coroutine { || { yield; t } } -fn make_non_send_generator2() -> impl Generator>> { +fn make_non_send_coroutine2() -> impl Coroutine>> { make_gen2(Arc::new(RefCell::new(0))) } fn test2() { let send_gen = || { - let _non_send_gen = make_non_send_generator2(); + let _non_send_gen = make_non_send_coroutine2(); yield; }; require_send(send_gen); diff --git a/tests/ui/generator/print/generator-print-verbose-1.stderr b/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr similarity index 58% rename from tests/ui/generator/print/generator-print-verbose-1.stderr rename to tests/ui/coroutine/print/coroutine-print-verbose-1.stderr index d949543de41bc..bcdcbc154cf0a 100644 --- a/tests/ui/generator/print/generator-print-verbose-1.stderr +++ b/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr @@ -1,26 +1,26 @@ -error: generator cannot be sent between threads safely - --> $DIR/generator-print-verbose-1.rs:37:5 +error: coroutine cannot be sent between threads safely + --> $DIR/coroutine-print-verbose-1.rs:37:5 | LL | require_send(send_gen); - | ^^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^^ coroutine is not `Send` | = help: the trait `Sync` is not implemented for `RefCell` = note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead -note: generator is not `Send` as this value is used across a yield - --> $DIR/generator-print-verbose-1.rs:35:9 +note: coroutine is not `Send` as this value is used across a yield + --> $DIR/coroutine-print-verbose-1.rs:35:9 | -LL | let _non_send_gen = make_non_send_generator(); - | ------------- has type `Opaque(DefId(0:34 ~ generator_print_verbose_1[7d1d]::make_non_send_generator::{opaque#0}), [])` which is not `Send` +LL | let _non_send_gen = make_non_send_coroutine(); + | ------------- has type `Opaque(DefId(0:34 ~ coroutine_print_verbose_1[75fb]::make_non_send_coroutine::{opaque#0}), [])` which is not `Send` LL | yield; | ^^^^^ yield occurs here, with `_non_send_gen` maybe used later note: required by a bound in `require_send` - --> $DIR/generator-print-verbose-1.rs:26:25 + --> $DIR/coroutine-print-verbose-1.rs:26:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error[E0277]: `RefCell` cannot be shared between threads safely - --> $DIR/generator-print-verbose-1.rs:56:5 + --> $DIR/coroutine-print-verbose-1.rs:56:5 | LL | require_send(send_gen); | ^^^^^^^^^^^^ `RefCell` cannot be shared between threads safely @@ -28,29 +28,29 @@ LL | require_send(send_gen); = help: the trait `Sync` is not implemented for `RefCell` = note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead = note: required for `Arc>` to implement `Send` -note: required because it's used within this generator - --> $DIR/generator-print-verbose-1.rs:42:5 +note: required because it's used within this coroutine + --> $DIR/coroutine-print-verbose-1.rs:42:5 | LL | || { | ^^ -note: required because it appears within the type `Opaque(DefId(0:35 ~ generator_print_verbose_1[7d1d]::make_gen2::{opaque#0}), [Arc>])` - --> $DIR/generator-print-verbose-1.rs:41:30 +note: required because it appears within the type `Opaque(DefId(0:35 ~ coroutine_print_verbose_1[75fb]::make_gen2::{opaque#0}), [Arc>])` + --> $DIR/coroutine-print-verbose-1.rs:41:30 | -LL | pub fn make_gen2(t: T) -> impl Generator { +LL | pub fn make_gen2(t: T) -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: required because it appears within the type `Opaque(DefId(0:36 ~ generator_print_verbose_1[7d1d]::make_non_send_generator2::{opaque#0}), [])` - --> $DIR/generator-print-verbose-1.rs:47:34 +note: required because it appears within the type `Opaque(DefId(0:36 ~ coroutine_print_verbose_1[75fb]::make_non_send_coroutine2::{opaque#0}), [])` + --> $DIR/coroutine-print-verbose-1.rs:47:34 | -LL | fn make_non_send_generator2() -> impl Generator>> { +LL | fn make_non_send_coroutine2() -> impl Coroutine>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `Opaque(DefId(0:36 ~ generator_print_verbose_1[7d1d]::make_non_send_generator2::{opaque#0}), [])` -note: required because it's used within this generator - --> $DIR/generator-print-verbose-1.rs:52:20 + = note: required because it captures the following types: `Opaque(DefId(0:36 ~ coroutine_print_verbose_1[75fb]::make_non_send_coroutine2::{opaque#0}), [])` +note: required because it's used within this coroutine + --> $DIR/coroutine-print-verbose-1.rs:52:20 | LL | let send_gen = || { | ^^ note: required by a bound in `require_send` - --> $DIR/generator-print-verbose-1.rs:26:25 + --> $DIR/coroutine-print-verbose-1.rs:26:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` diff --git a/tests/ui/generator/print/generator-print-verbose-2.rs b/tests/ui/coroutine/print/coroutine-print-verbose-2.rs similarity index 67% rename from tests/ui/generator/print/generator-print-verbose-2.rs rename to tests/ui/coroutine/print/coroutine-print-verbose-2.rs index e53a7ef8cc137..c65c33cb4bacb 100644 --- a/tests/ui/generator/print/generator-print-verbose-2.rs +++ b/tests/ui/coroutine/print/coroutine-print-verbose-2.rs @@ -1,7 +1,7 @@ // compile-flags: -Zverbose -// Same as test/ui/generator/not-send-sync.rs -#![feature(generators)] +// Same as test/ui/coroutine/not-send-sync.rs +#![feature(coroutines)] #![feature(negative_impls)] struct NotSend; @@ -15,14 +15,14 @@ fn main() { fn assert_send(_: T) {} assert_sync(|| { - //~^ ERROR: generator cannot be shared between threads safely + //~^ ERROR: coroutine cannot be shared between threads safely let a = NotSync; yield; drop(a); }); assert_send(|| { - //~^ ERROR: generator cannot be sent between threads safely + //~^ ERROR: coroutine cannot be sent between threads safely let a = NotSend; yield; drop(a); diff --git a/tests/ui/generator/print/generator-print-verbose-2.stderr b/tests/ui/coroutine/print/coroutine-print-verbose-2.stderr similarity index 63% rename from tests/ui/generator/print/generator-print-verbose-2.stderr rename to tests/ui/coroutine/print/coroutine-print-verbose-2.stderr index 8ff7557619fee..e9c7a8ffcaab6 100644 --- a/tests/ui/generator/print/generator-print-verbose-2.stderr +++ b/tests/ui/coroutine/print/coroutine-print-verbose-2.stderr @@ -1,39 +1,39 @@ -error: generator cannot be shared between threads safely - --> $DIR/generator-print-verbose-2.rs:17:5 +error: coroutine cannot be shared between threads safely + --> $DIR/coroutine-print-verbose-2.rs:17:5 | LL | assert_sync(|| { - | ^^^^^^^^^^^ generator is not `Sync` + | ^^^^^^^^^^^ coroutine is not `Sync` | = help: within `{main::{closure#0} upvar_tys=() {main::{closure#0}}}`, the trait `Sync` is not implemented for `NotSync` -note: generator is not `Sync` as this value is used across a yield - --> $DIR/generator-print-verbose-2.rs:20:9 +note: coroutine is not `Sync` as this value is used across a yield + --> $DIR/coroutine-print-verbose-2.rs:20:9 | LL | let a = NotSync; | - has type `NotSync` which is not `Sync` LL | yield; | ^^^^^ yield occurs here, with `a` maybe used later note: required by a bound in `assert_sync` - --> $DIR/generator-print-verbose-2.rs:14:23 + --> $DIR/coroutine-print-verbose-2.rs:14:23 | LL | fn assert_sync(_: T) {} | ^^^^ required by this bound in `assert_sync` -error: generator cannot be sent between threads safely - --> $DIR/generator-print-verbose-2.rs:24:5 +error: coroutine cannot be sent between threads safely + --> $DIR/coroutine-print-verbose-2.rs:24:5 | LL | assert_send(|| { - | ^^^^^^^^^^^ generator is not `Send` + | ^^^^^^^^^^^ coroutine is not `Send` | = help: within `{main::{closure#1} upvar_tys=() {main::{closure#1}}}`, the trait `Send` is not implemented for `NotSend` -note: generator is not `Send` as this value is used across a yield - --> $DIR/generator-print-verbose-2.rs:27:9 +note: coroutine is not `Send` as this value is used across a yield + --> $DIR/coroutine-print-verbose-2.rs:27:9 | LL | let a = NotSend; | - has type `NotSend` which is not `Send` LL | yield; | ^^^^^ yield occurs here, with `a` maybe used later note: required by a bound in `assert_send` - --> $DIR/generator-print-verbose-2.rs:15:23 + --> $DIR/coroutine-print-verbose-2.rs:15:23 | LL | fn assert_send(_: T) {} | ^^^^ required by this bound in `assert_send` diff --git a/tests/ui/generator/print/generator-print-verbose-3.rs b/tests/ui/coroutine/print/coroutine-print-verbose-3.rs similarity index 68% rename from tests/ui/generator/print/generator-print-verbose-3.rs rename to tests/ui/coroutine/print/coroutine-print-verbose-3.rs index 8689539ec8ebb..3e4bb6281768a 100644 --- a/tests/ui/generator/print/generator-print-verbose-3.rs +++ b/tests/ui/coroutine/print/coroutine-print-verbose-3.rs @@ -1,10 +1,10 @@ // compile-flags: -Zverbose -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { let x = "Type mismatch test"; - let generator :() = || { + let coroutine :() = || { //~^ ERROR mismatched types yield 1i32; return x diff --git a/tests/ui/generator/print/generator-print-verbose-3.stderr b/tests/ui/coroutine/print/coroutine-print-verbose-3.stderr similarity index 66% rename from tests/ui/generator/print/generator-print-verbose-3.stderr rename to tests/ui/coroutine/print/coroutine-print-verbose-3.stderr index 69358ed0a9182..fb80f29d10d81 100644 --- a/tests/ui/generator/print/generator-print-verbose-3.stderr +++ b/tests/ui/coroutine/print/coroutine-print-verbose-3.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types - --> $DIR/generator-print-verbose-3.rs:7:25 + --> $DIR/coroutine-print-verbose-3.rs:7:25 | -LL | let generator :() = || { +LL | let coroutine :() = || { | ____________________--___^ | | | | | expected due to this @@ -9,10 +9,10 @@ LL | | LL | | yield 1i32; LL | | return x LL | | }; - | |_____^ expected `()`, found generator + | |_____^ expected `()`, found coroutine | = note: expected unit type `()` - found generator `{main::{closure#0} upvar_tys=(unavailable)}` + found coroutine `{main::{closure#0} upvar_tys=(unavailable)}` error: aborting due to previous error diff --git a/tests/ui/generator/reborrow-mut-upvar.rs b/tests/ui/coroutine/reborrow-mut-upvar.rs similarity index 66% rename from tests/ui/generator/reborrow-mut-upvar.rs rename to tests/ui/coroutine/reborrow-mut-upvar.rs index dbd9e24e205c8..e4f717be8b5cc 100644 --- a/tests/ui/generator/reborrow-mut-upvar.rs +++ b/tests/ui/coroutine/reborrow-mut-upvar.rs @@ -1,9 +1,9 @@ // run-pass -#![feature(generators)] +#![feature(coroutines)] fn _run(bar: &mut i32) { - || { //~ WARN unused generator that must be used + || { //~ WARN unused coroutine that must be used { let _baz = &*bar; yield; diff --git a/tests/ui/generator/reborrow-mut-upvar.stderr b/tests/ui/coroutine/reborrow-mut-upvar.stderr similarity index 72% rename from tests/ui/generator/reborrow-mut-upvar.stderr rename to tests/ui/coroutine/reborrow-mut-upvar.stderr index 2e1fec35eaf52..5b614ac4be8b2 100644 --- a/tests/ui/generator/reborrow-mut-upvar.stderr +++ b/tests/ui/coroutine/reborrow-mut-upvar.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/reborrow-mut-upvar.rs:6:5 | LL | / || { @@ -10,7 +10,7 @@ LL | | *bar = 2; LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/generator/ref-escapes-but-not-over-yield.rs b/tests/ui/coroutine/ref-escapes-but-not-over-yield.rs similarity index 64% rename from tests/ui/generator/ref-escapes-but-not-over-yield.rs rename to tests/ui/coroutine/ref-escapes-but-not-over-yield.rs index 3856d8233bcc0..a9c13188ff386 100644 --- a/tests/ui/generator/ref-escapes-but-not-over-yield.rs +++ b/tests/ui/coroutine/ref-escapes-but-not-over-yield.rs @@ -1,7 +1,7 @@ -#![feature(generators)] +#![feature(coroutines)] fn foo(x: &i32) { - // In this case, a reference to `b` escapes the generator, but not + // In this case, a reference to `b` escapes the coroutine, but not // because of a yield. We see that there is no yield in the scope of // `b` and give the more generic error message. let mut a = &3; @@ -9,7 +9,7 @@ fn foo(x: &i32) { yield(); let b = 5; a = &b; - //~^ ERROR borrowed data escapes outside of generator + //~^ ERROR borrowed data escapes outside of coroutine }; } diff --git a/tests/ui/generator/ref-escapes-but-not-over-yield.stderr b/tests/ui/coroutine/ref-escapes-but-not-over-yield.stderr similarity index 51% rename from tests/ui/generator/ref-escapes-but-not-over-yield.stderr rename to tests/ui/coroutine/ref-escapes-but-not-over-yield.stderr index 5fc8100409822..4c8694e67869f 100644 --- a/tests/ui/generator/ref-escapes-but-not-over-yield.stderr +++ b/tests/ui/coroutine/ref-escapes-but-not-over-yield.stderr @@ -1,14 +1,14 @@ -error[E0521]: borrowed data escapes outside of generator +error[E0521]: borrowed data escapes outside of coroutine --> $DIR/ref-escapes-but-not-over-yield.rs:11:9 | LL | let mut a = &3; - | ----- `a` declared here, outside of the generator body + | ----- `a` declared here, outside of the coroutine body ... LL | a = &b; | ^^^^-- | | | - | | borrow is only valid in the generator body - | reference to `b` escapes the generator body here + | | borrow is only valid in the coroutine body + | reference to `b` escapes the coroutine body here error: aborting due to previous error diff --git a/tests/ui/generator/ref-upvar-not-send.rs b/tests/ui/coroutine/ref-upvar-not-send.rs similarity index 76% rename from tests/ui/generator/ref-upvar-not-send.rs rename to tests/ui/coroutine/ref-upvar-not-send.rs index eb9ef63ecfcb4..487fdeea2dae9 100644 --- a/tests/ui/generator/ref-upvar-not-send.rs +++ b/tests/ui/coroutine/ref-upvar-not-send.rs @@ -1,7 +1,7 @@ -// For `Send` generators, suggest a `T: Sync` requirement for `&T` upvars, +// For `Send` coroutines, suggest a `T: Sync` requirement for `&T` upvars, // and suggest a `T: Send` requirement for `&mut T` upvars. -#![feature(generators)] +#![feature(coroutines)] fn assert_send(_: T) {} //~^ NOTE required by a bound in `assert_send` @@ -13,16 +13,16 @@ fn main() { let x: &*mut () = &std::ptr::null_mut(); let y: &mut *mut () = &mut std::ptr::null_mut(); assert_send(move || { - //~^ ERROR generator cannot be sent between threads safely - //~| NOTE generator is not `Send` + //~^ ERROR coroutine cannot be sent between threads safely + //~| NOTE coroutine is not `Send` yield; let _x = x; }); //~^^ NOTE captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` //~| NOTE has type `&*mut ()` which is not `Send`, because `*mut ()` is not `Sync` assert_send(move || { - //~^ ERROR generator cannot be sent between threads safely - //~| NOTE generator is not `Send` + //~^ ERROR coroutine cannot be sent between threads safely + //~| NOTE coroutine is not `Send` yield; let _y = y; }); diff --git a/tests/ui/generator/ref-upvar-not-send.stderr b/tests/ui/coroutine/ref-upvar-not-send.stderr similarity index 85% rename from tests/ui/generator/ref-upvar-not-send.stderr rename to tests/ui/coroutine/ref-upvar-not-send.stderr index d6a2be977e4c3..7f18c6fba775f 100644 --- a/tests/ui/generator/ref-upvar-not-send.stderr +++ b/tests/ui/coroutine/ref-upvar-not-send.stderr @@ -1,4 +1,4 @@ -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/ref-upvar-not-send.rs:15:17 | LL | assert_send(move || { @@ -8,7 +8,7 @@ LL | | LL | | yield; LL | | let _x = x; LL | | }); - | |_____^ generator is not `Send` + | |_____^ coroutine is not `Send` | = help: the trait `Sync` is not implemented for `*mut ()` note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` @@ -22,7 +22,7 @@ note: required by a bound in `assert_send` LL | fn assert_send(_: T) {} | ^^^^ required by this bound in `assert_send` -error: generator cannot be sent between threads safely +error: coroutine cannot be sent between threads safely --> $DIR/ref-upvar-not-send.rs:23:17 | LL | assert_send(move || { @@ -32,9 +32,9 @@ LL | | LL | | yield; LL | | let _y = y; LL | | }); - | |_____^ generator is not `Send` + | |_____^ coroutine is not `Send` | - = help: within `{generator@$DIR/ref-upvar-not-send.rs:23:17: 23:24}`, the trait `Send` is not implemented for `*mut ()` + = help: within `{coroutine@$DIR/ref-upvar-not-send.rs:23:17: 23:24}`, the trait `Send` is not implemented for `*mut ()` note: captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send` --> $DIR/ref-upvar-not-send.rs:27:18 | diff --git a/tests/ui/generator/reinit-in-match-guard.rs b/tests/ui/coroutine/reinit-in-match-guard.rs similarity index 93% rename from tests/ui/generator/reinit-in-match-guard.rs rename to tests/ui/coroutine/reinit-in-match-guard.rs index 260b341a52525..1895de1f12b3c 100644 --- a/tests/ui/generator/reinit-in-match-guard.rs +++ b/tests/ui/coroutine/reinit-in-match-guard.rs @@ -1,6 +1,6 @@ // build-pass -#![feature(generators)] +#![feature(coroutines)] #![allow(unused_assignments, dead_code)] diff --git a/tests/ui/generator/resume-after-return.rs b/tests/ui/coroutine/resume-after-return.rs similarity index 66% rename from tests/ui/generator/resume-after-return.rs rename to tests/ui/coroutine/resume-after-return.rs index 01a059a161cea..acbd8740a359e 100644 --- a/tests/ui/generator/resume-after-return.rs +++ b/tests/ui/coroutine/resume-after-return.rs @@ -2,9 +2,9 @@ // needs-unwind -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{GeneratorState, Generator}; +use std::ops::{CoroutineState, Coroutine}; use std::pin::Pin; use std::panic; @@ -17,12 +17,12 @@ fn main() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } match panic::catch_unwind(move || Pin::new(&mut foo).resume(())) { - Ok(_) => panic!("generator successfully resumed"), + Ok(_) => panic!("coroutine successfully resumed"), Err(_) => {} } } diff --git a/tests/ui/generator/resume-arg-late-bound.rs b/tests/ui/coroutine/resume-arg-late-bound.rs similarity index 54% rename from tests/ui/generator/resume-arg-late-bound.rs rename to tests/ui/coroutine/resume-arg-late-bound.rs index 1c35ba80d2b13..dd6d318afbcd7 100644 --- a/tests/ui/generator/resume-arg-late-bound.rs +++ b/tests/ui/coroutine/resume-arg-late-bound.rs @@ -1,11 +1,11 @@ -//! Tests that we cannot produce a generator that accepts a resume argument +//! Tests that we cannot produce a coroutine that accepts a resume argument //! with any lifetime and then stores it across a `yield`. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; -fn test(a: impl for<'a> Generator<&'a mut bool>) {} +fn test(a: impl for<'a> Coroutine<&'a mut bool>) {} fn main() { let gen = |arg: &mut bool| { diff --git a/tests/ui/generator/resume-arg-late-bound.stderr b/tests/ui/coroutine/resume-arg-late-bound.stderr similarity index 71% rename from tests/ui/generator/resume-arg-late-bound.stderr rename to tests/ui/coroutine/resume-arg-late-bound.stderr index 34ee4036cc56c..f1a8a8ed71113 100644 --- a/tests/ui/generator/resume-arg-late-bound.stderr +++ b/tests/ui/coroutine/resume-arg-late-bound.stderr @@ -4,12 +4,12 @@ error[E0308]: mismatched types LL | test(gen); | ^^^^^^^^^ one type is more general than the other | - = note: expected trait `for<'a> Generator<&'a mut bool>` - found trait `Generator<&mut bool>` + = note: expected trait `for<'a> Coroutine<&'a mut bool>` + found trait `Coroutine<&mut bool>` note: the lifetime requirement is introduced here --> $DIR/resume-arg-late-bound.rs:8:17 | -LL | fn test(a: impl for<'a> Generator<&'a mut bool>) {} +LL | fn test(a: impl for<'a> Coroutine<&'a mut bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/generator/resume-arg-size.rs b/tests/ui/coroutine/resume-arg-size.rs similarity index 72% rename from tests/ui/generator/resume-arg-size.rs rename to tests/ui/coroutine/resume-arg-size.rs index 195166f975b63..22bb469f9411d 100644 --- a/tests/ui/generator/resume-arg-size.rs +++ b/tests/ui/coroutine/resume-arg-size.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![allow(dropping_copy_types)] // run-pass @@ -6,7 +6,7 @@ use std::mem::size_of_val; fn main() { - // Generator taking a `Copy`able resume arg. + // Coroutine taking a `Copy`able resume arg. let gen_copy = |mut x: usize| { loop { drop(x); @@ -14,7 +14,7 @@ fn main() { } }; - // Generator taking a non-`Copy` resume arg. + // Coroutine taking a non-`Copy` resume arg. let gen_move = |mut x: Box| { loop { drop(x); @@ -22,7 +22,7 @@ fn main() { } }; - // Neither of these generators have the resume arg live across the `yield`, so they should be + // Neither of these coroutines have the resume arg live across the `yield`, so they should be // 1 Byte in size (only storing the discriminant) assert_eq!(size_of_val(&gen_copy), 1); assert_eq!(size_of_val(&gen_move), 1); diff --git a/tests/ui/generator/resume-live-across-yield.rs b/tests/ui/coroutine/resume-live-across-yield.rs similarity index 84% rename from tests/ui/generator/resume-live-across-yield.rs rename to tests/ui/coroutine/resume-live-across-yield.rs index 4c4cf117a5563..935e7d326be43 100644 --- a/tests/ui/generator/resume-live-across-yield.rs +++ b/tests/ui/coroutine/resume-live-across-yield.rs @@ -1,8 +1,8 @@ // run-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -27,11 +27,11 @@ fn main() { assert_eq!( g.as_mut().resume(Dropper(String::from("Hello world!"))), - GeneratorState::Yielded(()) + CoroutineState::Yielded(()) ); assert_eq!(DROP.load(Ordering::Acquire), 0); match g.as_mut().resume(Dropper(String::from("Number Two"))) { - GeneratorState::Complete(dropper) => { + CoroutineState::Complete(dropper) => { assert_eq!(DROP.load(Ordering::Acquire), 1); assert_eq!(dropper.0, "Number Two"); drop(dropper); diff --git a/tests/ui/generator/retain-resume-ref.rs b/tests/ui/coroutine/retain-resume-ref.rs similarity index 84% rename from tests/ui/generator/retain-resume-ref.rs rename to tests/ui/coroutine/retain-resume-ref.rs index 0606ea71cdf37..c9f995ab0cf31 100644 --- a/tests/ui/generator/retain-resume-ref.rs +++ b/tests/ui/coroutine/retain-resume-ref.rs @@ -1,11 +1,11 @@ //! This test ensures that a mutable reference cannot be passed as a resume argument twice. -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::marker::Unpin; use std::ops::{ - Generator, - GeneratorState::{self, *}, + Coroutine, + CoroutineState::{self, *}, }; use std::pin::Pin; diff --git a/tests/ui/generator/retain-resume-ref.stderr b/tests/ui/coroutine/retain-resume-ref.stderr similarity index 93% rename from tests/ui/generator/retain-resume-ref.stderr rename to tests/ui/coroutine/retain-resume-ref.stderr index bc715c7030eb3..983443bbfeb37 100644 --- a/tests/ui/generator/retain-resume-ref.stderr +++ b/tests/ui/coroutine/retain-resume-ref.stderr @@ -7,7 +7,7 @@ LL | gen.as_mut().resume(&mut thing); | ^^^^^^^^^^ second mutable borrow occurs here LL | LL | } - | - first borrow might be used here, when `gen` is dropped and runs the destructor for generator + | - first borrow might be used here, when `gen` is dropped and runs the destructor for coroutine error: aborting due to previous error diff --git a/tests/ui/generator/size-moved-locals.rs b/tests/ui/coroutine/size-moved-locals.rs similarity index 82% rename from tests/ui/generator/size-moved-locals.rs rename to tests/ui/coroutine/size-moved-locals.rs index 601a314182876..cfbbb9c1b318f 100644 --- a/tests/ui/generator/size-moved-locals.rs +++ b/tests/ui/coroutine/size-moved-locals.rs @@ -4,7 +4,7 @@ // `complex` below.) // // The exact sizes here can change (we'd like to know when they do). What we -// don't want to see is the `complex` generator size being upwards of 2048 bytes +// don't want to see is the `complex` coroutine size being upwards of 2048 bytes // (which would indicate it is reserving space for two copies of Foo.) // // See issue #59123 for a full explanation. @@ -14,9 +14,9 @@ // ignore-asmjs issue #62807 // needs-unwind Size of Closures change on panic=abort -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; const FOO_SIZE: usize = 1024; struct Foo(#[allow(unused_tuple_struct_fields)] [u8; FOO_SIZE]); @@ -25,7 +25,7 @@ impl Drop for Foo { fn drop(&mut self) {} } -fn move_before_yield() -> impl Generator { +fn move_before_yield() -> impl Coroutine { static || { let first = Foo([0; FOO_SIZE]); let _second = first; @@ -36,7 +36,7 @@ fn move_before_yield() -> impl Generator { fn noop() {} -fn move_before_yield_with_noop() -> impl Generator { +fn move_before_yield_with_noop() -> impl Coroutine { static || { let first = Foo([0; FOO_SIZE]); noop(); @@ -48,7 +48,7 @@ fn move_before_yield_with_noop() -> impl Generator { // Today we don't have NRVO (we allocate space for both `first` and `second`,) // but we can overlap `first` with `_third`. -fn overlap_move_points() -> impl Generator { +fn overlap_move_points() -> impl Coroutine { static || { let first = Foo([0; FOO_SIZE]); yield; @@ -59,7 +59,7 @@ fn overlap_move_points() -> impl Generator { } } -fn overlap_x_and_y() -> impl Generator { +fn overlap_x_and_y() -> impl Coroutine { static || { let x = Foo([0; FOO_SIZE]); yield; diff --git a/tests/ui/coroutine/sized-yield.rs b/tests/ui/coroutine/sized-yield.rs new file mode 100644 index 0000000000000..1368c88b5227d --- /dev/null +++ b/tests/ui/coroutine/sized-yield.rs @@ -0,0 +1,14 @@ +#![feature(coroutines, coroutine_trait)] + +use std::ops::Coroutine; +use std::pin::Pin; + +fn main() { + let s = String::from("foo"); + let mut gen = move || { + //~^ ERROR the size for values of type + yield s[..]; + }; + Pin::new(&mut gen).resume(()); + //~^ ERROR the size for values of type +} diff --git a/tests/ui/coroutine/sized-yield.stderr b/tests/ui/coroutine/sized-yield.stderr new file mode 100644 index 0000000000000..40663ac12de46 --- /dev/null +++ b/tests/ui/coroutine/sized-yield.stderr @@ -0,0 +1,26 @@ +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/sized-yield.rs:8:27 + | +LL | let mut gen = move || { + | ___________________________^ +LL | | +LL | | yield s[..]; +LL | | }; + | |_____^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: the yield type of a coroutine must have a statically known size + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/sized-yield.rs:12:24 + | +LL | Pin::new(&mut gen).resume(()); + | ^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` +note: required by a bound in `CoroutineState` + --> $SRC_DIR/core/src/ops/coroutine.rs:LL:COL + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/generator/smoke-resume-args.rs b/tests/ui/coroutine/smoke-resume-args.rs similarity index 91% rename from tests/ui/generator/smoke-resume-args.rs rename to tests/ui/coroutine/smoke-resume-args.rs index fa9271c538f53..a801989859e86 100644 --- a/tests/ui/generator/smoke-resume-args.rs +++ b/tests/ui/coroutine/smoke-resume-args.rs @@ -3,20 +3,20 @@ // revisions: default nomiropt //[nomiropt]compile-flags: -Z mir-opt-level=0 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::fmt::Debug; use std::marker::Unpin; use std::ops::{ - Generator, - GeneratorState::{self, *}, + Coroutine, + CoroutineState::{self, *}, }; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; -fn drain + Unpin, R, Y>( +fn drain + Unpin, R, Y>( gen: &mut G, - inout: Vec<(R, GeneratorState)>, + inout: Vec<(R, CoroutineState)>, ) where Y: Debug + PartialEq, G::Return: Debug + PartialEq, diff --git a/tests/ui/generator/smoke.rs b/tests/ui/coroutine/smoke.rs similarity index 79% rename from tests/ui/generator/smoke.rs rename to tests/ui/coroutine/smoke.rs index 7a917a05dd9a6..b74ed26865ff7 100644 --- a/tests/ui/generator/smoke.rs +++ b/tests/ui/coroutine/smoke.rs @@ -6,9 +6,9 @@ // ignore-emscripten no threads support // compile-flags: --test -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{GeneratorState, Generator}; +use std::ops::{CoroutineState, Coroutine}; use std::pin::Pin; use std::thread; @@ -21,7 +21,7 @@ fn simple() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } } @@ -37,7 +37,7 @@ fn return_capture() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(ref s) if *s == "foo" => {} + CoroutineState::Complete(ref s) if *s == "foo" => {} s => panic!("bad state: {:?}", s), } } @@ -49,11 +49,11 @@ fn simple_yield() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(()) => {} + CoroutineState::Yielded(()) => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } } @@ -66,11 +66,11 @@ fn yield_capture() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(ref s) if *s == "foo" => {} + CoroutineState::Yielded(ref s) if *s == "foo" => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } } @@ -83,11 +83,11 @@ fn simple_yield_value() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(ref s) if *s == "bar" => {} + CoroutineState::Yielded(ref s) if *s == "bar" => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(ref s) if *s == "foo" => {} + CoroutineState::Complete(ref s) if *s == "foo" => {} s => panic!("bad state: {:?}", s), } } @@ -101,11 +101,11 @@ fn return_after_yield() { }; match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(()) => {} + CoroutineState::Yielded(()) => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(ref s) if *s == "foo" => {} + CoroutineState::Complete(ref s) if *s == "foo" => {} s => panic!("bad state: {:?}", s), } } @@ -153,11 +153,11 @@ fn send_over_threads() { let mut foo = || { yield }; thread::spawn(move || { match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(()) => {} + CoroutineState::Yielded(()) => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } }).join().unwrap(); @@ -166,11 +166,11 @@ fn send_over_threads() { let mut foo = || { yield a }; thread::spawn(move || { match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(ref s) if *s == "a" => {} + CoroutineState::Yielded(ref s) if *s == "a" => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } }).join().unwrap(); diff --git a/tests/ui/coroutine/static-coroutine.rs b/tests/ui/coroutine/static-coroutine.rs new file mode 100644 index 0000000000000..f9fd65b9793d6 --- /dev/null +++ b/tests/ui/coroutine/static-coroutine.rs @@ -0,0 +1,20 @@ +// run-pass + +#![feature(coroutines, coroutine_trait)] + +use std::pin::Pin; +use std::ops::{Coroutine, CoroutineState}; + +fn main() { + let mut coroutine = static || { + let a = true; + let b = &a; + yield; + assert_eq!(b as *const _, &a as *const _); + }; + // SAFETY: We shadow the original coroutine variable so have no safe API to + // move it after this point. + let mut coroutine = unsafe { Pin::new_unchecked(&mut coroutine) }; + assert_eq!(coroutine.as_mut().resume(()), CoroutineState::Yielded(())); + assert_eq!(coroutine.as_mut().resume(()), CoroutineState::Complete(())); +} diff --git a/tests/ui/generator/static-mut-reference-across-yield.rs b/tests/ui/coroutine/static-mut-reference-across-yield.rs similarity index 96% rename from tests/ui/generator/static-mut-reference-across-yield.rs rename to tests/ui/coroutine/static-mut-reference-across-yield.rs index 0fa6d9cdc77b6..07f810856a72f 100644 --- a/tests/ui/generator/static-mut-reference-across-yield.rs +++ b/tests/ui/coroutine/static-mut-reference-across-yield.rs @@ -2,7 +2,7 @@ // revisions: mir thir // [thir]compile-flags: -Zthir-unsafeck -#![feature(generators)] +#![feature(coroutines)] static mut A: [i32; 5] = [1, 2, 3, 4, 5]; diff --git a/tests/ui/generator/static-not-unpin.current.stderr b/tests/ui/coroutine/static-not-unpin.current.stderr similarity index 80% rename from tests/ui/generator/static-not-unpin.current.stderr rename to tests/ui/coroutine/static-not-unpin.current.stderr index 242489841e802..cd607904f5a60 100644 --- a/tests/ui/generator/static-not-unpin.current.stderr +++ b/tests/ui/coroutine/static-not-unpin.current.stderr @@ -1,8 +1,8 @@ -error[E0277]: `{static generator@$DIR/static-not-unpin.rs:14:25: 14:34}` cannot be unpinned +error[E0277]: `{static coroutine@$DIR/static-not-unpin.rs:14:25: 14:34}` cannot be unpinned --> $DIR/static-not-unpin.rs:17:18 | -LL | assert_unpin(generator); - | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static generator@$DIR/static-not-unpin.rs:14:25: 14:34}` +LL | assert_unpin(coroutine); + | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/static-not-unpin.rs:14:25: 14:34}` | | | required by a bound introduced by this call | diff --git a/tests/ui/generator/static-not-unpin.next.stderr b/tests/ui/coroutine/static-not-unpin.next.stderr similarity index 80% rename from tests/ui/generator/static-not-unpin.next.stderr rename to tests/ui/coroutine/static-not-unpin.next.stderr index 242489841e802..cd607904f5a60 100644 --- a/tests/ui/generator/static-not-unpin.next.stderr +++ b/tests/ui/coroutine/static-not-unpin.next.stderr @@ -1,8 +1,8 @@ -error[E0277]: `{static generator@$DIR/static-not-unpin.rs:14:25: 14:34}` cannot be unpinned +error[E0277]: `{static coroutine@$DIR/static-not-unpin.rs:14:25: 14:34}` cannot be unpinned --> $DIR/static-not-unpin.rs:17:18 | -LL | assert_unpin(generator); - | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static generator@$DIR/static-not-unpin.rs:14:25: 14:34}` +LL | assert_unpin(coroutine); + | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/static-not-unpin.rs:14:25: 14:34}` | | | required by a bound introduced by this call | diff --git a/tests/ui/generator/static-not-unpin.rs b/tests/ui/coroutine/static-not-unpin.rs similarity index 69% rename from tests/ui/generator/static-not-unpin.rs rename to tests/ui/coroutine/static-not-unpin.rs index 30d3f29187096..6ce78046dcc89 100644 --- a/tests/ui/generator/static-not-unpin.rs +++ b/tests/ui/coroutine/static-not-unpin.rs @@ -1,7 +1,7 @@ // revisions: current next //[next] compile-flags: -Ztrait-solver=next -#![feature(generators)] +#![feature(coroutines)] // normalize-stderr-test "std::pin::Unpin" -> "std::marker::Unpin" @@ -11,8 +11,8 @@ fn assert_unpin(_: T) { } fn main() { - let mut generator = static || { + let mut coroutine = static || { yield; }; - assert_unpin(generator); //~ ERROR E0277 + assert_unpin(coroutine); //~ ERROR E0277 } diff --git a/tests/ui/generator/static-reference-across-yield.rs b/tests/ui/coroutine/static-reference-across-yield.rs similarity index 90% rename from tests/ui/generator/static-reference-across-yield.rs rename to tests/ui/coroutine/static-reference-across-yield.rs index 23b11593bb5d6..6496d8b86cc53 100644 --- a/tests/ui/generator/static-reference-across-yield.rs +++ b/tests/ui/coroutine/static-reference-across-yield.rs @@ -1,5 +1,5 @@ // build-pass -#![feature(generators)] +#![feature(coroutines)] static A: [i32; 5] = [1, 2, 3, 4, 5]; diff --git a/tests/ui/generator/too-live-local-in-immovable-gen.rs b/tests/ui/coroutine/too-live-local-in-immovable-gen.rs similarity index 67% rename from tests/ui/generator/too-live-local-in-immovable-gen.rs rename to tests/ui/coroutine/too-live-local-in-immovable-gen.rs index e0b856db7a55d..7eaa155222729 100644 --- a/tests/ui/generator/too-live-local-in-immovable-gen.rs +++ b/tests/ui/coroutine/too-live-local-in-immovable-gen.rs @@ -1,15 +1,15 @@ // run-pass #![allow(unused_unsafe)] -#![feature(generators)] +#![feature(coroutines)] fn main() { unsafe { - static move || { //~ WARN unused generator that must be used - // Tests that the generator transformation finds out that `a` is not live + static move || { //~ WARN unused coroutine that must be used + // Tests that the coroutine transformation finds out that `a` is not live // during the yield expression. Type checking will also compute liveness // and it should also find out that `a` is not live. - // The compiler will panic if the generator transformation finds that + // The compiler will panic if the coroutine transformation finds that // `a` is live and type checking finds it dead. let a = { yield (); diff --git a/tests/ui/generator/too-live-local-in-immovable-gen.stderr b/tests/ui/coroutine/too-live-local-in-immovable-gen.stderr similarity index 72% rename from tests/ui/generator/too-live-local-in-immovable-gen.stderr rename to tests/ui/coroutine/too-live-local-in-immovable-gen.stderr index e262f213f63d2..4a67dbe71e19b 100644 --- a/tests/ui/generator/too-live-local-in-immovable-gen.stderr +++ b/tests/ui/coroutine/too-live-local-in-immovable-gen.stderr @@ -1,8 +1,8 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/too-live-local-in-immovable-gen.rs:8:9 | LL | / static move || { -LL | | // Tests that the generator transformation finds out that `a` is not live +LL | | // Tests that the coroutine transformation finds out that `a` is not live LL | | // during the yield expression. Type checking will also compute liveness LL | | // and it should also find out that `a` is not live. ... | @@ -10,7 +10,7 @@ LL | | let _ = &a; LL | | }; | |_________^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/coroutine/too-many-parameters.rs b/tests/ui/coroutine/too-many-parameters.rs new file mode 100644 index 0000000000000..377d80c7b22e2 --- /dev/null +++ b/tests/ui/coroutine/too-many-parameters.rs @@ -0,0 +1,8 @@ +#![feature(coroutines)] + +fn main() { + |(), ()| { + //~^ error: too many parameters for a coroutine + yield; + }; +} diff --git a/tests/ui/generator/too-many-parameters.stderr b/tests/ui/coroutine/too-many-parameters.stderr similarity index 76% rename from tests/ui/generator/too-many-parameters.stderr rename to tests/ui/coroutine/too-many-parameters.stderr index 22d40db3f2678..54cf42e78d3b6 100644 --- a/tests/ui/generator/too-many-parameters.stderr +++ b/tests/ui/coroutine/too-many-parameters.stderr @@ -1,4 +1,4 @@ -error[E0628]: too many parameters for a generator (expected 0 or 1 parameters) +error[E0628]: too many parameters for a coroutine (expected 0 or 1 parameters) --> $DIR/too-many-parameters.rs:4:5 | LL | |(), ()| { diff --git a/tests/ui/generator/type-mismatch-error.rs b/tests/ui/coroutine/type-mismatch-error.rs similarity index 79% rename from tests/ui/generator/type-mismatch-error.rs rename to tests/ui/coroutine/type-mismatch-error.rs index d39c788a84bd4..0d04c21484cbe 100644 --- a/tests/ui/generator/type-mismatch-error.rs +++ b/tests/ui/coroutine/type-mismatch-error.rs @@ -1,11 +1,11 @@ //! Test that we get the expected type mismatch error instead of "closure is expected to take 0 //! arguments" (which got introduced after implementing resume arguments). -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; -fn f(_: G, _: G::Return) {} +fn f(_: G, _: G::Return) {} fn main() { f( diff --git a/tests/ui/generator/type-mismatch-error.stderr b/tests/ui/coroutine/type-mismatch-error.stderr similarity index 100% rename from tests/ui/generator/type-mismatch-error.stderr rename to tests/ui/coroutine/type-mismatch-error.stderr diff --git a/tests/ui/generator/type-mismatch-signature-deduction.rs b/tests/ui/coroutine/type-mismatch-signature-deduction.rs similarity index 62% rename from tests/ui/generator/type-mismatch-signature-deduction.rs rename to tests/ui/coroutine/type-mismatch-signature-deduction.rs index 8d1ce6c7a437c..d4ca622e80f53 100644 --- a/tests/ui/generator/type-mismatch-signature-deduction.rs +++ b/tests/ui/coroutine/type-mismatch-signature-deduction.rs @@ -1,8 +1,8 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; -fn foo() -> impl Generator { +fn foo() -> impl Coroutine { //~^ ERROR type mismatch || { if false { diff --git a/tests/ui/generator/type-mismatch-signature-deduction.stderr b/tests/ui/coroutine/type-mismatch-signature-deduction.stderr similarity index 84% rename from tests/ui/generator/type-mismatch-signature-deduction.stderr rename to tests/ui/coroutine/type-mismatch-signature-deduction.stderr index fe1bade5577c8..f26e30a8e7435 100644 --- a/tests/ui/generator/type-mismatch-signature-deduction.stderr +++ b/tests/ui/coroutine/type-mismatch-signature-deduction.stderr @@ -18,10 +18,10 @@ LL | Ok(5) LL | Err(5) | ++++ + -error[E0271]: type mismatch resolving `<{generator@$DIR/type-mismatch-signature-deduction.rs:7:5: 7:7} as Generator>::Return == i32` +error[E0271]: type mismatch resolving `<{coroutine@$DIR/type-mismatch-signature-deduction.rs:7:5: 7:7} as Coroutine>::Return == i32` --> $DIR/type-mismatch-signature-deduction.rs:5:13 | -LL | fn foo() -> impl Generator { +LL | fn foo() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<{integer}, _>`, found `i32` | = note: expected enum `Result<{integer}, _>` diff --git a/tests/ui/generator/unresolved-ct-var.rs b/tests/ui/coroutine/unresolved-ct-var.rs similarity index 100% rename from tests/ui/generator/unresolved-ct-var.rs rename to tests/ui/coroutine/unresolved-ct-var.rs diff --git a/tests/ui/generator/unresolved-ct-var.stderr b/tests/ui/coroutine/unresolved-ct-var.stderr similarity index 100% rename from tests/ui/generator/unresolved-ct-var.stderr rename to tests/ui/coroutine/unresolved-ct-var.stderr diff --git a/tests/ui/generator/unsized-capture-across-yield.rs b/tests/ui/coroutine/unsized-capture-across-yield.rs similarity index 78% rename from tests/ui/generator/unsized-capture-across-yield.rs rename to tests/ui/coroutine/unsized-capture-across-yield.rs index 7bcb0800ccfb8..ef9cbc1d677da 100644 --- a/tests/ui/generator/unsized-capture-across-yield.rs +++ b/tests/ui/coroutine/unsized-capture-across-yield.rs @@ -1,11 +1,11 @@ -#![feature(generator_trait)] -#![feature(generators)] +#![feature(coroutine_trait)] +#![feature(coroutines)] #![feature(unsized_locals)] //~^ WARN the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes -use std::ops::Generator; +use std::ops::Coroutine; -fn capture() -> impl Generator { +fn capture() -> impl Coroutine { let b: [u8] = *(Box::new([]) as Box<[u8]>); move || { println!("{:?}", &b); diff --git a/tests/ui/generator/unsized-capture-across-yield.stderr b/tests/ui/coroutine/unsized-capture-across-yield.stderr similarity index 100% rename from tests/ui/generator/unsized-capture-across-yield.stderr rename to tests/ui/coroutine/unsized-capture-across-yield.stderr diff --git a/tests/ui/generator/unsized-local-across-yield.rs b/tests/ui/coroutine/unsized-local-across-yield.rs similarity index 77% rename from tests/ui/generator/unsized-local-across-yield.rs rename to tests/ui/coroutine/unsized-local-across-yield.rs index f761f45c2af3a..7a8ed60e46ae4 100644 --- a/tests/ui/generator/unsized-local-across-yield.rs +++ b/tests/ui/coroutine/unsized-local-across-yield.rs @@ -1,11 +1,11 @@ -#![feature(generator_trait)] -#![feature(generators)] +#![feature(coroutine_trait)] +#![feature(coroutines)] #![feature(unsized_locals)] //~^ WARN the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes -use std::ops::Generator; +use std::ops::Coroutine; -fn across() -> impl Generator { +fn across() -> impl Coroutine { move || { let b: [u8] = *(Box::new([]) as Box<[u8]>); //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time diff --git a/tests/ui/generator/unsized-local-across-yield.stderr b/tests/ui/coroutine/unsized-local-across-yield.stderr similarity index 100% rename from tests/ui/generator/unsized-local-across-yield.stderr rename to tests/ui/coroutine/unsized-local-across-yield.stderr diff --git a/tests/ui/generator/xcrate-reachable.rs b/tests/ui/coroutine/xcrate-reachable.rs similarity index 75% rename from tests/ui/generator/xcrate-reachable.rs rename to tests/ui/coroutine/xcrate-reachable.rs index 1b1cff3387d9f..c6328448868cb 100644 --- a/tests/ui/generator/xcrate-reachable.rs +++ b/tests/ui/coroutine/xcrate-reachable.rs @@ -2,11 +2,11 @@ // aux-build:xcrate-reachable.rs -#![feature(generator_trait)] +#![feature(coroutine_trait)] extern crate xcrate_reachable as foo; -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/ui/generator/xcrate.rs b/tests/ui/coroutine/xcrate.rs similarity index 67% rename from tests/ui/generator/xcrate.rs rename to tests/ui/coroutine/xcrate.rs index 40986bbeb6517..4572d1cfd5477 100644 --- a/tests/ui/generator/xcrate.rs +++ b/tests/ui/coroutine/xcrate.rs @@ -2,29 +2,29 @@ // aux-build:xcrate.rs -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] extern crate xcrate; -use std::ops::{GeneratorState, Generator}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn main() { let mut foo = xcrate::foo(); match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } let mut foo = xcrate::bar(3); match Pin::new(&mut foo).resume(()) { - GeneratorState::Yielded(3) => {} + CoroutineState::Yielded(3) => {} s => panic!("bad state: {:?}", s), } match Pin::new(&mut foo).resume(()) { - GeneratorState::Complete(()) => {} + CoroutineState::Complete(()) => {} s => panic!("bad state: {:?}", s), } } diff --git a/tests/ui/generator/yield-in-args-rev.rs b/tests/ui/coroutine/yield-in-args-rev.rs similarity index 78% rename from tests/ui/generator/yield-in-args-rev.rs rename to tests/ui/coroutine/yield-in-args-rev.rs index 4c99bb3ef5ee1..b22c32ccd92db 100644 --- a/tests/ui/generator/yield-in-args-rev.rs +++ b/tests/ui/coroutine/yield-in-args-rev.rs @@ -5,12 +5,12 @@ // argument list is not treated as live across the yield by // type-checking. -#![feature(generators)] +#![feature(coroutines)] fn foo(_a: (), _b: &bool) {} fn bar() { - || { //~ WARN unused generator that must be used + || { //~ WARN unused coroutine that must be used let b = true; foo(yield, &b); }; diff --git a/tests/ui/generator/yield-in-args-rev.stderr b/tests/ui/coroutine/yield-in-args-rev.stderr similarity index 68% rename from tests/ui/generator/yield-in-args-rev.stderr rename to tests/ui/coroutine/yield-in-args-rev.stderr index a87248f662100..dbf46739e8bf1 100644 --- a/tests/ui/generator/yield-in-args-rev.stderr +++ b/tests/ui/coroutine/yield-in-args-rev.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/yield-in-args-rev.rs:13:5 | LL | / || { @@ -7,7 +7,7 @@ LL | | foo(yield, &b); LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/generator/yield-in-args.rs b/tests/ui/coroutine/yield-in-args.rs similarity index 82% rename from tests/ui/generator/yield-in-args.rs rename to tests/ui/coroutine/yield-in-args.rs index 80110af55ab07..b2827148d771a 100644 --- a/tests/ui/generator/yield-in-args.rs +++ b/tests/ui/coroutine/yield-in-args.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] fn foo(_b: &bool, _a: ()) {} diff --git a/tests/ui/generator/yield-in-args.stderr b/tests/ui/coroutine/yield-in-args.stderr similarity index 78% rename from tests/ui/generator/yield-in-args.stderr rename to tests/ui/coroutine/yield-in-args.stderr index ee6d22c27cde8..4ff97281d7b42 100644 --- a/tests/ui/generator/yield-in-args.stderr +++ b/tests/ui/coroutine/yield-in-args.stderr @@ -1,4 +1,4 @@ -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-in-args.rs:8:13 | LL | foo(&b, yield); diff --git a/tests/ui/generator/yield-in-const.rs b/tests/ui/coroutine/yield-in-const.rs similarity index 77% rename from tests/ui/generator/yield-in-const.rs rename to tests/ui/coroutine/yield-in-const.rs index fe5ca822ceca1..22651f32cf85a 100644 --- a/tests/ui/generator/yield-in-const.rs +++ b/tests/ui/coroutine/yield-in-const.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] const A: u8 = { yield 3u8; 3u8}; //~^ ERROR yield expression outside diff --git a/tests/ui/generator/yield-in-const.stderr b/tests/ui/coroutine/yield-in-const.stderr similarity index 78% rename from tests/ui/generator/yield-in-const.stderr rename to tests/ui/coroutine/yield-in-const.stderr index dcf4fe63e64bc..7afcd83403ebc 100644 --- a/tests/ui/generator/yield-in-const.stderr +++ b/tests/ui/coroutine/yield-in-const.stderr @@ -1,4 +1,4 @@ -error[E0627]: yield expression outside of generator literal +error[E0627]: yield expression outside of coroutine literal --> $DIR/yield-in-const.rs:3:17 | LL | const A: u8 = { yield 3u8; 3u8}; diff --git a/tests/ui/generator/yield-in-function.rs b/tests/ui/coroutine/yield-in-function.rs similarity index 70% rename from tests/ui/generator/yield-in-function.rs rename to tests/ui/coroutine/yield-in-function.rs index 29b811621de1e..a99312043bdb9 100644 --- a/tests/ui/generator/yield-in-function.rs +++ b/tests/ui/coroutine/yield-in-function.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] fn main() { yield; } //~^ ERROR yield expression outside diff --git a/tests/ui/generator/yield-in-function.stderr b/tests/ui/coroutine/yield-in-function.stderr similarity index 76% rename from tests/ui/generator/yield-in-function.stderr rename to tests/ui/coroutine/yield-in-function.stderr index 51cce198ca3b4..b2f839a65db08 100644 --- a/tests/ui/generator/yield-in-function.stderr +++ b/tests/ui/coroutine/yield-in-function.stderr @@ -1,4 +1,4 @@ -error[E0627]: yield expression outside of generator literal +error[E0627]: yield expression outside of coroutine literal --> $DIR/yield-in-function.rs:3:13 | LL | fn main() { yield; } diff --git a/tests/ui/generator/yield-in-initializer.rs b/tests/ui/coroutine/yield-in-initializer.rs similarity index 79% rename from tests/ui/generator/yield-in-initializer.rs rename to tests/ui/coroutine/yield-in-initializer.rs index 0cab36e5f2880..5a7b3a4feafbe 100644 --- a/tests/ui/generator/yield-in-initializer.rs +++ b/tests/ui/coroutine/yield-in-initializer.rs @@ -1,9 +1,9 @@ // run-pass -#![feature(generators)] +#![feature(coroutines)] fn main() { - static || { //~ WARN unused generator that must be used + static || { //~ WARN unused coroutine that must be used loop { // Test that `opt` is not live across the yield, even when borrowed in a loop // See https://github.com/rust-lang/rust/issues/52792 diff --git a/tests/ui/generator/yield-in-initializer.stderr b/tests/ui/coroutine/yield-in-initializer.stderr similarity index 79% rename from tests/ui/generator/yield-in-initializer.stderr rename to tests/ui/coroutine/yield-in-initializer.stderr index ed14a2e3273af..614df43f2f58f 100644 --- a/tests/ui/generator/yield-in-initializer.stderr +++ b/tests/ui/coroutine/yield-in-initializer.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/yield-in-initializer.rs:6:5 | LL | / static || { @@ -10,7 +10,7 @@ LL | | } LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/generator/yield-in-static.rs b/tests/ui/coroutine/yield-in-static.rs similarity index 77% rename from tests/ui/generator/yield-in-static.rs rename to tests/ui/coroutine/yield-in-static.rs index d27fbb33ba10a..45e0380d46d9f 100644 --- a/tests/ui/generator/yield-in-static.rs +++ b/tests/ui/coroutine/yield-in-static.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] static B: u8 = { yield 3u8; 3u8}; //~^ ERROR yield expression outside diff --git a/tests/ui/generator/yield-in-static.stderr b/tests/ui/coroutine/yield-in-static.stderr similarity index 78% rename from tests/ui/generator/yield-in-static.stderr rename to tests/ui/coroutine/yield-in-static.stderr index d867f3ad34528..17d58325e9868 100644 --- a/tests/ui/generator/yield-in-static.stderr +++ b/tests/ui/coroutine/yield-in-static.stderr @@ -1,4 +1,4 @@ -error[E0627]: yield expression outside of generator literal +error[E0627]: yield expression outside of coroutine literal --> $DIR/yield-in-static.rs:3:18 | LL | static B: u8 = { yield 3u8; 3u8}; diff --git a/tests/ui/generator/yield-outside-generator-issue-78653.rs b/tests/ui/coroutine/yield-outside-coroutine-issue-78653.rs similarity index 51% rename from tests/ui/generator/yield-outside-generator-issue-78653.rs rename to tests/ui/coroutine/yield-outside-coroutine-issue-78653.rs index 4e8050c81b0d3..31025c33b1a26 100644 --- a/tests/ui/generator/yield-outside-generator-issue-78653.rs +++ b/tests/ui/coroutine/yield-outside-coroutine-issue-78653.rs @@ -1,7 +1,7 @@ -#![feature(generators)] +#![feature(coroutines)] fn main() { yield || for i in 0 { } - //~^ ERROR yield expression outside of generator literal + //~^ ERROR yield expression outside of coroutine literal //~| ERROR `{integer}` is not an iterator } diff --git a/tests/ui/generator/yield-outside-generator-issue-78653.stderr b/tests/ui/coroutine/yield-outside-coroutine-issue-78653.stderr similarity index 79% rename from tests/ui/generator/yield-outside-generator-issue-78653.stderr rename to tests/ui/coroutine/yield-outside-coroutine-issue-78653.stderr index dcfb211744ced..f28f8913508f2 100644 --- a/tests/ui/generator/yield-outside-generator-issue-78653.stderr +++ b/tests/ui/coroutine/yield-outside-coroutine-issue-78653.stderr @@ -1,11 +1,11 @@ -error[E0627]: yield expression outside of generator literal - --> $DIR/yield-outside-generator-issue-78653.rs:4:5 +error[E0627]: yield expression outside of coroutine literal + --> $DIR/yield-outside-coroutine-issue-78653.rs:4:5 | LL | yield || for i in 0 { } | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: `{integer}` is not an iterator - --> $DIR/yield-outside-generator-issue-78653.rs:4:23 + --> $DIR/yield-outside-coroutine-issue-78653.rs:4:23 | LL | yield || for i in 0 { } | ^ `{integer}` is not an iterator diff --git a/tests/ui/generator/yield-subtype.rs b/tests/ui/coroutine/yield-subtype.rs similarity index 70% rename from tests/ui/generator/yield-subtype.rs rename to tests/ui/coroutine/yield-subtype.rs index cb3fc909145c2..3595d449823e3 100644 --- a/tests/ui/generator/yield-subtype.rs +++ b/tests/ui/coroutine/yield-subtype.rs @@ -2,13 +2,13 @@ #![allow(dead_code)] #![allow(dead_code)] -#![feature(generators)] +#![feature(coroutines)] fn bar<'a>() { let a: &'static str = "hi"; let b: &'a str = a; - || { //~ WARN unused generator that must be used + || { //~ WARN unused coroutine that must be used yield a; yield b; }; diff --git a/tests/ui/generator/yield-subtype.stderr b/tests/ui/coroutine/yield-subtype.stderr similarity index 67% rename from tests/ui/generator/yield-subtype.stderr rename to tests/ui/coroutine/yield-subtype.stderr index 97862e91cd4a0..5e7ae9f581eb1 100644 --- a/tests/ui/generator/yield-subtype.stderr +++ b/tests/ui/coroutine/yield-subtype.stderr @@ -1,4 +1,4 @@ -warning: unused generator that must be used +warning: unused coroutine that must be used --> $DIR/yield-subtype.rs:11:5 | LL | / || { @@ -7,7 +7,7 @@ LL | | yield b; LL | | }; | |_____^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/generator/yield-while-iterating.rs b/tests/ui/coroutine/yield-while-iterating.rs similarity index 91% rename from tests/ui/generator/yield-while-iterating.rs rename to tests/ui/coroutine/yield-while-iterating.rs index 985e5d8bdc838..66ac6d3922a9c 100644 --- a/tests/ui/generator/yield-while-iterating.rs +++ b/tests/ui/coroutine/yield-while-iterating.rs @@ -1,11 +1,11 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{GeneratorState, Generator}; +use std::ops::{CoroutineState, Coroutine}; use std::cell::Cell; use std::pin::Pin; fn yield_during_iter_owned_data(x: Vec) { - // The generator owns `x`, so we error out when yielding with a + // The coroutine owns `x`, so we error out when yielding with a // reference to it. This winds up becoming a rather confusing // regionck error -- in particular, we would freeze with the // reference in scope, and it doesn't live long enough. diff --git a/tests/ui/generator/yield-while-iterating.stderr b/tests/ui/coroutine/yield-while-iterating.stderr similarity index 91% rename from tests/ui/generator/yield-while-iterating.stderr rename to tests/ui/coroutine/yield-while-iterating.stderr index b6563475235c2..5330121f3728f 100644 --- a/tests/ui/generator/yield-while-iterating.stderr +++ b/tests/ui/coroutine/yield-while-iterating.stderr @@ -1,4 +1,4 @@ -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-while-iterating.rs:13:18 | LL | for p in &x { @@ -12,7 +12,7 @@ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as muta LL | let mut b = || { | -- mutable borrow occurs here LL | for p in &mut x { - | - first borrow occurs due to use of `x` in generator + | - first borrow occurs due to use of `x` in coroutine ... LL | println!("{}", x[0]); | ^ immutable borrow occurs here diff --git a/tests/ui/generator/yield-while-local-borrowed.rs b/tests/ui/coroutine/yield-while-local-borrowed.rs similarity index 77% rename from tests/ui/generator/yield-while-local-borrowed.rs rename to tests/ui/coroutine/yield-while-local-borrowed.rs index 061a64dbc364d..7f8d1d4543d89 100644 --- a/tests/ui/generator/yield-while-local-borrowed.rs +++ b/tests/ui/coroutine/yield-while-local-borrowed.rs @@ -1,7 +1,7 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{GeneratorState, Generator}; use std::cell::Cell; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; fn borrow_local_inline() { @@ -11,8 +11,8 @@ fn borrow_local_inline() { // `b` and gets extended by region inference.) let mut b = move || { let a = &mut 3; - //~^ ERROR borrow may still be in use when generator yields - yield(); + //~^ ERROR borrow may still be in use when coroutine yields + yield (); println!("{}", a); }; Pin::new(&mut b).resume(()); @@ -24,7 +24,7 @@ fn borrow_local_inline_done() { { let a = &mut 3; } - yield(); + yield (); }; Pin::new(&mut b).resume(()); } @@ -38,12 +38,12 @@ fn borrow_local() { let a = 3; { let b = &a; - //~^ ERROR borrow may still be in use when generator yields - yield(); + //~^ ERROR borrow may still be in use when coroutine yields + yield (); println!("{}", b); } }; Pin::new(&mut b).resume(()); } -fn main() { } +fn main() {} diff --git a/tests/ui/generator/yield-while-local-borrowed.stderr b/tests/ui/coroutine/yield-while-local-borrowed.stderr similarity index 55% rename from tests/ui/generator/yield-while-local-borrowed.stderr rename to tests/ui/coroutine/yield-while-local-borrowed.stderr index c1513ef9b7157..8fe981de929a1 100644 --- a/tests/ui/generator/yield-while-local-borrowed.stderr +++ b/tests/ui/coroutine/yield-while-local-borrowed.stderr @@ -1,20 +1,20 @@ -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-while-local-borrowed.rs:13:17 | LL | let a = &mut 3; | ^^^^^^ LL | -LL | yield(); - | ------- possible yield occurs here +LL | yield (); + | -------- possible yield occurs here -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/yield-while-local-borrowed.rs:40:21 | LL | let b = &a; | ^^ LL | -LL | yield(); - | ------- possible yield occurs here +LL | yield (); + | -------- possible yield occurs here error: aborting due to 2 previous errors diff --git a/tests/ui/generator/yield-while-ref-reborrowed.rs b/tests/ui/coroutine/yield-while-ref-reborrowed.rs similarity index 82% rename from tests/ui/generator/yield-while-ref-reborrowed.rs rename to tests/ui/coroutine/yield-while-ref-reborrowed.rs index a03ef945dd231..07c591758586b 100644 --- a/tests/ui/generator/yield-while-ref-reborrowed.rs +++ b/tests/ui/coroutine/yield-while-ref-reborrowed.rs @@ -1,12 +1,12 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{GeneratorState, Generator}; +use std::ops::{CoroutineState, Coroutine}; use std::cell::Cell; use std::pin::Pin; fn reborrow_shared_ref(x: &i32) { // This is OK -- we have a borrow live over the yield, but it's of - // data that outlives the generator. + // data that outlives the coroutine. let mut b = move || { let a = &*x; yield(); @@ -17,7 +17,7 @@ fn reborrow_shared_ref(x: &i32) { fn reborrow_mutable_ref(x: &mut i32) { // This is OK -- we have a borrow live over the yield, but it's of - // data that outlives the generator. + // data that outlives the coroutine. let mut b = move || { let a = &mut *x; yield(); diff --git a/tests/ui/generator/yield-while-ref-reborrowed.stderr b/tests/ui/coroutine/yield-while-ref-reborrowed.stderr similarity index 90% rename from tests/ui/generator/yield-while-ref-reborrowed.stderr rename to tests/ui/coroutine/yield-while-ref-reborrowed.stderr index 47147f9c05d78..e60a953162289 100644 --- a/tests/ui/generator/yield-while-ref-reborrowed.stderr +++ b/tests/ui/coroutine/yield-while-ref-reborrowed.stderr @@ -2,9 +2,9 @@ error[E0501]: cannot borrow `x` as immutable because previous closure requires u --> $DIR/yield-while-ref-reborrowed.rs:36:20 | LL | let mut b = || { - | -- generator construction occurs here + | -- coroutine construction occurs here LL | let a = &mut *x; - | -- first borrow occurs due to use of `x` in generator + | -- first borrow occurs due to use of `x` in coroutine ... LL | println!("{}", x); | ^ second borrow occurs here diff --git a/tests/ui/generator/yielding-in-match-guards.rs b/tests/ui/coroutine/yielding-in-match-guards.rs similarity index 96% rename from tests/ui/generator/yielding-in-match-guards.rs rename to tests/ui/coroutine/yielding-in-match-guards.rs index 4e89fc975d04c..a9575a9e77e24 100644 --- a/tests/ui/generator/yielding-in-match-guards.rs +++ b/tests/ui/coroutine/yielding-in-match-guards.rs @@ -8,7 +8,7 @@ // indeed a temporary borrow `y` from `x` is live // while `f().await` is being evaluated. // Thus, `&'_ u8` should be included in type signature -// of the underlying generator. +// of the underlying coroutine. #![feature(if_let_guard)] diff --git a/tests/ui/drop/dynamic-drop.rs b/tests/ui/drop/dynamic-drop.rs index caef6358ea782..5bf2cc30e7fd6 100644 --- a/tests/ui/drop/dynamic-drop.rs +++ b/tests/ui/drop/dynamic-drop.rs @@ -1,7 +1,7 @@ // run-pass // needs-unwind -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] #![feature(if_let_guard)] #![allow(unused_assignments)] @@ -9,7 +9,7 @@ use std::cell::{Cell, RefCell}; use std::mem::ManuallyDrop; -use std::ops::Generator; +use std::ops::Coroutine; use std::panic; use std::pin::Pin; @@ -173,7 +173,7 @@ fn vec_simple(a: &Allocator) { let _x = vec![a.alloc(), a.alloc(), a.alloc(), a.alloc()]; } -fn generator(a: &Allocator, run_count: usize) { +fn coroutine(a: &Allocator, run_count: usize) { assert!(run_count < 4); let mut gen = || { @@ -471,10 +471,10 @@ fn main() { run_test(|a| field_assignment(a, false)); run_test(|a| field_assignment(a, true)); - run_test(|a| generator(a, 0)); - run_test(|a| generator(a, 1)); - run_test(|a| generator(a, 2)); - run_test(|a| generator(a, 3)); + run_test(|a| coroutine(a, 0)); + run_test(|a| coroutine(a, 1)); + run_test(|a| coroutine(a, 2)); + run_test(|a| coroutine(a, 3)); run_test(|a| mixed_drop_and_nondrop(a)); diff --git a/tests/ui/error-codes/E0283.rs b/tests/ui/error-codes/E0283.rs index 0643af4b7e8c6..5134660e3f4bd 100644 --- a/tests/ui/error-codes/E0283.rs +++ b/tests/ui/error-codes/E0283.rs @@ -1,10 +1,10 @@ -trait Generator { +trait Coroutine { fn create() -> u32; } struct Impl; -impl Generator for Impl { +impl Coroutine for Impl { fn create() -> u32 { 1 } } @@ -22,12 +22,12 @@ fn foo(bar: u32) {} struct AnotherImpl; -impl Generator for AnotherImpl { +impl Coroutine for AnotherImpl { fn create() -> u32 { 2 } } fn main() { - let cont: u32 = Generator::create(); //~ ERROR E0790 + let cont: u32 = Coroutine::create(); //~ ERROR E0790 } fn buzz() { diff --git a/tests/ui/error-codes/E0283.stderr b/tests/ui/error-codes/E0283.stderr index fa8d4b6e01577..6008809f050f8 100644 --- a/tests/ui/error-codes/E0283.stderr +++ b/tests/ui/error-codes/E0283.stderr @@ -2,14 +2,14 @@ error[E0790]: cannot call associated function on trait without specifying the co --> $DIR/E0283.rs:30:21 | LL | fn create() -> u32; - | ------------------- `Generator::create` defined here + | ------------------- `Coroutine::create` defined here ... -LL | let cont: u32 = Generator::create(); +LL | let cont: u32 = Coroutine::create(); | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait | help: use a fully-qualified path to a specific available implementation | -LL | let cont: u32 = ::create(); +LL | let cont: u32 = ::create(); | +++++++++++++++++++ + error[E0283]: type annotations needed diff --git a/tests/ui/feature-gates/feature-gate-closure_track_caller.rs b/tests/ui/feature-gates/feature-gate-closure_track_caller.rs index a4c91f3bc1880..58a9c84be5acf 100644 --- a/tests/ui/feature-gates/feature-gate-closure_track_caller.rs +++ b/tests/ui/feature-gates/feature-gate-closure_track_caller.rs @@ -1,9 +1,9 @@ // edition:2021 #![feature(stmt_expr_attributes)] -#![feature(generators)] +#![feature(coroutines)] fn main() { let _closure = #[track_caller] || {}; //~ `#[track_caller]` on closures - let _generator = #[track_caller] || { yield; }; //~ `#[track_caller]` on closures + let _coroutine = #[track_caller] || { yield; }; //~ `#[track_caller]` on closures let _future = #[track_caller] async {}; //~ `#[track_caller]` on closures } diff --git a/tests/ui/feature-gates/feature-gate-closure_track_caller.stderr b/tests/ui/feature-gates/feature-gate-closure_track_caller.stderr index cf2ea5fe1cac3..d5ef5d09ed451 100644 --- a/tests/ui/feature-gates/feature-gate-closure_track_caller.stderr +++ b/tests/ui/feature-gates/feature-gate-closure_track_caller.stderr @@ -10,7 +10,7 @@ LL | let _closure = #[track_caller] || {}; error[E0658]: `#[track_caller]` on closures is currently unstable --> $DIR/feature-gate-closure_track_caller.rs:7:22 | -LL | let _generator = #[track_caller] || { yield; }; +LL | let _coroutine = #[track_caller] || { yield; }; | ^^^^^^^^^^^^^^^ | = note: see issue #87417 for more information diff --git a/tests/ui/feature-gates/feature-gate-generators.rs b/tests/ui/feature-gates/feature-gate-coroutines.rs similarity index 76% rename from tests/ui/feature-gates/feature-gate-generators.rs rename to tests/ui/feature-gates/feature-gate-coroutines.rs index 931fee1347126..c3c5aec88248a 100644 --- a/tests/ui/feature-gates/feature-gate-generators.rs +++ b/tests/ui/feature-gates/feature-gate-coroutines.rs @@ -1,6 +1,6 @@ fn main() { yield true; //~ ERROR yield syntax is experimental - //~^ ERROR yield expression outside of generator literal + //~^ ERROR yield expression outside of coroutine literal } #[cfg(FALSE)] diff --git a/tests/ui/feature-gates/feature-gate-generators.stderr b/tests/ui/feature-gates/feature-gate-coroutines.stderr similarity index 65% rename from tests/ui/feature-gates/feature-gate-generators.stderr rename to tests/ui/feature-gates/feature-gate-coroutines.stderr index dfea178a6372c..dd56164390118 100644 --- a/tests/ui/feature-gates/feature-gate-generators.stderr +++ b/tests/ui/feature-gates/feature-gate-coroutines.stderr @@ -1,32 +1,32 @@ error[E0658]: yield syntax is experimental - --> $DIR/feature-gate-generators.rs:2:5 + --> $DIR/feature-gate-coroutines.rs:2:5 | LL | yield true; | ^^^^^^^^^^ | = note: see issue #43122 for more information - = help: add `#![feature(generators)]` to the crate attributes to enable + = help: add `#![feature(coroutines)]` to the crate attributes to enable error[E0658]: yield syntax is experimental - --> $DIR/feature-gate-generators.rs:8:5 + --> $DIR/feature-gate-coroutines.rs:8:5 | LL | yield; | ^^^^^ | = note: see issue #43122 for more information - = help: add `#![feature(generators)]` to the crate attributes to enable + = help: add `#![feature(coroutines)]` to the crate attributes to enable error[E0658]: yield syntax is experimental - --> $DIR/feature-gate-generators.rs:9:5 + --> $DIR/feature-gate-coroutines.rs:9:5 | LL | yield 0; | ^^^^^^^ | = note: see issue #43122 for more information - = help: add `#![feature(generators)]` to the crate attributes to enable + = help: add `#![feature(coroutines)]` to the crate attributes to enable -error[E0627]: yield expression outside of generator literal - --> $DIR/feature-gate-generators.rs:2:5 +error[E0627]: yield expression outside of coroutine literal + --> $DIR/feature-gate-coroutines.rs:2:5 | LL | yield true; | ^^^^^^^^^^ diff --git a/tests/ui/generator/async-generator-issue-67158.rs b/tests/ui/generator/async-generator-issue-67158.rs deleted file mode 100644 index 8125a7a9bb664..0000000000000 --- a/tests/ui/generator/async-generator-issue-67158.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![feature(generators)] -// edition:2018 -// Regression test for #67158. -fn main() { - async { yield print!(":C") }; //~ ERROR `async` generators are not yet supported -} diff --git a/tests/ui/generator/auxiliary/metadata-sufficient-for-layout.rs b/tests/ui/generator/auxiliary/metadata-sufficient-for-layout.rs deleted file mode 100644 index 207c2735f8886..0000000000000 --- a/tests/ui/generator/auxiliary/metadata-sufficient-for-layout.rs +++ /dev/null @@ -1,11 +0,0 @@ -// compile-flags: --emit metadata -#![feature(generators, generator_trait)] - -use std::marker::Unpin; -use std::ops::Generator; - -pub fn g() -> impl Generator<(), Yield = (), Return = ()> { - || { - yield; - } -} diff --git a/tests/ui/generator/auxiliary/xcrate-reachable.rs b/tests/ui/generator/auxiliary/xcrate-reachable.rs deleted file mode 100644 index 2dd5ea675233c..0000000000000 --- a/tests/ui/generator/auxiliary/xcrate-reachable.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(generators, generator_trait)] - -use std::ops::Generator; - -fn msg() -> u32 { - 0 -} - -pub fn foo() -> impl Generator<(), Yield=(), Return=u32> { - || { - yield; - return msg(); - } -} diff --git a/tests/ui/generator/auxiliary/xcrate.rs b/tests/ui/generator/auxiliary/xcrate.rs deleted file mode 100644 index d07abd0918c78..0000000000000 --- a/tests/ui/generator/auxiliary/xcrate.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![feature(generators, generator_trait)] - -use std::marker::Unpin; -use std::ops::Generator; - -pub fn foo() -> impl Generator<(), Yield = (), Return = ()> { - || { - if false { - yield; - } - } -} - -pub fn bar(t: T) -> Box + Unpin> { - Box::new(|| { - yield t; - }) -} diff --git a/tests/ui/generator/generator-yielding-or-returning-itself.rs b/tests/ui/generator/generator-yielding-or-returning-itself.rs deleted file mode 100644 index 30788e3c1864b..0000000000000 --- a/tests/ui/generator/generator-yielding-or-returning-itself.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![feature(generator_trait)] -#![feature(generators)] - -// Test that we cannot create a generator that returns a value of its -// own type. - -use std::ops::Generator; - -pub fn want_cyclic_generator_return(_: T) - where T: Generator -{ -} - -fn supply_cyclic_generator_return() { - want_cyclic_generator_return(|| { - //~^ ERROR type mismatch - if false { yield None.unwrap(); } - None.unwrap() - }) -} - -pub fn want_cyclic_generator_yield(_: T) - where T: Generator -{ -} - -fn supply_cyclic_generator_yield() { - want_cyclic_generator_yield(|| { - //~^ ERROR type mismatch - if false { yield None.unwrap(); } - None.unwrap() - }) -} - -fn main() { } diff --git a/tests/ui/generator/issue-52304.rs b/tests/ui/generator/issue-52304.rs deleted file mode 100644 index 3e9de765b12b2..0000000000000 --- a/tests/ui/generator/issue-52304.rs +++ /dev/null @@ -1,11 +0,0 @@ -// check-pass - -#![feature(generators, generator_trait)] - -use std::ops::Generator; - -pub fn example() -> impl Generator { - || yield &1 -} - -fn main() {} diff --git a/tests/ui/generator/issue-64620-yield-array-element.rs b/tests/ui/generator/issue-64620-yield-array-element.rs deleted file mode 100644 index 2cbe8f5161465..0000000000000 --- a/tests/ui/generator/issue-64620-yield-array-element.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Regression test for #64620 - -#![feature(generators)] - -pub fn crash(arr: [usize; 1]) { - yield arr[0]; //~ ERROR: yield expression outside of generator literal -} - -fn main() {} diff --git a/tests/ui/generator/issue-87142.rs b/tests/ui/generator/issue-87142.rs deleted file mode 100644 index 7f670919ed603..0000000000000 --- a/tests/ui/generator/issue-87142.rs +++ /dev/null @@ -1,32 +0,0 @@ -// compile-flags: -Cdebuginfo=2 -// build-pass - -// Regression test for #87142 -// This test needs the above flags and the "lib" crate type. - -#![feature(impl_trait_in_assoc_type, generator_trait, generators)] -#![crate_type = "lib"] - -use std::ops::Generator; - -pub trait GeneratorProviderAlt: Sized { - type Gen: Generator<(), Return = (), Yield = ()>; - - fn start(ctx: Context) -> Self::Gen; -} - -pub struct Context { - pub link: Box, -} - -impl GeneratorProviderAlt for () { - type Gen = impl Generator<(), Return = (), Yield = ()>; - fn start(ctx: Context) -> Self::Gen { - move || { - match ctx { - _ => (), - } - yield (); - } - } -} diff --git a/tests/ui/generator/nested_generators.rs b/tests/ui/generator/nested_generators.rs deleted file mode 100644 index 45519150eec2b..0000000000000 --- a/tests/ui/generator/nested_generators.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass - -#![feature(generators, generator_trait)] - -use std::ops::{Generator, GeneratorState}; -use std::pin::Pin; - -fn main() { - let _generator = || { - let mut sub_generator = || { - yield 2; - }; - - match Pin::new(&mut sub_generator).resume(()) { - GeneratorState::Yielded(x) => { - yield x; - } - _ => panic!(), - }; - }; -} diff --git a/tests/ui/generator/pin-box-generator.rs b/tests/ui/generator/pin-box-generator.rs deleted file mode 100644 index c3136f5c0ec82..0000000000000 --- a/tests/ui/generator/pin-box-generator.rs +++ /dev/null @@ -1,13 +0,0 @@ -// run-pass - -#![feature(generators, generator_trait)] - -use std::ops::Generator; - -fn assert_generator(_: G) { -} - -fn main() { - assert_generator(static || yield); - assert_generator(Box::pin(static || yield)); -} diff --git a/tests/ui/generator/sized-yield.rs b/tests/ui/generator/sized-yield.rs deleted file mode 100644 index c6dd738d6ac60..0000000000000 --- a/tests/ui/generator/sized-yield.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(generators, generator_trait)] - -use std::ops::Generator; -use std::pin::Pin; - -fn main() { - let s = String::from("foo"); - let mut gen = move || { - //~^ ERROR the size for values of type - yield s[..]; - }; - Pin::new(&mut gen).resume(()); - //~^ ERROR the size for values of type -} diff --git a/tests/ui/generator/sized-yield.stderr b/tests/ui/generator/sized-yield.stderr deleted file mode 100644 index fb34540d969da..0000000000000 --- a/tests/ui/generator/sized-yield.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/sized-yield.rs:8:26 - | -LL | let mut gen = move || { - | __________________________^ -LL | | -LL | | yield s[..]; -LL | | }; - | |____^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` - = note: the yield type of a generator must have a statically known size - -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/sized-yield.rs:12:23 - | -LL | Pin::new(&mut gen).resume(()); - | ^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` -note: required by a bound in `GeneratorState` - --> $SRC_DIR/core/src/ops/generator.rs:LL:COL - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/generator/static-generators.rs b/tests/ui/generator/static-generators.rs deleted file mode 100644 index d098bf1e68812..0000000000000 --- a/tests/ui/generator/static-generators.rs +++ /dev/null @@ -1,20 +0,0 @@ -// run-pass - -#![feature(generators, generator_trait)] - -use std::pin::Pin; -use std::ops::{Generator, GeneratorState}; - -fn main() { - let mut generator = static || { - let a = true; - let b = &a; - yield; - assert_eq!(b as *const _, &a as *const _); - }; - // SAFETY: We shadow the original generator variable so have no safe API to - // move it after this point. - let mut generator = unsafe { Pin::new_unchecked(&mut generator) }; - assert_eq!(generator.as_mut().resume(()), GeneratorState::Yielded(())); - assert_eq!(generator.as_mut().resume(()), GeneratorState::Complete(())); -} diff --git a/tests/ui/generator/too-many-parameters.rs b/tests/ui/generator/too-many-parameters.rs deleted file mode 100644 index 7a353ea298b26..0000000000000 --- a/tests/ui/generator/too-many-parameters.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(generators)] - -fn main() { - |(), ()| { - //~^ error: too many parameters for a generator - yield; - }; -} diff --git a/tests/ui/generic-associated-types/bugs/issue-100013.rs b/tests/ui/generic-associated-types/bugs/issue-100013.rs index 973c548d785ed..b13b730d5d8b7 100644 --- a/tests/ui/generic-associated-types/bugs/issue-100013.rs +++ b/tests/ui/generic-associated-types/bugs/issue-100013.rs @@ -3,7 +3,7 @@ // edition: 2021 // We really should accept this, but we need implied bounds between the regions -// in a generator interior. +// in a coroutine interior. pub trait FutureIterator { type Future<'s, 'cx>: Send @@ -12,21 +12,21 @@ pub trait FutureIterator { } fn call() -> impl Send { - async { // a generator checked for autotrait impl `Send` + async { // a coroutine checked for autotrait impl `Send` let x = None::>; // a type referencing GAT async {}.await; // a yield point } } fn call2<'a, 'b, I: FutureIterator>() -> impl Send { - async { // a generator checked for autotrait impl `Send` + async { // a coroutine checked for autotrait impl `Send` let x = None::>; // a type referencing GAT async {}.await; // a yield point } } fn call3<'a: 'b, 'b, I: FutureIterator>() -> impl Send { - async { // a generator checked for autotrait impl `Send` + async { // a coroutine checked for autotrait impl `Send` let x = None::>; // a type referencing GAT async {}.await; // a yield point } diff --git a/tests/ui/generic-associated-types/bugs/issue-100013.stderr b/tests/ui/generic-associated-types/bugs/issue-100013.stderr index 93c69422f00c7..ff82aebfef911 100644 --- a/tests/ui/generic-associated-types/bugs/issue-100013.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-100013.stderr @@ -1,7 +1,7 @@ error: lifetime bound not satisfied --> $DIR/issue-100013.rs:15:5 | -LL | / async { // a generator checked for autotrait impl `Send` +LL | / async { // a coroutine checked for autotrait impl `Send` LL | | let x = None::>; // a type referencing GAT LL | | async {}.await; // a yield point LL | | } @@ -12,7 +12,7 @@ LL | | } error: lifetime bound not satisfied --> $DIR/issue-100013.rs:22:5 | -LL | / async { // a generator checked for autotrait impl `Send` +LL | / async { // a coroutine checked for autotrait impl `Send` LL | | let x = None::>; // a type referencing GAT LL | | async {}.await; // a yield point LL | | } @@ -27,7 +27,7 @@ LL | fn call2<'a, 'b, I: FutureIterator>() -> impl Send { | -- -- lifetime `'b` defined here | | | lifetime `'a` defined here -LL | async { // a generator checked for autotrait impl `Send` +LL | async { // a coroutine checked for autotrait impl `Send` LL | let x = None::>; // a type referencing GAT | ^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'b` | @@ -36,7 +36,7 @@ LL | let x = None::>; // a type referencing GAT error: lifetime bound not satisfied --> $DIR/issue-100013.rs:29:5 | -LL | / async { // a generator checked for autotrait impl `Send` +LL | / async { // a coroutine checked for autotrait impl `Send` LL | | let x = None::>; // a type referencing GAT LL | | async {}.await; // a yield point LL | | } diff --git a/tests/ui/impl-trait/bounds_regression.rs b/tests/ui/impl-trait/bounds_regression.rs index 31fc46203d329..f32d83c0c4001 100644 --- a/tests/ui/impl-trait/bounds_regression.rs +++ b/tests/ui/impl-trait/bounds_regression.rs @@ -1,6 +1,6 @@ // run-pass -pub trait FakeGenerator { +pub trait FakeCoroutine { type Yield; type Return; } @@ -9,15 +9,15 @@ pub trait FakeFuture { type Output; } -pub fn future_from_generator< - T: FakeGenerator +pub fn future_from_coroutine< + T: FakeCoroutine >(x: T) -> impl FakeFuture { GenFuture(x) } -struct GenFuture>(#[allow(unused_tuple_struct_fields)] T); +struct GenFuture>(#[allow(unused_tuple_struct_fields)] T); -impl> FakeFuture for GenFuture { +impl> FakeFuture for GenFuture { type Output = T::Return; } diff --git a/tests/ui/impl-trait/issues/issue-58504.rs b/tests/ui/impl-trait/issues/issue-58504.rs index f1d7b94ef2dbd..03b51ae92d189 100644 --- a/tests/ui/impl-trait/issues/issue-58504.rs +++ b/tests/ui/impl-trait/issues/issue-58504.rs @@ -1,12 +1,12 @@ -#![feature(generators, generator_trait, never_type)] +#![feature(coroutines, coroutine_trait, never_type)] -use std::ops::Generator; +use std::ops::Coroutine; -fn mk_gen() -> impl Generator { +fn mk_gen() -> impl Coroutine { || { loop { yield; } } } fn main() { - let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; + let gens: [impl Coroutine;2] = [ mk_gen(), mk_gen() ]; //~^ `impl Trait` only allowed in function and inherent method argument and return types } diff --git a/tests/ui/impl-trait/issues/issue-58504.stderr b/tests/ui/impl-trait/issues/issue-58504.stderr index 1be676ee075d3..49376f559cfcf 100644 --- a/tests/ui/impl-trait/issues/issue-58504.stderr +++ b/tests/ui/impl-trait/issues/issue-58504.stderr @@ -1,7 +1,7 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings --> $DIR/issue-58504.rs:10:16 | -LL | let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; +LL | let gens: [impl Coroutine;2] = [ mk_gen(), mk_gen() ]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/impl-trait/lifetimes.rs b/tests/ui/impl-trait/lifetimes.rs index 9a9843375e4c5..f853117a9c6e4 100644 --- a/tests/ui/impl-trait/lifetimes.rs +++ b/tests/ui/impl-trait/lifetimes.rs @@ -1,7 +1,7 @@ // run-pass #![allow(warnings)] -#![feature(generators)] +#![feature(coroutines)] use std::fmt::Debug; @@ -114,7 +114,7 @@ impl<'unnecessary_lifetime> MyVec { self.0.iter().flat_map(|inner_vec| inner_vec.iter()) } - fn generator_doesnt_capture_unnecessary_lifetime<'s: 's>() -> impl Sized { + fn coroutine_doesnt_capture_unnecessary_lifetime<'s: 's>() -> impl Sized { || yield } } diff --git a/tests/ui/impl-trait/recursive-generator.rs b/tests/ui/impl-trait/recursive-coroutine.rs similarity index 57% rename from tests/ui/impl-trait/recursive-generator.rs rename to tests/ui/impl-trait/recursive-coroutine.rs index 000af70c4540e..6351cef95a618 100644 --- a/tests/ui/impl-trait/recursive-generator.rs +++ b/tests/ui/impl-trait/recursive-coroutine.rs @@ -1,16 +1,16 @@ -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; -fn foo() -> impl Generator { +fn foo() -> impl Coroutine { //~^ ERROR cannot resolve opaque type //~| NOTE recursive opaque type //~| NOTE in this expansion of desugaring of || { let mut gen = Box::pin(foo()); - //~^ NOTE generator captures itself here + //~^ NOTE coroutine captures itself here let mut r = gen.as_mut().resume(()); - while let GeneratorState::Yielded(v) = r { + while let CoroutineState::Yielded(v) = r { yield v; r = gen.as_mut().resume(()); } diff --git a/tests/ui/impl-trait/recursive-generator.stderr b/tests/ui/impl-trait/recursive-coroutine.stderr similarity index 64% rename from tests/ui/impl-trait/recursive-generator.stderr rename to tests/ui/impl-trait/recursive-coroutine.stderr index 86e193d9599a1..d36a58a864343 100644 --- a/tests/ui/impl-trait/recursive-generator.stderr +++ b/tests/ui/impl-trait/recursive-coroutine.stderr @@ -1,11 +1,11 @@ error[E0720]: cannot resolve opaque type - --> $DIR/recursive-generator.rs:5:13 + --> $DIR/recursive-coroutine.rs:5:13 | -LL | fn foo() -> impl Generator { +LL | fn foo() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive opaque type ... LL | let mut gen = Box::pin(foo()); - | ------- generator captures itself here + | ------- coroutine captures itself here error: aborting due to previous error diff --git a/tests/ui/impl-trait/recursive-impl-trait-type-indirect.rs b/tests/ui/impl-trait/recursive-impl-trait-type-indirect.rs index ffc0cd9d10c34..8331eec906e10 100644 --- a/tests/ui/impl-trait/recursive-impl-trait-type-indirect.rs +++ b/tests/ui/impl-trait/recursive-impl-trait-type-indirect.rs @@ -1,7 +1,7 @@ // Test that impl trait does not allow creating recursive types that are // otherwise forbidden. -#![feature(generators)] +#![feature(coroutines)] #![allow(unconditional_recursion)] fn option(i: i32) -> impl Sized { @@ -50,14 +50,14 @@ fn closure_sig() -> impl Sized { || closure_sig() } -fn generator_sig() -> impl Sized { +fn coroutine_sig() -> impl Sized { //~^ ERROR - || generator_sig() + || coroutine_sig() } -fn generator_capture() -> impl Sized { +fn coroutine_capture() -> impl Sized { //~^ ERROR - let x = generator_capture(); + let x = coroutine_capture(); move || { yield; x; @@ -69,10 +69,10 @@ fn substs_change() -> impl Sized { (substs_change::<&T>(),) } -fn generator_hold() -> impl Sized { +fn coroutine_hold() -> impl Sized { //~^ ERROR move || { - let x = generator_hold(); + let x = coroutine_hold(); yield; x; } diff --git a/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr b/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr index 1d919fb524049..8e9aa8ad0a690 100644 --- a/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr +++ b/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr @@ -81,24 +81,24 @@ LL | || closure_sig() error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:53:23 | -LL | fn generator_sig() -> impl Sized { +LL | fn coroutine_sig() -> impl Sized { | ^^^^^^^^^^ recursive opaque type LL | -LL | || generator_sig() +LL | || coroutine_sig() | ------------------ returning here with type `{closure@$DIR/recursive-impl-trait-type-indirect.rs:55:5: 55:7}` error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:58:27 | -LL | fn generator_capture() -> impl Sized { +LL | fn coroutine_capture() -> impl Sized { | ^^^^^^^^^^ recursive opaque type ... LL | / move || { LL | | yield; LL | | x; - | | - generator captures itself here + | | - coroutine captures itself here LL | | } - | |_____- returning here with type `{generator@$DIR/recursive-impl-trait-type-indirect.rs:61:5: 61:12}` + | |_____- returning here with type `{coroutine@$DIR/recursive-impl-trait-type-indirect.rs:61:5: 61:12}` error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:67:35 @@ -112,11 +112,11 @@ LL | (substs_change::<&T>(),) error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:72:24 | -LL | fn generator_hold() -> impl Sized { +LL | fn coroutine_hold() -> impl Sized { | ^^^^^^^^^^ recursive opaque type ... -LL | let x = generator_hold(); - | - generator captures itself here +LL | let x = coroutine_hold(); + | - coroutine captures itself here error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:86:26 diff --git a/tests/ui/lazy-type-alias-impl-trait/freeze_cycle.rs b/tests/ui/lazy-type-alias-impl-trait/freeze_cycle.rs index f02a93ed41b9a..80aba0ba04d85 100644 --- a/tests/ui/lazy-type-alias-impl-trait/freeze_cycle.rs +++ b/tests/ui/lazy-type-alias-impl-trait/freeze_cycle.rs @@ -1,8 +1,8 @@ // check-pass -#![feature(generator_trait, negative_impls)] +#![feature(coroutine_trait, negative_impls)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::task::{Poll, Context}; use std::future::{Future}; use std::ptr::NonNull; @@ -17,27 +17,27 @@ unsafe impl Send for ResumeTy {} unsafe impl Sync for ResumeTy {} -pub const fn from_generator(gen: T) -> impl Future +pub const fn from_coroutine(gen: T) -> impl Future where - T: Generator, + T: Coroutine, { - struct GenFuture>(T); + struct GenFuture>(T); // We rely on the fact that async/await futures are immovable in order to create - // self-referential borrows in the underlying generator. - impl> !Unpin for GenFuture {} + // self-referential borrows in the underlying coroutine. + impl> !Unpin for GenFuture {} - impl> Future for GenFuture { + impl> Future for GenFuture { type Output = T::Return; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { // SAFETY: Safe because we're !Unpin + !Drop, and this is just a field projection. let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) }; - // Resume the generator, turning the `&mut Context` into a `NonNull` raw pointer. The + // Resume the coroutine, turning the `&mut Context` into a `NonNull` raw pointer. The // `.await` lowering will safely cast that back to a `&mut Context`. match gen.resume(ResumeTy(NonNull::from(cx).cast::>())) { - GeneratorState::Yielded(()) => Poll::Pending, - GeneratorState::Complete(x) => Poll::Ready(x), + CoroutineState::Yielded(()) => Poll::Pending, + CoroutineState::Complete(x) => Poll::Ready(x), } } } diff --git a/tests/ui/lifetimes/issue-77175.rs b/tests/ui/lifetimes/issue-77175.rs index 2282752b6c1fe..8072691ae3c9b 100644 --- a/tests/ui/lifetimes/issue-77175.rs +++ b/tests/ui/lifetimes/issue-77175.rs @@ -5,7 +5,7 @@ // Prior to the fix, the compiler complained that the 'a lifetime was only used // once. This was obviously wrong since the lifetime is used twice: For the s3 // parameter and the return type. The issue was caused by the compiler -// desugaring the async function into a generator that uses only a single +// desugaring the async function into a coroutine that uses only a single // lifetime, which then the validator complained about becauase of the // single_use_lifetimes constraints. async fn bar<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str { diff --git a/tests/ui/lint/must_not_suspend/tuple-mismatch.rs b/tests/ui/lint/must_not_suspend/tuple-mismatch.rs index c7e14e4256138..2f3c5d9ea294d 100644 --- a/tests/ui/lint/must_not_suspend/tuple-mismatch.rs +++ b/tests/ui/lint/must_not_suspend/tuple-mismatch.rs @@ -1,7 +1,7 @@ -#![feature(generators)] +#![feature(coroutines)] fn main() { - let _generator = || { + let _coroutine = || { yield ((), ((), ())); yield ((), ()); //~^ ERROR mismatched types diff --git a/tests/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs b/tests/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs index 8064c3a88d1d9..c5dd281cb4e5f 100644 --- a/tests/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs +++ b/tests/ui/lint/unused/issue-74883-unused-paren-baren-yield.rs @@ -1,8 +1,8 @@ -#![feature(generator_trait)] -#![feature(generators)] +#![feature(coroutine_trait)] +#![feature(coroutines)] #![deny(unused_braces, unused_parens)] -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; fn main() { diff --git a/tests/ui/lint/unused/unused-closure.rs b/tests/ui/lint/unused/unused-closure.rs index c96c907318ce9..12ee8b3a9bb8b 100644 --- a/tests/ui/lint/unused/unused-closure.rs +++ b/tests/ui/lint/unused/unused-closure.rs @@ -1,8 +1,8 @@ -// Test that closures and generators are "must use" types. +// Test that closures and coroutines are "must use" types. // edition:2018 #![feature(async_closure)] -#![feature(generators)] +#![feature(coroutines)] #![deny(unused_must_use)] fn unused() { diff --git a/tests/ui/liveness/liveness-upvars.rs b/tests/ui/liveness/liveness-upvars.rs index d446d57d39647..17158dfbc6ccf 100644 --- a/tests/ui/liveness/liveness-upvars.rs +++ b/tests/ui/liveness/liveness-upvars.rs @@ -1,6 +1,6 @@ // edition:2018 // check-pass -#![feature(generators)] +#![feature(coroutines)] #![warn(unused)] #![allow(unreachable_code)] @@ -60,7 +60,7 @@ pub fn f() { }; let _ = async move { println!("{}", c); - // Never read because this is a generator. + // Never read because this is a coroutine. c += 1; //~ WARN value assigned to `c` is never read }; } @@ -110,7 +110,7 @@ async fn yield_now() { todo!(); } -pub fn async_generator() { +pub fn async_coroutine() { let mut state: u32 = 0; let _ = async { @@ -129,7 +129,7 @@ pub fn async_generator() { }; } -pub fn generator() { +pub fn coroutine() { let mut s: u32 = 0; let _ = |_| { s = 0; diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 8b4e6250a3080..1e9e7a89dde77 100644 --- a/tests/ui/macros/stringify.rs +++ b/tests/ui/macros/stringify.rs @@ -7,7 +7,7 @@ #![feature(box_patterns)] #![feature(const_trait_impl)] #![feature(decl_macro)] -#![feature(generators)] +#![feature(coroutines)] #![feature(more_qualified_paths)] #![feature(raw_ref_op)] #![feature(trait_alias)] diff --git a/tests/ui/mir/issue-71793-inline-args-storage.rs b/tests/ui/mir/issue-71793-inline-args-storage.rs index 18f2e38d14c4a..3749d5ebf81bd 100644 --- a/tests/ui/mir/issue-71793-inline-args-storage.rs +++ b/tests/ui/mir/issue-71793-inline-args-storage.rs @@ -1,5 +1,5 @@ // Verifies that inliner emits StorageLive & StorageDead when introducing -// temporaries for arguments, so that they don't become part of the generator. +// temporaries for arguments, so that they don't become part of the coroutine. // Regression test for #71793. // // check-pass diff --git a/tests/ui/mir/remove-zsts-query-cycle.rs b/tests/ui/mir/remove-zsts-query-cycle.rs index be4d68f2de707..bcaf8468857fc 100644 --- a/tests/ui/mir/remove-zsts-query-cycle.rs +++ b/tests/ui/mir/remove-zsts-query-cycle.rs @@ -1,5 +1,5 @@ // Regression test for #88972. Used to cause a query cycle: -// optimized mir -> remove zsts -> layout of a generator -> optimized mir. +// optimized mir -> remove zsts -> layout of a coroutine -> optimized mir. // // edition:2018 // compile-flags: --crate-type=lib -Zinline-mir=yes diff --git a/tests/ui/nll/generator-distinct-lifetime.rs b/tests/ui/nll/coroutine-distinct-lifetime.rs similarity index 83% rename from tests/ui/nll/generator-distinct-lifetime.rs rename to tests/ui/nll/coroutine-distinct-lifetime.rs index 90fe6b569602a..0483b8858bac8 100644 --- a/tests/ui/nll/generator-distinct-lifetime.rs +++ b/tests/ui/nll/coroutine-distinct-lifetime.rs @@ -1,7 +1,7 @@ -#![feature(generators)] +#![feature(coroutines)] // Test for issue #47189. Here, both `s` and `t` are live for the -// generator's lifetime, but within the generator they have distinct +// coroutine's lifetime, but within the coroutine they have distinct // lifetimes. We accept this code -- even though the borrow extends // over a yield -- because the data that is borrowed (`*x`) is not // stored on the stack. diff --git a/tests/ui/nll/generator-upvar-mutability.rs b/tests/ui/nll/coroutine-upvar-mutability.rs similarity index 58% rename from tests/ui/nll/generator-upvar-mutability.rs rename to tests/ui/nll/coroutine-upvar-mutability.rs index c49ea15b82483..12853b16b9b75 100644 --- a/tests/ui/nll/generator-upvar-mutability.rs +++ b/tests/ui/nll/coroutine-upvar-mutability.rs @@ -1,6 +1,6 @@ -// Check that generators respect the muatability of their upvars. +// Check that coroutines respect the muatability of their upvars. -#![feature(generators)] +#![feature(coroutines)] fn mutate_upvar() { let x = 0; diff --git a/tests/ui/nll/generator-upvar-mutability.stderr b/tests/ui/nll/coroutine-upvar-mutability.stderr similarity index 88% rename from tests/ui/nll/generator-upvar-mutability.stderr rename to tests/ui/nll/coroutine-upvar-mutability.stderr index 31b061b61d19d..464bbc7693117 100644 --- a/tests/ui/nll/generator-upvar-mutability.stderr +++ b/tests/ui/nll/coroutine-upvar-mutability.stderr @@ -1,5 +1,5 @@ error[E0594]: cannot assign to `x`, as it is not declared as mutable - --> $DIR/generator-upvar-mutability.rs:8:9 + --> $DIR/coroutine-upvar-mutability.rs:8:9 | LL | let x = 0; | - help: consider changing this to be mutable: `mut x` diff --git a/tests/ui/nll/extra-unused-mut.rs b/tests/ui/nll/extra-unused-mut.rs index 340f2952accd0..b04e395424927 100644 --- a/tests/ui/nll/extra-unused-mut.rs +++ b/tests/ui/nll/extra-unused-mut.rs @@ -2,7 +2,7 @@ // check-pass -#![feature(generators)] +#![feature(coroutines)] #![deny(unused_mut)] fn ref_argument(ref _y: i32) {} @@ -16,7 +16,7 @@ fn mutable_upvar() { } // #50897 -fn generator_mutable_upvar() { +fn coroutine_mutable_upvar() { let mut x = 0; move || { x = 1; diff --git a/tests/ui/nll/issue-48623-generator.rs b/tests/ui/nll/issue-48623-coroutine.rs similarity index 56% rename from tests/ui/nll/issue-48623-generator.rs rename to tests/ui/nll/issue-48623-coroutine.rs index 08d2584ee5efd..bd11aaf142977 100644 --- a/tests/ui/nll/issue-48623-generator.rs +++ b/tests/ui/nll/issue-48623-coroutine.rs @@ -2,7 +2,7 @@ #![allow(path_statements)] #![allow(dead_code)] -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] struct WithDrop; @@ -10,9 +10,9 @@ impl Drop for WithDrop { fn drop(&mut self) {} } -fn reborrow_from_generator(r: &mut ()) { +fn reborrow_from_coroutine(r: &mut ()) { let d = WithDrop; - move || { d; yield; &mut *r }; //~ WARN unused generator that must be used + move || { d; yield; &mut *r }; //~ WARN unused coroutine that must be used } fn main() {} diff --git a/tests/ui/nll/issue-48623-generator.stderr b/tests/ui/nll/issue-48623-coroutine.stderr similarity index 53% rename from tests/ui/nll/issue-48623-generator.stderr rename to tests/ui/nll/issue-48623-coroutine.stderr index bfdfca2100406..1b7b1735aacb1 100644 --- a/tests/ui/nll/issue-48623-generator.stderr +++ b/tests/ui/nll/issue-48623-coroutine.stderr @@ -1,10 +1,10 @@ -warning: unused generator that must be used - --> $DIR/issue-48623-generator.rs:15:5 +warning: unused coroutine that must be used + --> $DIR/issue-48623-coroutine.rs:15:5 | LL | move || { d; yield; &mut *r }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: generators are lazy and do nothing unless resumed + = note: coroutines are lazy and do nothing unless resumed = note: `#[warn(unused_must_use)]` on by default warning: 1 warning emitted diff --git a/tests/ui/nll/issue-55850.rs b/tests/ui/nll/issue-55850.rs index e6279bd028e01..fc873af94638b 100644 --- a/tests/ui/nll/issue-55850.rs +++ b/tests/ui/nll/issue-55850.rs @@ -1,16 +1,16 @@ #![allow(unused_mut)] -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] use std::marker::Unpin; -use std::ops::Generator; -use std::ops::GeneratorState::Yielded; +use std::ops::Coroutine; +use std::ops::CoroutineState::Yielded; use std::pin::Pin; pub struct GenIter(G); impl Iterator for GenIter where - G: Generator + Unpin, + G: Coroutine + Unpin, { type Item = G::Yield; @@ -26,7 +26,7 @@ fn bug<'a>() -> impl Iterator { GenIter(move || { let mut s = String::new(); yield &s[..] //~ ERROR cannot yield value referencing local variable `s` [E0515] - //~| ERROR borrow may still be in use when generator yields + //~| ERROR borrow may still be in use when coroutine yields }) } diff --git a/tests/ui/nll/issue-55850.stderr b/tests/ui/nll/issue-55850.stderr index 86a8cdc42ff9f..3d43817f4d8a2 100644 --- a/tests/ui/nll/issue-55850.stderr +++ b/tests/ui/nll/issue-55850.stderr @@ -7,7 +7,7 @@ LL | yield &s[..] | | `s` is borrowed here | yields a value referencing data owned by the current function -error[E0626]: borrow may still be in use when generator yields +error[E0626]: borrow may still be in use when coroutine yields --> $DIR/issue-55850.rs:28:16 | LL | yield &s[..] diff --git a/tests/ui/packed/packed-struct-drop-aligned.rs b/tests/ui/packed/packed-struct-drop-aligned.rs index 9f9f41e251564..4fec72763a47a 100644 --- a/tests/ui/packed/packed-struct-drop-aligned.rs +++ b/tests/ui/packed/packed-struct-drop-aligned.rs @@ -1,9 +1,9 @@ // run-pass -#![feature(generators)] -#![feature(generator_trait)] +#![feature(coroutines)] +#![feature(coroutine_trait)] use std::cell::Cell; use std::mem; -use std::ops::Generator; +use std::ops::Coroutine; use std::pin::Pin; struct Aligned<'a> { @@ -44,7 +44,7 @@ fn main() { let _ = &p; p.1 = Aligned { drop_count }; assert_eq!(drop_count.get(), 1); - // Test that a generator drop function moves a value from a packed + // Test that a coroutine drop function moves a value from a packed // struct to a separate local before dropping it. We move out the // first field to generate and open drop for the second field. drop(p.0); diff --git a/tests/ui/parser/doc-comment-in-stmt.fixed b/tests/ui/parser/doc-comment-in-stmt.fixed new file mode 100644 index 0000000000000..4b3ecccf66c35 --- /dev/null +++ b/tests/ui/parser/doc-comment-in-stmt.fixed @@ -0,0 +1,27 @@ +// run-rustfix +#![allow(unused)] +fn foo() -> bool { + false + // !self.allow_ty_infer() + //~^ ERROR found doc comment +} + +fn bar() -> bool { + false + /* ! bar */ //~ ERROR found doc comment +} + +fn baz() -> i32 { + 1 /* * baz */ //~ ERROR found doc comment +} + +fn quux() -> i32 { + 2 // / quux + //~^ ERROR found doc comment +} + +fn main() { + let x = 0; + let y = x.max(1) // !foo //~ ERROR found doc comment + .min(2); +} diff --git a/tests/ui/parser/doc-comment-in-stmt.rs b/tests/ui/parser/doc-comment-in-stmt.rs index b02df13213f20..73d08f51c669e 100644 --- a/tests/ui/parser/doc-comment-in-stmt.rs +++ b/tests/ui/parser/doc-comment-in-stmt.rs @@ -1,3 +1,5 @@ +// run-rustfix +#![allow(unused)] fn foo() -> bool { false //!self.allow_ty_infer() @@ -14,7 +16,12 @@ fn baz() -> i32 { } fn quux() -> i32 { - 2 /*! quux */ //~ ERROR found doc comment + 2 /// quux + //~^ ERROR found doc comment } -fn main() {} +fn main() { + let x = 0; + let y = x.max(1) //!foo //~ ERROR found doc comment + .min(2); +} diff --git a/tests/ui/parser/doc-comment-in-stmt.stderr b/tests/ui/parser/doc-comment-in-stmt.stderr index febfb600cc7a6..7aefd5c99527c 100644 --- a/tests/ui/parser/doc-comment-in-stmt.stderr +++ b/tests/ui/parser/doc-comment-in-stmt.stderr @@ -1,50 +1,61 @@ error: expected one of `.`, `;`, `?`, `}`, or an operator, found doc comment `//!self.allow_ty_infer()` - --> $DIR/doc-comment-in-stmt.rs:3:5 + --> $DIR/doc-comment-in-stmt.rs:5:5 | LL | false | - expected one of `.`, `;`, `?`, `}`, or an operator LL | //!self.allow_ty_infer() | ^^^^^^^^^^^^^^^^^^^^^^^^ unexpected token | -help: add a space before `!` to use a regular comment +help: add a space before `!` to write a regular comment | LL | // !self.allow_ty_infer() - | ~~~~ + | + error: expected one of `.`, `;`, `?`, `}`, or an operator, found doc comment `/*! bar */` - --> $DIR/doc-comment-in-stmt.rs:9:5 + --> $DIR/doc-comment-in-stmt.rs:11:5 | LL | false | - expected one of `.`, `;`, `?`, `}`, or an operator LL | /*! bar */ | ^^^^^^^^^^ unexpected token | -help: add a space before `!` to use a regular comment +help: add a space before `!` to write a regular comment | LL | /* ! bar */ - | ~~~~ + | + error: expected one of `.`, `;`, `?`, `}`, or an operator, found doc comment `/** baz */` - --> $DIR/doc-comment-in-stmt.rs:13:7 + --> $DIR/doc-comment-in-stmt.rs:15:7 | LL | 1 /** baz */ | ^^^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator | -help: add a space before `*` to use a regular comment +help: add a space before the last `*` to write a regular comment | LL | 1 /* * baz */ - | ~~~~ + | + -error: expected one of `.`, `;`, `?`, `}`, or an operator, found doc comment `/*! quux */` - --> $DIR/doc-comment-in-stmt.rs:17:7 +error: expected one of `.`, `;`, `?`, `}`, or an operator, found doc comment `/// quux` + --> $DIR/doc-comment-in-stmt.rs:19:7 | -LL | 2 /*! quux */ - | ^^^^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator +LL | 2 /// quux + | ^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator | -help: add a space before `!` to use a regular comment +help: add a space before the last `/` to write a regular comment | -LL | 2 /* ! quux */ - | ~~~~ +LL | 2 // / quux + | + -error: aborting due to 4 previous errors +error: expected one of `.`, `;`, `?`, `else`, or an operator, found doc comment `//!foo + --> $DIR/doc-comment-in-stmt.rs:25:22 + | +LL | let y = x.max(1) //!foo + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected one of `.`, `;`, `?`, `else`, or an operator + | +help: add a space before `!` to write a regular comment + | +LL | let y = x.max(1) // !foo + | + + +error: aborting due to 5 previous errors diff --git a/tests/ui/polymorphization/generators.rs b/tests/ui/polymorphization/coroutine.rs similarity index 70% rename from tests/ui/polymorphization/generators.rs rename to tests/ui/polymorphization/coroutine.rs index 779bac0ace29b..3f28e89e36c6e 100644 --- a/tests/ui/polymorphization/generators.rs +++ b/tests/ui/polymorphization/coroutine.rs @@ -1,10 +1,10 @@ // build-fail // compile-flags:-Zpolymorphize=on -Zinline-mir=off -#![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)] +#![feature(generic_const_exprs, coroutines, coroutine_trait, rustc_attrs)] //~^ WARN the feature `generic_const_exprs` is incomplete use std::marker::Unpin; -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; enum YieldOrReturn { @@ -14,13 +14,13 @@ enum YieldOrReturn { fn finish(mut t: T) -> Vec> where - T: Generator<(), Yield = Y, Return = R> + Unpin, + T: Coroutine<(), Yield = Y, Return = R> + Unpin, { let mut results = Vec::new(); loop { match Pin::new(&mut t).resume(()) { - GeneratorState::Yielded(yielded) => results.push(YieldOrReturn::Yield(yielded)), - GeneratorState::Complete(returned) => { + CoroutineState::Yielded(yielded) => results.push(YieldOrReturn::Yield(yielded)), + CoroutineState::Complete(returned) => { results.push(YieldOrReturn::Return(returned)); return results; } @@ -28,10 +28,10 @@ where } } -// This test checks that the polymorphization analysis functions on generators. +// This test checks that the polymorphization analysis functions on coroutines. #[rustc_polymorphize_error] -pub fn unused_type() -> impl Generator<(), Yield = u32, Return = u32> + Unpin { +pub fn unused_type() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin { || { //~^ ERROR item has unused generic parameters yield 1; @@ -40,7 +40,7 @@ pub fn unused_type() -> impl Generator<(), Yield = u32, Return = u32> + Unpin } #[rustc_polymorphize_error] -pub fn used_type_in_yield() -> impl Generator<(), Yield = Y, Return = u32> + Unpin { +pub fn used_type_in_yield() -> impl Coroutine<(), Yield = Y, Return = u32> + Unpin { || { yield Y::default(); 2 @@ -48,7 +48,7 @@ pub fn used_type_in_yield() -> impl Generator<(), Yield = Y, Return } #[rustc_polymorphize_error] -pub fn used_type_in_return() -> impl Generator<(), Yield = u32, Return = R> + Unpin { +pub fn used_type_in_return() -> impl Coroutine<(), Yield = u32, Return = R> + Unpin { || { yield 3; R::default() @@ -56,7 +56,7 @@ pub fn used_type_in_return() -> impl Generator<(), Yield = u32, Retu } #[rustc_polymorphize_error] -pub fn unused_const() -> impl Generator<(), Yield = u32, Return = u32> + Unpin { +pub fn unused_const() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin { || { //~^ ERROR item has unused generic parameters yield 1; @@ -65,7 +65,7 @@ pub fn unused_const() -> impl Generator<(), Yield = u32, Return = } #[rustc_polymorphize_error] -pub fn used_const_in_yield() -> impl Generator<(), Yield = u32, Return = u32> + Unpin +pub fn used_const_in_yield() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin { || { yield Y; @@ -74,7 +74,7 @@ pub fn used_const_in_yield() -> impl Generator<(), Yield = u32, Re } #[rustc_polymorphize_error] -pub fn used_const_in_return() -> impl Generator<(), Yield = u32, Return = u32> + Unpin +pub fn used_const_in_return() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin { || { yield 4; diff --git a/tests/ui/polymorphization/generators.stderr b/tests/ui/polymorphization/coroutine.stderr similarity index 72% rename from tests/ui/polymorphization/generators.stderr rename to tests/ui/polymorphization/coroutine.stderr index 32d49d25f02ac..67b55a5988317 100644 --- a/tests/ui/polymorphization/generators.stderr +++ b/tests/ui/polymorphization/coroutine.stderr @@ -1,24 +1,24 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generators.rs:3:12 + --> $DIR/coroutine.rs:3:12 | -LL | #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)] +LL | #![feature(generic_const_exprs, coroutines, coroutine_trait, rustc_attrs)] | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 for more information = note: `#[warn(incomplete_features)]` on by default error: item has unused generic parameters - --> $DIR/generators.rs:35:5 + --> $DIR/coroutine.rs:35:5 | -LL | pub fn unused_type() -> impl Generator<(), Yield = u32, Return = u32> + Unpin { +LL | pub fn unused_type() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin { | - generic parameter `T` is unused LL | || { | ^^ error: item has unused generic parameters - --> $DIR/generators.rs:60:5 + --> $DIR/coroutine.rs:60:5 | -LL | pub fn unused_const() -> impl Generator<(), Yield = u32, Return = u32> + Unpin { +LL | pub fn unused_const() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin { | ------------ generic parameter `T` is unused LL | || { | ^^ diff --git a/tests/ui/print_type_sizes/generator.rs b/tests/ui/print_type_sizes/coroutine.rs similarity index 54% rename from tests/ui/print_type_sizes/generator.rs rename to tests/ui/print_type_sizes/coroutine.rs index d1cd36274ef3e..aae72e0f37ec5 100644 --- a/tests/ui/print_type_sizes/generator.rs +++ b/tests/ui/print_type_sizes/coroutine.rs @@ -2,11 +2,11 @@ // build-pass // ignore-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -use std::ops::Generator; +use std::ops::Coroutine; -fn generator(array: [u8; C]) -> impl Generator { +fn coroutine(array: [u8; C]) -> impl Coroutine { move |()| { yield (); let _ = array; @@ -14,5 +14,5 @@ fn generator(array: [u8; C]) -> impl Generator as Iterator>::Item: 'static` without // requiring `T: 'static` diff --git a/tests/ui/rfcs/rfc-2091-track-caller/tracked-closure.rs b/tests/ui/rfcs/rfc-2091-track-caller/tracked-closure.rs index 670c423a7e0e2..86bcf1f6f8d92 100644 --- a/tests/ui/rfcs/rfc-2091-track-caller/tracked-closure.rs +++ b/tests/ui/rfcs/rfc-2091-track-caller/tracked-closure.rs @@ -2,10 +2,10 @@ #![feature(stmt_expr_attributes)] #![feature(closure_track_caller)] -#![feature(generator_trait)] -#![feature(generators)] +#![feature(coroutine_trait)] +#![feature(coroutines)] -use std::ops::{Generator, GeneratorState}; +use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; use std::panic::Location; @@ -93,53 +93,53 @@ fn test_closure() { #[track_caller] -fn mono_generator>( +fn mono_coroutine>( val: Pin<&mut F> ) -> (&'static str, String, Loc) { match val.resume("Mono".to_string()) { - GeneratorState::Yielded(val) => val, + CoroutineState::Yielded(val) => val, _ => unreachable!() } } #[track_caller] -fn dyn_generator( - val: Pin<&mut dyn Generator> +fn dyn_coroutine( + val: Pin<&mut dyn Coroutine> ) -> (&'static str, String, Loc) { match val.resume("Dyn".to_string()) { - GeneratorState::Yielded(val) => val, + CoroutineState::Yielded(val) => val, _ => unreachable!() } } -fn test_generator() { - let generator = #[track_caller] |arg: String| { +fn test_coroutine() { + let coroutine = #[track_caller] |arg: String| { yield ("first", arg.clone(), Location::caller()); yield ("second", arg.clone(), Location::caller()); }; - let mut pinned = Box::pin(generator); - let (dyn_ret, dyn_arg, dyn_loc) = dyn_generator(pinned.as_mut()); + let mut pinned = Box::pin(coroutine); + let (dyn_ret, dyn_arg, dyn_loc) = dyn_coroutine(pinned.as_mut()); assert_eq!(dyn_ret, "first"); assert_eq!(dyn_arg, "Dyn".to_string()); - // The `Generator` trait does not have `#[track_caller]` on `resume`, so + // The `Coroutine` trait does not have `#[track_caller]` on `resume`, so // this will not match. assert_ne!(dyn_loc.file(), file!()); - let (mono_ret, mono_arg, mono_loc) = mono_generator(pinned.as_mut()); + let (mono_ret, mono_arg, mono_loc) = mono_coroutine(pinned.as_mut()); let mono_line = line!() - 1; assert_eq!(mono_ret, "second"); - // The generator ignores the argument to the second `resume` call + // The coroutine ignores the argument to the second `resume` call assert_eq!(mono_arg, "Dyn".to_string()); assert_eq!(mono_loc.file(), file!()); assert_eq!(mono_loc.line(), mono_line); assert_eq!(mono_loc.column(), 42); - let non_tracked_generator = || { yield Location::caller(); }; - let non_tracked_line = line!() - 1; // This is the line of the generator, not its caller - let non_tracked_loc = match Box::pin(non_tracked_generator).as_mut().resume(()) { - GeneratorState::Yielded(val) => val, + let non_tracked_coroutine = || { yield Location::caller(); }; + let non_tracked_line = line!() - 1; // This is the line of the coroutine, not its caller + let non_tracked_loc = match Box::pin(non_tracked_coroutine).as_mut().resume(()) { + CoroutineState::Yielded(val) => val, _ => unreachable!() }; assert_eq!(non_tracked_loc.file(), file!()); @@ -150,5 +150,5 @@ fn test_generator() { fn main() { test_closure(); - test_generator(); + test_coroutine(); } diff --git a/tests/ui/sanitize/issue-111184-generator-witness.rs b/tests/ui/sanitize/issue-111184-coroutine-witness.rs similarity index 85% rename from tests/ui/sanitize/issue-111184-generator-witness.rs rename to tests/ui/sanitize/issue-111184-coroutine-witness.rs index d36d8bce561f0..dffb739f20321 100644 --- a/tests/ui/sanitize/issue-111184-generator-witness.rs +++ b/tests/ui/sanitize/issue-111184-coroutine-witness.rs @@ -1,4 +1,4 @@ -// Regression test for issue 111184, where ty::GeneratorWitness were not expected to occur in +// Regression test for issue 111184, where ty::CoroutineWitness were not expected to occur in // encode_ty and caused the compiler to ICE. // // needs-sanitizer-cfi diff --git a/tests/ui/suggestions/issue-84973-blacklist.rs b/tests/ui/suggestions/issue-84973-blacklist.rs index 6813b07a2ee64..6a35d779c1cda 100644 --- a/tests/ui/suggestions/issue-84973-blacklist.rs +++ b/tests/ui/suggestions/issue-84973-blacklist.rs @@ -1,7 +1,7 @@ // Checks that certain traits for which we don't want to suggest borrowing // are blacklisted and don't cause the suggestion to be issued. -#![feature(generators)] +#![feature(coroutines)] fn f_copy(t: T) {} fn f_clone(t: T) {} diff --git a/tests/ui/suggestions/issue-84973-blacklist.stderr b/tests/ui/suggestions/issue-84973-blacklist.stderr index c8ce146cebf9a..e0bdb6949a9c9 100644 --- a/tests/ui/suggestions/issue-84973-blacklist.stderr +++ b/tests/ui/suggestions/issue-84973-blacklist.stderr @@ -31,11 +31,11 @@ LL + #[derive(Clone)] LL | struct S; | -error[E0277]: `{static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22}` cannot be unpinned +error[E0277]: `{static coroutine@$DIR/issue-84973-blacklist.rs:17:13: 17:22}` cannot be unpinned --> $DIR/issue-84973-blacklist.rs:17:13 | LL | f_unpin(static || { yield; }); - | ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22}` + | ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:17:13: 17:22}` | | | required by a bound introduced by this call | diff --git a/tests/ui/suggestions/unnamable-types.rs b/tests/ui/suggestions/unnamable-types.rs index f2485041d9ba2..a4e32d7c80654 100644 --- a/tests/ui/suggestions/unnamable-types.rs +++ b/tests/ui/suggestions/unnamable-types.rs @@ -1,7 +1,7 @@ // Test that we do not suggest to add type annotations for unnamable types. #![crate_type="lib"] -#![feature(generators)] +#![feature(coroutines)] const A = 5; //~^ ERROR: missing type for `const` item diff --git a/tests/ui/suggestions/unnamable-types.stderr b/tests/ui/suggestions/unnamable-types.stderr index 19e9af14535dc..d003b91691c0f 100644 --- a/tests/ui/suggestions/unnamable-types.stderr +++ b/tests/ui/suggestions/unnamable-types.stderr @@ -55,7 +55,7 @@ error: missing type for `const` item LL | const G = || -> i32 { yield 0; return 1; }; | ^ | -note: however, the inferred type `{generator@$DIR/unnamable-types.rs:37:11: 37:20}` cannot be named +note: however, the inferred type `{coroutine@$DIR/unnamable-types.rs:37:11: 37:20}` cannot be named --> $DIR/unnamable-types.rs:37:11 | LL | const G = || -> i32 { yield 0; return 1; }; diff --git a/tests/ui/threads-sendsync/sync-send-iterators-in-libcollections.rs b/tests/ui/threads-sendsync/sync-send-iterators-in-libcollections.rs index fd53bb607f79d..61f54ac4e0bdb 100644 --- a/tests/ui/threads-sendsync/sync-send-iterators-in-libcollections.rs +++ b/tests/ui/threads-sendsync/sync-send-iterators-in-libcollections.rs @@ -37,7 +37,7 @@ macro_rules! is_sync_send { } fn main() { - // The iterator "generator" list should exhaust what corresponding + // The iterator "coroutine" list should exhaust what corresponding // implementations have where `Sync` and `Send` semantics apply. all_sync_send!(BinaryHeap::::new(), iter, drain, into_iter); diff --git a/tests/ui/traits/new-solver/coroutine.fail.stderr b/tests/ui/traits/new-solver/coroutine.fail.stderr new file mode 100644 index 0000000000000..14e67727d0ba7 --- /dev/null +++ b/tests/ui/traits/new-solver/coroutine.fail.stderr @@ -0,0 +1,64 @@ +error[E0277]: the trait bound `{coroutine@$DIR/coroutine.rs:18:21: 18:23}: Coroutine` is not satisfied + --> $DIR/coroutine.rs:18:21 + | +LL | needs_coroutine(|| { + | _____---------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | +LL | | +LL | | yield (); +LL | | }); + | |_____^ the trait `Coroutine` is not implemented for `{coroutine@$DIR/coroutine.rs:18:21: 18:23}` + | +note: required by a bound in `needs_coroutine` + --> $DIR/coroutine.rs:14:28 + | +LL | fn needs_coroutine(_: impl Coroutine) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `needs_coroutine` + +error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine.rs:18:21: 18:23} as Coroutine>::Yield == B` + --> $DIR/coroutine.rs:18:21 + | +LL | needs_coroutine(|| { + | _____---------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | +LL | | +LL | | yield (); +LL | | }); + | |_____^ types differ + | +note: required by a bound in `needs_coroutine` + --> $DIR/coroutine.rs:14:41 + | +LL | fn needs_coroutine(_: impl Coroutine) {} + | ^^^^^^^^^ required by this bound in `needs_coroutine` + +error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine.rs:18:21: 18:23} as Coroutine>::Return == C` + --> $DIR/coroutine.rs:18:21 + | +LL | needs_coroutine(|| { + | _____---------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | +LL | | +LL | | yield (); +LL | | }); + | |_____^ types differ + | +note: required by a bound in `needs_coroutine` + --> $DIR/coroutine.rs:14:52 + | +LL | fn needs_coroutine(_: impl Coroutine) {} + | ^^^^^^^^^^ required by this bound in `needs_coroutine` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0271, E0277. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/traits/new-solver/coroutine.rs b/tests/ui/traits/new-solver/coroutine.rs new file mode 100644 index 0000000000000..af16f70fb56c7 --- /dev/null +++ b/tests/ui/traits/new-solver/coroutine.rs @@ -0,0 +1,32 @@ +// compile-flags: -Ztrait-solver=next +// edition: 2021 +// revisions: pass fail +//[pass] check-pass + +#![feature(coroutine_trait, coroutines)] + +use std::ops::Coroutine; + +struct A; +struct B; +struct C; + +fn needs_coroutine(_: impl Coroutine) {} + +#[cfg(fail)] +fn main() { + needs_coroutine(|| { + //[fail]~^ ERROR Coroutine` is not satisfied + //[fail]~| ERROR as Coroutine>::Yield == B` + //[fail]~| ERROR as Coroutine>::Return == C` + yield (); + }); +} + +#[cfg(pass)] +fn main() { + needs_coroutine(|_: A| { + let _: A = yield B; + C + }) +} diff --git a/tests/ui/traits/new-solver/generator.fail.stderr b/tests/ui/traits/new-solver/generator.fail.stderr deleted file mode 100644 index e3fe4bf5a6acf..0000000000000 --- a/tests/ui/traits/new-solver/generator.fail.stderr +++ /dev/null @@ -1,64 +0,0 @@ -error[E0277]: the trait bound `{generator@$DIR/generator.rs:18:21: 18:23}: Generator` is not satisfied - --> $DIR/generator.rs:18:21 - | -LL | needs_generator(|| { - | _____---------------_^ - | | | - | | required by a bound introduced by this call -LL | | -LL | | -LL | | -LL | | yield (); -LL | | }); - | |_____^ the trait `Generator` is not implemented for `{generator@$DIR/generator.rs:18:21: 18:23}` - | -note: required by a bound in `needs_generator` - --> $DIR/generator.rs:14:28 - | -LL | fn needs_generator(_: impl Generator) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `needs_generator` - -error[E0271]: type mismatch resolving `<{generator@$DIR/generator.rs:18:21: 18:23} as Generator>::Yield == B` - --> $DIR/generator.rs:18:21 - | -LL | needs_generator(|| { - | _____---------------_^ - | | | - | | required by a bound introduced by this call -LL | | -LL | | -LL | | -LL | | yield (); -LL | | }); - | |_____^ types differ - | -note: required by a bound in `needs_generator` - --> $DIR/generator.rs:14:41 - | -LL | fn needs_generator(_: impl Generator) {} - | ^^^^^^^^^ required by this bound in `needs_generator` - -error[E0271]: type mismatch resolving `<{generator@$DIR/generator.rs:18:21: 18:23} as Generator>::Return == C` - --> $DIR/generator.rs:18:21 - | -LL | needs_generator(|| { - | _____---------------_^ - | | | - | | required by a bound introduced by this call -LL | | -LL | | -LL | | -LL | | yield (); -LL | | }); - | |_____^ types differ - | -note: required by a bound in `needs_generator` - --> $DIR/generator.rs:14:52 - | -LL | fn needs_generator(_: impl Generator) {} - | ^^^^^^^^^^ required by this bound in `needs_generator` - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0271, E0277. -For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/traits/new-solver/generator.rs b/tests/ui/traits/new-solver/generator.rs deleted file mode 100644 index 364373ca8be71..0000000000000 --- a/tests/ui/traits/new-solver/generator.rs +++ /dev/null @@ -1,32 +0,0 @@ -// compile-flags: -Ztrait-solver=next -// edition: 2021 -// revisions: pass fail -//[pass] check-pass - -#![feature(generator_trait, generators)] - -use std::ops::Generator; - -struct A; -struct B; -struct C; - -fn needs_generator(_: impl Generator) {} - -#[cfg(fail)] -fn main() { - needs_generator(|| { - //[fail]~^ ERROR Generator` is not satisfied - //[fail]~| ERROR as Generator>::Yield == B` - //[fail]~| ERROR as Generator>::Return == C` - yield (); - }); -} - -#[cfg(pass)] -fn main() { - needs_generator(|_: A| { - let _: A = yield B; - C - }) -} diff --git a/tests/ui/type-alias-impl-trait/closure_parent_substs.rs b/tests/ui/type-alias-impl-trait/closure_parent_substs.rs index 3ff20d99ad886..7d8193b26cccf 100644 --- a/tests/ui/type-alias-impl-trait/closure_parent_substs.rs +++ b/tests/ui/type-alias-impl-trait/closure_parent_substs.rs @@ -1,5 +1,5 @@ // When WF checking the hidden type in the ParamEnv of the opaque type, -// one complication arises when the hidden type is a closure/generator: +// one complication arises when the hidden type is a closure/coroutine: // the "parent_substs" of the type may reference lifetime parameters // not present in the opaque type. // These region parameters are not really useful in this check. diff --git a/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs b/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs new file mode 100644 index 0000000000000..ad1ede9c3e482 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs @@ -0,0 +1,22 @@ +#![feature(coroutines, coroutine_trait, rustc_attrs)] +#![feature(type_alias_impl_trait)] + +// check-pass + +mod gen { + use std::ops::Coroutine; + + pub type CoroOnce = impl Coroutine; + + pub const fn const_coroutine(yielding: Y, returning: R) -> CoroOnce { + move || { + yield yielding; + + return returning; + } + } +} + +const FOO: gen::CoroOnce = gen::const_coroutine(10, 100); + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs deleted file mode 100644 index a213dbba4ea01..0000000000000 --- a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(generators, generator_trait, rustc_attrs)] -#![feature(type_alias_impl_trait)] - -// check-pass - -mod gen { - use std::ops::Generator; - - pub type GenOnce = impl Generator; - - pub const fn const_generator(yielding: Y, returning: R) -> GenOnce { - move || { - yield yielding; - - return returning; - } - } -} - -const FOO: gen::GenOnce = gen::const_generator(10, 100); - -fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs b/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs new file mode 100644 index 0000000000000..bc6a34392127e --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs @@ -0,0 +1,39 @@ +// check-pass + +#![feature(coroutines, coroutine_trait)] +#![feature(type_alias_impl_trait)] + +use std::ops::{Coroutine, CoroutineState}; +use std::pin::Pin; + +type RandCoroutine<'a> = impl Coroutine + 'a; +fn rand_coroutine<'a>(rng: &'a ()) -> RandCoroutine<'a> { + move || { + let _rng = rng; + loop { + yield 0; + } + } +} + +pub type RandCoroutineWithIndirection<'c> = impl Coroutine + 'c; +pub fn rand_coroutine_with_indirection<'a>(rng: &'a ()) -> RandCoroutineWithIndirection<'a> { + fn helper<'b>(rng: &'b ()) -> impl 'b + Coroutine { + move || { + let _rng = rng; + loop { + yield 0; + } + } + } + + helper(rng) +} + +fn main() { + let mut gen = rand_coroutine(&()); + match unsafe { Pin::new_unchecked(&mut gen) }.resume(()) { + CoroutineState::Yielded(_) => {} + CoroutineState::Complete(_) => {} + }; +} diff --git a/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs b/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs deleted file mode 100644 index 477b61390ed46..0000000000000 --- a/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs +++ /dev/null @@ -1,39 +0,0 @@ -// check-pass - -#![feature(generators, generator_trait)] -#![feature(type_alias_impl_trait)] - -use std::ops::{Generator, GeneratorState}; -use std::pin::Pin; - -type RandGenerator<'a> = impl Generator + 'a; -fn rand_generator<'a>(rng: &'a ()) -> RandGenerator<'a> { - move || { - let _rng = rng; - loop { - yield 0; - } - } -} - -pub type RandGeneratorWithIndirection<'c> = impl Generator + 'c; -pub fn rand_generator_with_indirection<'a>(rng: &'a ()) -> RandGeneratorWithIndirection<'a> { - fn helper<'b>(rng: &'b ()) -> impl 'b + Generator { - move || { - let _rng = rng; - loop { - yield 0; - } - } - } - - helper(rng) -} - -fn main() { - let mut gen = rand_generator(&()); - match unsafe { Pin::new_unchecked(&mut gen) }.resume(()) { - GeneratorState::Yielded(_) => {} - GeneratorState::Complete(_) => {} - }; -} diff --git a/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs b/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs index 27ca7d0fdc9fa..a1cf23dab7b69 100644 --- a/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs +++ b/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs @@ -1,6 +1,6 @@ // check-pass -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] #![feature(type_alias_impl_trait)] trait Trait {} diff --git a/tests/ui/type-alias-impl-trait/issue-94429.rs b/tests/ui/type-alias-impl-trait/issue-94429.rs index d764545f906f3..306e73003fa98 100644 --- a/tests/ui/type-alias-impl-trait/issue-94429.rs +++ b/tests/ui/type-alias-impl-trait/issue-94429.rs @@ -1,18 +1,18 @@ -#![feature(impl_trait_in_assoc_type, generator_trait, generators)] -use std::ops::Generator; +#![feature(impl_trait_in_assoc_type, coroutine_trait, coroutines)] +use std::ops::Coroutine; trait Runnable { - type Gen: Generator; + type Coro: Coroutine; - fn run(&mut self) -> Self::Gen; + fn run(&mut self) -> Self::Coro; } struct Implementor {} impl Runnable for Implementor { - type Gen = impl Generator; + type Coro = impl Coroutine; - fn run(&mut self) -> Self::Gen { + fn run(&mut self) -> Self::Coro { //~^ ERROR: type mismatch resolving move || { yield 1; diff --git a/tests/ui/type-alias-impl-trait/issue-94429.stderr b/tests/ui/type-alias-impl-trait/issue-94429.stderr index 26605cdd2c216..360ecfa61bfa7 100644 --- a/tests/ui/type-alias-impl-trait/issue-94429.stderr +++ b/tests/ui/type-alias-impl-trait/issue-94429.stderr @@ -1,8 +1,8 @@ -error[E0271]: type mismatch resolving `<{generator@$DIR/issue-94429.rs:17:9: 17:16} as Generator>::Yield == ()` +error[E0271]: type mismatch resolving `<{coroutine@$DIR/issue-94429.rs:17:9: 17:16} as Coroutine>::Yield == ()` --> $DIR/issue-94429.rs:15:26 | -LL | fn run(&mut self) -> Self::Gen { - | ^^^^^^^^^ expected integer, found `()` +LL | fn run(&mut self) -> Self::Coro { + | ^^^^^^^^^^ expected integer, found `()` error: aborting due to previous error diff --git a/tests/ui/typeck/issue-91334.rs b/tests/ui/typeck/issue-91334.rs index 29204276bb3a5..1ffc56e66127e 100644 --- a/tests/ui/typeck/issue-91334.rs +++ b/tests/ui/typeck/issue-91334.rs @@ -2,6 +2,6 @@ // error-pattern: this file contains an unclosed delimiter -#![feature(generators)] +#![feature(coroutines)] fn f(){||yield(((){), diff --git a/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.rs b/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.rs index 9d0aa413207ab..057bdf0f618a4 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.rs +++ b/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.rs @@ -5,5 +5,5 @@ fn g(_: F) where F: FnOnce(Option) {} fn main() { - g(|_| { }); //~ ERROR closure/generator type that references itself + g(|_| { }); //~ ERROR closure/coroutine type that references itself } diff --git a/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.stderr b/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.stderr index 6d5dbca055858..9d3c1902cf30b 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-no-cyclic-sig.stderr @@ -1,4 +1,4 @@ -error[E0644]: closure/generator type that references itself +error[E0644]: closure/coroutine type that references itself --> $DIR/unboxed-closure-no-cyclic-sig.rs:8:7 | LL | g(|_| { }); diff --git a/tests/ui/weird-exprs.rs b/tests/ui/weird-exprs.rs index 892b281357f2e..6d40d6377c5de 100644 --- a/tests/ui/weird-exprs.rs +++ b/tests/ui/weird-exprs.rs @@ -1,6 +1,6 @@ // run-pass -#![feature(generators)] +#![feature(coroutines)] #![allow(non_camel_case_types)] #![allow(dead_code)]