Skip to content

Commit ffb7ed9

Browse files
committed
Auto merge of #117419 - compiler-errors:gen, r=oli-obk
Some more coroutine renamings a few places where `gen_` names leaked through but should be coroutine. r? oli-obk
2 parents 650991d + add09e6 commit ffb7ed9

File tree

16 files changed

+85
-76
lines changed

16 files changed

+85
-76
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
606606
closure_node_id: NodeId,
607607
ret_ty: Option<hir::FnRetTy<'hir>>,
608608
span: Span,
609-
async_gen_kind: hir::CoroutineSource,
609+
async_coroutine_source: hir::CoroutineSource,
610610
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
611611
) -> hir::ExprKind<'hir> {
612612
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
@@ -645,7 +645,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
645645
let params = arena_vec![self; param];
646646

647647
let body = self.lower_body(move |this| {
648-
this.coroutine_kind = Some(hir::CoroutineKind::Async(async_gen_kind));
648+
this.coroutine_kind = Some(hir::CoroutineKind::Async(async_coroutine_source));
649649

650650
let old_ctx = this.task_context;
651651
this.task_context = Some(task_context_hid);
@@ -684,7 +684,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
684684
closure_node_id: NodeId,
685685
_yield_ty: Option<hir::FnRetTy<'hir>>,
686686
span: Span,
687-
gen_kind: hir::CoroutineSource,
687+
coroutine_source: hir::CoroutineSource,
688688
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
689689
) -> hir::ExprKind<'hir> {
690690
let output = hir::FnRetTy::DefaultReturn(self.lower_span(span));
@@ -699,7 +699,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
699699
});
700700

701701
let body = self.lower_body(move |this| {
702-
this.coroutine_kind = Some(hir::CoroutineKind::Gen(gen_kind));
702+
this.coroutine_kind = Some(hir::CoroutineKind::Gen(coroutine_source));
703703

704704
let res = body(this);
705705
(&[], res)

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -988,12 +988,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
988988
&mut self,
989989
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
990990
) -> hir::BodyId {
991-
let prev_gen_kind = self.coroutine_kind.take();
991+
let prev_coroutine_kind = self.coroutine_kind.take();
992992
let task_context = self.task_context.take();
993993
let (parameters, result) = f(self);
994994
let body_id = self.record_body(parameters, result);
995995
self.task_context = task_context;
996-
self.coroutine_kind = prev_gen_kind;
996+
self.coroutine_kind = prev_coroutine_kind;
997997
body_id
998998
}
999999

compiler/rustc_hir/src/lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ language_item_table! {
212212

213213
Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);
214214
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
215-
CoroutineState, sym::coroutine_state, gen_state, Target::Enum, GenericRequirement::None;
216-
Coroutine, sym::coroutine, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
215+
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
216+
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
217217
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
218218
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
219219

compiler/rustc_hir_typeck/src/check.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ pub(super) fn check_fn<'a, 'tcx>(
128128
// We insert the deferred_coroutine_interiors entry after visiting the body.
129129
// This ensures that all nested coroutines appear before the entry of this coroutine.
130130
// resolve_coroutine_interiors relies on this property.
131-
let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_coroutine, body.coroutine_kind) {
131+
let coroutine_ty = if let (Some(_), Some(coroutine_kind)) =
132+
(can_be_coroutine, body.coroutine_kind)
133+
{
132134
let interior = fcx
133135
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span });
134136
fcx.deferred_coroutine_interiors.borrow_mut().push((
135137
fn_def_id,
136138
body.id(),
137139
interior,
138-
gen_kind,
140+
coroutine_kind,
139141
));
140142

141143
let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap();
@@ -184,7 +186,7 @@ pub(super) fn check_fn<'a, 'tcx>(
184186
check_lang_start_fn(tcx, fn_sig, fn_def_id);
185187
}
186188

187-
gen_ty
189+
coroutine_ty
188190
}
189191

190192
fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>) {

compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
302302

303303
let is_fn = tcx.is_fn_trait(trait_def_id);
304304

305-
let gen_trait = tcx.lang_items().gen_trait();
306-
let is_gen = gen_trait == Some(trait_def_id);
305+
let coroutine_trait = tcx.lang_items().coroutine_trait();
306+
let is_gen = coroutine_trait == Some(trait_def_id);
307307

308308
if !is_fn && !is_gen {
309309
debug!("not fn or coroutine");

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10531053
let term = if let Some(ty) = term.skip_binder().ty()
10541054
&& let ty::Alias(ty::Projection, proj) = ty.kind()
10551055
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
1056-
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
1056+
&& assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait()
10571057
&& assoc.name == rustc_span::sym::Return
10581058
{
10591059
if let ty::Coroutine(_, args, _) = args.type_at(0).kind() {

compiler/rustc_mir_build/src/build/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,14 @@ fn construct_fn<'tcx>(
483483
let arguments = &thir.params;
484484

485485
let (yield_ty, return_ty) = if coroutine_kind.is_some() {
486-
let gen_ty = arguments[thir::UPVAR_ENV_PARAM].ty;
487-
let gen_sig = match gen_ty.kind() {
486+
let coroutine_ty = arguments[thir::UPVAR_ENV_PARAM].ty;
487+
let coroutine_sig = match coroutine_ty.kind() {
488488
ty::Coroutine(_, gen_args, ..) => gen_args.as_coroutine().sig(),
489489
_ => {
490-
span_bug!(span, "coroutine w/o coroutine type: {:?}", gen_ty)
490+
span_bug!(span, "coroutine w/o coroutine type: {:?}", coroutine_ty)
491491
}
492492
};
493-
(Some(gen_sig.yield_ty), gen_sig.return_ty)
493+
(Some(coroutine_sig.yield_ty), coroutine_sig.return_ty)
494494
} else {
495495
(None, fn_sig.output())
496496
};

compiler/rustc_mir_build/src/thir/cx/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,15 @@ impl<'tcx> Cx<'tcx> {
149149
Some(env_param)
150150
}
151151
DefKind::Coroutine => {
152-
let gen_ty = self.typeck_results.node_type(owner_id);
153-
let gen_param =
154-
Param { ty: gen_ty, pat: None, ty_span: None, self_kind: None, hir_id: None };
155-
Some(gen_param)
152+
let coroutine_ty = self.typeck_results.node_type(owner_id);
153+
let coroutine_param = Param {
154+
ty: coroutine_ty,
155+
pat: None,
156+
ty_span: None,
157+
self_kind: None,
158+
hir_id: None,
159+
};
160+
Some(coroutine_param)
156161
}
157162
_ => None,
158163
}

compiler/rustc_mir_transform/src/coroutine.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
147147
}
148148

149149
struct PinArgVisitor<'tcx> {
150-
ref_gen_ty: Ty<'tcx>,
150+
ref_coroutine_ty: Ty<'tcx>,
151151
tcx: TyCtxt<'tcx>,
152152
}
153153

@@ -168,7 +168,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
168168
local: SELF_ARG,
169169
projection: self.tcx().mk_place_elems(&[ProjectionElem::Field(
170170
FieldIdx::new(0),
171-
self.ref_gen_ty,
171+
self.ref_coroutine_ty,
172172
)]),
173173
},
174174
self.tcx,
@@ -468,34 +468,34 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
468468
}
469469

470470
fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
471-
let gen_ty = body.local_decls.raw[1].ty;
471+
let coroutine_ty = body.local_decls.raw[1].ty;
472472

473-
let ref_gen_ty = Ty::new_ref(
473+
let ref_coroutine_ty = Ty::new_ref(
474474
tcx,
475475
tcx.lifetimes.re_erased,
476-
ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut },
476+
ty::TypeAndMut { ty: coroutine_ty, mutbl: Mutability::Mut },
477477
);
478478

479479
// Replace the by value coroutine argument
480-
body.local_decls.raw[1].ty = ref_gen_ty;
480+
body.local_decls.raw[1].ty = ref_coroutine_ty;
481481

482482
// Add a deref to accesses of the coroutine state
483483
DerefArgVisitor { tcx }.visit_body(body);
484484
}
485485

486486
fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
487-
let ref_gen_ty = body.local_decls.raw[1].ty;
487+
let ref_coroutine_ty = body.local_decls.raw[1].ty;
488488

489489
let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span));
490490
let pin_adt_ref = tcx.adt_def(pin_did);
491-
let args = tcx.mk_args(&[ref_gen_ty.into()]);
492-
let pin_ref_gen_ty = Ty::new_adt(tcx, pin_adt_ref, args);
491+
let args = tcx.mk_args(&[ref_coroutine_ty.into()]);
492+
let pin_ref_coroutine_ty = Ty::new_adt(tcx, pin_adt_ref, args);
493493

494494
// Replace the by ref coroutine argument
495-
body.local_decls.raw[1].ty = pin_ref_gen_ty;
495+
body.local_decls.raw[1].ty = pin_ref_coroutine_ty;
496496

497497
// Add the Pin field access to accesses of the coroutine state
498-
PinArgVisitor { ref_gen_ty, tcx }.visit_body(body);
498+
PinArgVisitor { ref_coroutine_ty, tcx }.visit_body(body);
499499
}
500500

501501
/// 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>) {
11041104
fn create_coroutine_drop_shim<'tcx>(
11051105
tcx: TyCtxt<'tcx>,
11061106
transform: &TransformVisitor<'tcx>,
1107-
gen_ty: Ty<'tcx>,
1107+
coroutine_ty: Ty<'tcx>,
11081108
body: &mut Body<'tcx>,
11091109
drop_clean: BasicBlock,
11101110
) -> Body<'tcx> {
@@ -1136,7 +1136,7 @@ fn create_coroutine_drop_shim<'tcx>(
11361136

11371137
// Change the coroutine argument from &mut to *mut
11381138
body.local_decls[SELF_ARG] = LocalDecl::with_source_info(
1139-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: gen_ty, mutbl: hir::Mutability::Mut }),
1139+
Ty::new_ptr(tcx, ty::TypeAndMut { ty: coroutine_ty, mutbl: hir::Mutability::Mut }),
11401140
source_info,
11411141
);
11421142

@@ -1146,9 +1146,9 @@ fn create_coroutine_drop_shim<'tcx>(
11461146

11471147
// Update the body's def to become the drop glue.
11481148
// This needs to be updated before the AbortUnwindingCalls pass.
1149-
let gen_instance = body.source.instance;
1149+
let coroutine_instance = body.source.instance;
11501150
let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, None);
1151-
let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(gen_ty));
1151+
let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(coroutine_ty));
11521152
body.source.instance = drop_instance;
11531153

11541154
pm::run_passes_no_validate(
@@ -1160,7 +1160,7 @@ fn create_coroutine_drop_shim<'tcx>(
11601160

11611161
// Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible
11621162
// filename.
1163-
body.source.instance = gen_instance;
1163+
body.source.instance = coroutine_instance;
11641164
dump_mir(tcx, false, "coroutine_drop", &0, &body, |_, _| Ok(()));
11651165
body.source.instance = drop_instance;
11661166

@@ -1447,13 +1447,13 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>(
14471447
let body = &*body;
14481448

14491449
// The first argument is the coroutine type passed by value
1450-
let gen_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
1450+
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
14511451

14521452
// Get the interior types and args which typeck computed
1453-
let movable = match *gen_ty.kind() {
1453+
let movable = match *coroutine_ty.kind() {
14541454
ty::Coroutine(_, _, movability) => movability == hir::Movability::Movable,
14551455
ty::Error(_) => return None,
1456-
_ => span_bug!(body.span, "unexpected coroutine type {}", gen_ty),
1456+
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
14571457
};
14581458

14591459
// When first entering the coroutine, move the resume argument into its new local.
@@ -1481,16 +1481,17 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
14811481
assert!(body.coroutine_drop().is_none());
14821482

14831483
// The first argument is the coroutine type passed by value
1484-
let gen_ty = body.local_decls.raw[1].ty;
1484+
let coroutine_ty = body.local_decls.raw[1].ty;
14851485

14861486
// Get the discriminant type and args which typeck computed
1487-
let (discr_ty, movable) = match *gen_ty.kind() {
1487+
let (discr_ty, movable) = match *coroutine_ty.kind() {
14881488
ty::Coroutine(_, args, movability) => {
14891489
let args = args.as_coroutine();
14901490
(args.discr_ty(tcx), movability == hir::Movability::Movable)
14911491
}
14921492
_ => {
1493-
tcx.sess.delay_span_bug(body.span, format!("unexpected coroutine type {gen_ty}"));
1493+
tcx.sess
1494+
.delay_span_bug(body.span, format!("unexpected coroutine type {coroutine_ty}"));
14941495
return;
14951496
}
14961497
};
@@ -1626,7 +1627,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
16261627
dump_mir(tcx, false, "coroutine_post-transform", &0, body, |_, _| Ok(()));
16271628

16281629
// Create a copy of our MIR and use it to create the drop shim for the coroutine
1629-
let drop_shim = create_coroutine_drop_shim(tcx, &transform, gen_ty, body, drop_clean);
1630+
let drop_shim = create_coroutine_drop_shim(tcx, &transform, coroutine_ty, body, drop_clean);
16301631

16311632
body.coroutine.as_mut().unwrap().coroutine_drop = Some(drop_shim);
16321633

compiler/rustc_mir_transform/src/shim.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
6969
ty::InstanceDef::DropGlue(def_id, ty) => {
7070
// FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end
7171
// of this function. Is this intentional?
72-
if let Some(ty::Coroutine(gen_def_id, args, _)) = ty.map(Ty::kind) {
73-
let body = tcx.optimized_mir(*gen_def_id).coroutine_drop().unwrap();
72+
if let Some(ty::Coroutine(coroutine_def_id, args, _)) = ty.map(Ty::kind) {
73+
let body = tcx.optimized_mir(*coroutine_def_id).coroutine_drop().unwrap();
7474
let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args);
7575
debug!("make_shim({:?}) = {:?}", instance, body);
7676

@@ -392,8 +392,8 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
392392
_ if is_copy => builder.copy_shim(),
393393
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
394394
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
395-
ty::Coroutine(gen_def_id, args, hir::Movability::Movable) => {
396-
builder.coroutine_shim(dest, src, *gen_def_id, args.as_coroutine())
395+
ty::Coroutine(coroutine_def_id, args, hir::Movability::Movable) => {
396+
builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine())
397397
}
398398
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),
399399
};
@@ -597,7 +597,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
597597
&mut self,
598598
dest: Place<'tcx>,
599599
src: Place<'tcx>,
600-
gen_def_id: DefId,
600+
coroutine_def_id: DefId,
601601
args: CoroutineArgs<'tcx>,
602602
) {
603603
self.block(vec![], TerminatorKind::Goto { target: self.block_index_offset(3) }, false);
@@ -607,8 +607,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
607607
let unwind = self.clone_fields(dest, src, switch, unwind, args.upvar_tys());
608608
let target = self.block(vec![], TerminatorKind::Return, false);
609609
let unreachable = self.block(vec![], TerminatorKind::Unreachable, false);
610-
let mut cases = Vec::with_capacity(args.state_tys(gen_def_id, self.tcx).count());
611-
for (index, state_tys) in args.state_tys(gen_def_id, self.tcx).enumerate() {
610+
let mut cases = Vec::with_capacity(args.state_tys(coroutine_def_id, self.tcx).count());
611+
for (index, state_tys) in args.state_tys(coroutine_def_id, self.tcx).enumerate() {
612612
let variant_index = VariantIdx::new(index);
613613
let dest = self.tcx.mk_place_downcast_unnamed(dest, variant_index);
614614
let src = self.tcx.mk_place_downcast_unnamed(src, variant_index);

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
564564
G::consider_builtin_future_candidate(self, goal)
565565
} else if lang_items.iterator_trait() == Some(trait_def_id) {
566566
G::consider_builtin_iterator_candidate(self, goal)
567-
} else if lang_items.gen_trait() == Some(trait_def_id) {
567+
} else if lang_items.coroutine_trait() == Some(trait_def_id) {
568568
G::consider_builtin_coroutine_candidate(self, goal)
569569
} else if lang_items.discriminant_kind_trait() == Some(trait_def_id) {
570570
G::consider_builtin_discriminant_kind_candidate(self, goal)

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16481648
}
16491649

16501650
fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> {
1651-
self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind {
1651+
self.tcx.hir().body(body_id).coroutine_kind.map(|coroutine_source| match coroutine_source {
16521652
hir::CoroutineKind::Coroutine => "a coroutine",
16531653
hir::CoroutineKind::Async(hir::CoroutineSource::Block) => "an async block",
16541654
hir::CoroutineKind::Async(hir::CoroutineSource::Fn) => "an async function",
@@ -3187,7 +3187,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31873187
// traits manually, but don't make it more confusing when it does
31883188
// happen.
31893189
Some(
3190-
if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().gen_trait() && not_tupled
3190+
if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().coroutine_trait()
3191+
&& not_tupled
31913192
{
31923193
self.report_and_explain_type_error(
31933194
TypeTrace::poly_trait_refs(

0 commit comments

Comments
 (0)