From add09e66f28c92eef41e730a63191cd2a824598a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 30 Oct 2023 23:35:35 +0000 Subject: [PATCH] Some more coroutine renamings --- compiler/rustc_ast_lowering/src/expr.rs | 8 ++-- compiler/rustc_ast_lowering/src/item.rs | 4 +- compiler/rustc_hir/src/lang_items.rs | 4 +- compiler/rustc_hir_typeck/src/check.rs | 8 ++-- compiler/rustc_hir_typeck/src/closure.rs | 4 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_mir_build/src/build/mod.rs | 8 ++-- compiler/rustc_mir_build/src/thir/cx/mod.rs | 13 +++-- compiler/rustc_mir_transform/src/coroutine.rs | 47 ++++++++++--------- compiler/rustc_mir_transform/src/shim.rs | 14 +++--- .../src/solve/assembly/mod.rs | 2 +- .../error_reporting/type_err_ctxt_ext.rs | 5 +- .../src/traits/project.rs | 30 ++++++------ .../src/traits/select/candidate_assembly.rs | 2 +- .../src/traits/select/confirmation.rs | 8 ++-- compiler/rustc_ty_utils/src/instance.rs | 2 +- 16 files changed, 85 insertions(+), 76 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index d6fa74dc3e6f2..93805710cb544 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -606,7 +606,7 @@ impl<'hir> LoweringContext<'_, 'hir> { closure_node_id: NodeId, ret_ty: Option>, span: Span, - async_gen_kind: hir::CoroutineSource, + async_coroutine_source: hir::CoroutineSource, 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))); @@ -645,7 +645,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let params = arena_vec![self; param]; let body = self.lower_body(move |this| { - this.coroutine_kind = Some(hir::CoroutineKind::Async(async_gen_kind)); + this.coroutine_kind = Some(hir::CoroutineKind::Async(async_coroutine_source)); let old_ctx = this.task_context; this.task_context = Some(task_context_hid); @@ -684,7 +684,7 @@ impl<'hir> LoweringContext<'_, 'hir> { closure_node_id: NodeId, _yield_ty: Option>, span: Span, - gen_kind: hir::CoroutineSource, + coroutine_source: hir::CoroutineSource, body: impl FnOnce(&mut Self) -> hir::Expr<'hir>, ) -> hir::ExprKind<'hir> { let output = hir::FnRetTy::DefaultReturn(self.lower_span(span)); @@ -699,7 +699,7 @@ impl<'hir> LoweringContext<'_, 'hir> { }); let body = self.lower_body(move |this| { - this.coroutine_kind = Some(hir::CoroutineKind::Gen(gen_kind)); + this.coroutine_kind = Some(hir::CoroutineKind::Gen(coroutine_source)); let res = body(this); (&[], res) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index ca851bd4d35f0..299ca91460d87 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -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.coroutine_kind.take(); + let prev_coroutine_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.coroutine_kind = prev_gen_kind; + self.coroutine_kind = prev_coroutine_kind; body_id } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index c8ac95e29949b..1d1a1ee886272 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -212,8 +212,8 @@ language_item_table! { Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0); Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0); - CoroutineState, sym::coroutine_state, gen_state, Target::Enum, GenericRequirement::None; - Coroutine, sym::coroutine, gen_trait, Target::Trait, GenericRequirement::Minimum(1); + CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None; + Coroutine, sym::coroutine, coroutine_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_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index 14cd3881a068d..b8a265d4971d2 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -128,14 +128,16 @@ pub(super) fn check_fn<'a, 'tcx>( // 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 coroutine_ty = if let (Some(_), Some(coroutine_kind)) = + (can_be_coroutine, body.coroutine_kind) + { let interior = fcx .next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span }); fcx.deferred_coroutine_interiors.borrow_mut().push(( fn_def_id, body.id(), interior, - gen_kind, + coroutine_kind, )); let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap(); @@ -184,7 +186,7 @@ pub(super) fn check_fn<'a, 'tcx>( check_lang_start_fn(tcx, fn_sig, fn_def_id); } - gen_ty + coroutine_ty } fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>) { diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index b102ddd8d866d..d6073dbc128a9 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -302,8 +302,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let is_fn = tcx.is_fn_trait(trait_def_id); - let gen_trait = tcx.lang_items().gen_trait(); - let is_gen = gen_trait == Some(trait_def_id); + let coroutine_trait = tcx.lang_items().coroutine_trait(); + let is_gen = coroutine_trait == Some(trait_def_id); if !is_fn && !is_gen { debug!("not fn or coroutine"); diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 799ba2c35ec8b..baf160bcc99da 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1053,7 +1053,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { 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.trait_container(tcx) == tcx.lang_items().coroutine_trait() && assoc.name == rustc_span::sym::Return { if let ty::Coroutine(_, args, _) = args.type_at(0).kind() { diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 1f817633a2a13..58d6be50b905f 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -483,14 +483,14 @@ fn construct_fn<'tcx>( let arguments = &thir.params; 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() { + let coroutine_ty = arguments[thir::UPVAR_ENV_PARAM].ty; + let coroutine_sig = match coroutine_ty.kind() { ty::Coroutine(_, gen_args, ..) => gen_args.as_coroutine().sig(), _ => { - span_bug!(span, "coroutine w/o coroutine type: {:?}", gen_ty) + span_bug!(span, "coroutine w/o coroutine type: {:?}", coroutine_ty) } }; - (Some(gen_sig.yield_ty), gen_sig.return_ty) + (Some(coroutine_sig.yield_ty), coroutine_sig.return_ty) } else { (None, fn_sig.output()) }; diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 8bc4cbb953296..b6adb383fa6b2 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -149,10 +149,15 @@ impl<'tcx> Cx<'tcx> { Some(env_param) } 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 }; - Some(gen_param) + let coroutine_ty = self.typeck_results.node_type(owner_id); + let coroutine_param = Param { + ty: coroutine_ty, + pat: None, + ty_span: None, + self_kind: None, + hir_id: None, + }; + Some(coroutine_param) } _ => None, } diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 50d244d2831d4..fc30a718cbb57 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -147,7 +147,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> { } struct PinArgVisitor<'tcx> { - ref_gen_ty: Ty<'tcx>, + ref_coroutine_ty: Ty<'tcx>, tcx: TyCtxt<'tcx>, } @@ -168,7 +168,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> { local: SELF_ARG, projection: self.tcx().mk_place_elems(&[ProjectionElem::Field( FieldIdx::new(0), - self.ref_gen_ty, + self.ref_coroutine_ty, )]), }, self.tcx, @@ -468,34 +468,34 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'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 coroutine_ty = body.local_decls.raw[1].ty; - let ref_gen_ty = Ty::new_ref( + let ref_coroutine_ty = Ty::new_ref( tcx, tcx.lifetimes.re_erased, - ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut }, + ty::TypeAndMut { ty: coroutine_ty, mutbl: Mutability::Mut }, ); // Replace the by value coroutine argument - body.local_decls.raw[1].ty = ref_gen_ty; + body.local_decls.raw[1].ty = ref_coroutine_ty; // Add a deref to accesses of the coroutine state DerefArgVisitor { tcx }.visit_body(body); } 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 ref_coroutine_ty = body.local_decls.raw[1].ty; let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span)); let pin_adt_ref = tcx.adt_def(pin_did); - let args = tcx.mk_args(&[ref_gen_ty.into()]); - let pin_ref_gen_ty = Ty::new_adt(tcx, pin_adt_ref, args); + let args = tcx.mk_args(&[ref_coroutine_ty.into()]); + let pin_ref_coroutine_ty = Ty::new_adt(tcx, pin_adt_ref, args); // Replace the by ref coroutine argument - body.local_decls.raw[1].ty = pin_ref_gen_ty; + body.local_decls.raw[1].ty = pin_ref_coroutine_ty; // Add the Pin field access to accesses of the coroutine state - PinArgVisitor { ref_gen_ty, tcx }.visit_body(body); + PinArgVisitor { ref_coroutine_ty, tcx }.visit_body(body); } /// Allocates a new local and replaces all references of `local` with it. Returns the new local. @@ -1104,7 +1104,7 @@ fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { fn create_coroutine_drop_shim<'tcx>( tcx: TyCtxt<'tcx>, transform: &TransformVisitor<'tcx>, - gen_ty: Ty<'tcx>, + coroutine_ty: Ty<'tcx>, body: &mut Body<'tcx>, drop_clean: BasicBlock, ) -> Body<'tcx> { @@ -1136,7 +1136,7 @@ fn create_coroutine_drop_shim<'tcx>( // 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 }), + Ty::new_ptr(tcx, ty::TypeAndMut { ty: coroutine_ty, mutbl: hir::Mutability::Mut }), source_info, ); @@ -1146,9 +1146,9 @@ fn create_coroutine_drop_shim<'tcx>( // Update the body's def to become the drop glue. // This needs to be updated before the AbortUnwindingCalls pass. - let gen_instance = body.source.instance; + let coroutine_instance = body.source.instance; let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, None); - let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(gen_ty)); + let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(coroutine_ty)); body.source.instance = drop_instance; pm::run_passes_no_validate( @@ -1160,7 +1160,7 @@ fn create_coroutine_drop_shim<'tcx>( // Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible // filename. - body.source.instance = gen_instance; + body.source.instance = coroutine_instance; dump_mir(tcx, false, "coroutine_drop", &0, &body, |_, _| Ok(())); body.source.instance = drop_instance; @@ -1447,13 +1447,13 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>( let body = &*body; // The first argument is the coroutine type passed by value - let gen_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty; + let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty; // Get the interior types and args which typeck computed - let movable = match *gen_ty.kind() { + let movable = match *coroutine_ty.kind() { ty::Coroutine(_, _, movability) => movability == hir::Movability::Movable, ty::Error(_) => return None, - _ => span_bug!(body.span, "unexpected coroutine type {}", gen_ty), + _ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty), }; // When first entering the coroutine, move the resume argument into its new local. @@ -1481,16 +1481,17 @@ impl<'tcx> MirPass<'tcx> for StateTransform { assert!(body.coroutine_drop().is_none()); // The first argument is the coroutine type passed by value - let gen_ty = body.local_decls.raw[1].ty; + let coroutine_ty = body.local_decls.raw[1].ty; // Get the discriminant type and args which typeck computed - let (discr_ty, movable) = match *gen_ty.kind() { + let (discr_ty, movable) = match *coroutine_ty.kind() { 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 coroutine type {gen_ty}")); + tcx.sess + .delay_span_bug(body.span, format!("unexpected coroutine type {coroutine_ty}")); return; } }; @@ -1626,7 +1627,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { 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 coroutine - let drop_shim = create_coroutine_drop_shim(tcx, &transform, gen_ty, body, drop_clean); + let drop_shim = create_coroutine_drop_shim(tcx, &transform, coroutine_ty, body, drop_clean); body.coroutine.as_mut().unwrap().coroutine_drop = Some(drop_shim); diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 2400cfa21fba8..4ae5ea4c8d68f 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -69,8 +69,8 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' ty::InstanceDef::DropGlue(def_id, ty) => { // 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::Coroutine(gen_def_id, args, _)) = ty.map(Ty::kind) { - let body = tcx.optimized_mir(*gen_def_id).coroutine_drop().unwrap(); + if let Some(ty::Coroutine(coroutine_def_id, args, _)) = ty.map(Ty::kind) { + let body = tcx.optimized_mir(*coroutine_def_id).coroutine_drop().unwrap(); let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args); debug!("make_shim({:?}) = {:?}", instance, body); @@ -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::Coroutine(gen_def_id, args, hir::Movability::Movable) => { - builder.coroutine_shim(dest, src, *gen_def_id, args.as_coroutine()) + ty::Coroutine(coroutine_def_id, args, hir::Movability::Movable) => { + builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine()) } _ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty), }; @@ -597,7 +597,7 @@ impl<'tcx> CloneShimBuilder<'tcx> { &mut self, dest: Place<'tcx>, src: Place<'tcx>, - gen_def_id: DefId, + coroutine_def_id: DefId, args: CoroutineArgs<'tcx>, ) { self.block(vec![], TerminatorKind::Goto { target: self.block_index_offset(3) }, false); @@ -607,8 +607,8 @@ impl<'tcx> CloneShimBuilder<'tcx> { let unwind = self.clone_fields(dest, src, switch, unwind, args.upvar_tys()); let target = self.block(vec![], TerminatorKind::Return, false); let unreachable = self.block(vec![], TerminatorKind::Unreachable, false); - let mut cases = Vec::with_capacity(args.state_tys(gen_def_id, self.tcx).count()); - for (index, state_tys) in args.state_tys(gen_def_id, self.tcx).enumerate() { + let mut cases = Vec::with_capacity(args.state_tys(coroutine_def_id, self.tcx).count()); + for (index, state_tys) in args.state_tys(coroutine_def_id, self.tcx).enumerate() { let variant_index = VariantIdx::new(index); let dest = self.tcx.mk_place_downcast_unnamed(dest, variant_index); let src = self.tcx.mk_place_downcast_unnamed(src, variant_index); diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index 1ab2bb40af794..27d2bdead838f 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -564,7 +564,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { G::consider_builtin_future_candidate(self, goal) } else if lang_items.iterator_trait() == Some(trait_def_id) { G::consider_builtin_iterator_candidate(self, goal) - } else if lang_items.gen_trait() == Some(trait_def_id) { + } else if lang_items.coroutine_trait() == Some(trait_def_id) { 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) 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 f9ce81ce16553..ba2e3d1ae282a 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 @@ -1648,7 +1648,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } 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 { + self.tcx.hir().body(body_id).coroutine_kind.map(|coroutine_source| match coroutine_source { hir::CoroutineKind::Coroutine => "a coroutine", hir::CoroutineKind::Async(hir::CoroutineSource::Block) => "an async block", hir::CoroutineKind::Async(hir::CoroutineSource::Fn) => "an async function", @@ -3187,7 +3187,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // traits manually, but don't make it more confusing when it does // happen. Some( - if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().gen_trait() && not_tupled + if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().coroutine_trait() + && not_tupled { self.report_and_explain_type_error( TypeTrace::poly_trait_refs( diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 20aa3cec87335..e4f7592c409e1 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1798,7 +1798,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()); let lang_items = selcx.tcx().lang_items(); - if [lang_items.gen_trait(), lang_items.future_trait(), lang_items.iterator_trait()].contains(&Some(trait_ref.def_id)) + if [lang_items.coroutine_trait(), lang_items.future_trait(), lang_items.iterator_trait()].contains(&Some(trait_ref.def_id)) || selcx.tcx().fn_trait_kind_from_def_id(trait_ref.def_id).is_some() { true @@ -2011,7 +2011,7 @@ fn confirm_select_candidate<'cx, 'tcx>( ImplSource::Builtin(BuiltinImplSource::Misc, data) => { 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) { + if lang_items.coroutine_trait() == Some(trait_def_id) { confirm_coroutine_candidate(selcx, obligation, data) } else if lang_items.future_trait() == Some(trait_def_id) { confirm_future_candidate(selcx, obligation, data) @@ -2051,26 +2051,26 @@ fn confirm_coroutine_candidate<'cx, 'tcx>( else { unreachable!() }; - let gen_sig = args.as_coroutine().poly_sig(); - let Normalized { value: gen_sig, obligations } = normalize_with_depth( + let coroutine_sig = args.as_coroutine().poly_sig(); + let Normalized { value: coroutine_sig, obligations } = normalize_with_depth( selcx, obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - gen_sig, + coroutine_sig, ); - debug!(?obligation, ?gen_sig, ?obligations, "confirm_coroutine_candidate"); + debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_coroutine_candidate"); let tcx = selcx.tcx(); - let gen_def_id = tcx.require_lang_item(LangItem::Coroutine, None); + let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, None); let predicate = super::util::coroutine_trait_ref_and_outputs( tcx, - gen_def_id, + coroutine_def_id, obligation.predicate.self_ty(), - gen_sig, + coroutine_sig, ) .map_bound(|(trait_ref, yield_ty, return_ty)| { let name = tcx.associated_item(obligation.predicate.def_id).name; @@ -2103,16 +2103,16 @@ fn confirm_future_candidate<'cx, 'tcx>( else { unreachable!() }; - let gen_sig = args.as_coroutine().poly_sig(); - let Normalized { value: gen_sig, obligations } = normalize_with_depth( + let coroutine_sig = args.as_coroutine().poly_sig(); + let Normalized { value: coroutine_sig, obligations } = normalize_with_depth( selcx, obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - gen_sig, + coroutine_sig, ); - debug!(?obligation, ?gen_sig, ?obligations, "confirm_future_candidate"); + debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_future_candidate"); let tcx = selcx.tcx(); let fut_def_id = tcx.require_lang_item(LangItem::Future, None); @@ -2121,7 +2121,7 @@ fn confirm_future_candidate<'cx, 'tcx>( tcx, fut_def_id, obligation.predicate.self_ty(), - gen_sig, + coroutine_sig, ) .map_bound(|(trait_ref, return_ty)| { debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output); @@ -2156,7 +2156,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>( gen_sig, ); - debug!(?obligation, ?gen_sig, ?obligations, "confirm_future_candidate"); + debug!(?obligation, ?gen_sig, ?obligations, "confirm_iterator_candidate"); let tcx = selcx.tcx(); let iter_def_id = tcx.require_lang_item(LangItem::Iterator, None); 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 ee8e1bf7675d7..5c67188dd2401 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -109,7 +109,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.assemble_builtin_bound_candidates(clone_conditions, &mut candidates); } - if lang_items.gen_trait() == Some(def_id) { + if lang_items.coroutine_trait() == Some(def_id) { self.assemble_coroutine_candidates(obligation, &mut candidates); } else if lang_items.future_trait() == Some(def_id) { self.assemble_future_candidates(obligation, &mut candidates); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 952184175f4dd..4bfa341e3332a 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -730,7 +730,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?obligation, ?coroutine_def_id, ?args, "confirm_coroutine_candidate"); - let gen_sig = args.as_coroutine().poly_sig(); + let coroutine_sig = args.as_coroutine().poly_sig(); // NOTE: The self-type is a coroutine type and hence is // in fact unparameterized (or at least does not reference any @@ -745,7 +745,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.tcx(), obligation.predicate.def_id(), self_ty, - gen_sig, + coroutine_sig, ) .map_bound(|(trait_ref, ..)| trait_ref); @@ -769,13 +769,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?obligation, ?coroutine_def_id, ?args, "confirm_future_candidate"); - let gen_sig = args.as_coroutine().poly_sig(); + let coroutine_sig = args.as_coroutine().poly_sig(); let trait_ref = super::util::future_trait_ref_and_outputs( self.tcx(), obligation.predicate.def_id(), obligation.predicate.no_bound_vars().expect("future has no bound vars").self_ty(), - gen_sig, + coroutine_sig, ) .map_bound(|(trait_ref, ..)| trait_ref); diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index c0fe13ac9965b..1487f40fd9941 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -271,7 +271,7 @@ fn resolve_associated_item<'tcx>( debug_assert!(tcx.defaultness(trait_item_id).has_value()); Some(Instance::new(trait_item_id, rcvr_args)) } - } else if Some(trait_ref.def_id) == lang_items.gen_trait() { + } else if Some(trait_ref.def_id) == lang_items.coroutine_trait() { let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { bug!() };