Skip to content

Commit 3f13562

Browse files
authored
Rollup merge of #127729 - compiler-errors:ed-2024-gen, r=oli-obk
Stop using the `gen` identifier in the compiler In preparation for edition 2024, this PR previews the fallout of removing usages of `gen` since it's being reserved as a keyword. There are two notable changes here: 1. Had to rename `fn gen(..)` in gen/kill analysis to `gen_`. Not certain there's a better name than that. 2. There are (false?[^1]) positives in `rustc_macros` when using synstructure, which uses `gen impl` to mark an implementation. We could suppress this in a one-off way, or perhaps just ignore `gen` in macros altogether, since if an identifier ends up in expanded code then it'll get properly denied anyways. Not relevant to the compiler, but it's gonna be really annoying to change `rand`'s `gen` fn in the library and miri... [^1]: I haven't looked at the synstructure proc macro code itself so I'm not certain if it'll start to fail when converted to ed2024 (or, e.g., when syn starts parsing `gen` as a kw).
2 parents 4f9b598 + 80393ea commit 3f13562

File tree

17 files changed

+79
-68
lines changed

17 files changed

+79
-68
lines changed

Diff for: compiler/rustc_borrowck/src/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
553553
panic!("could not find BorrowIndex for location {location:?}");
554554
});
555555

556-
trans.gen(index);
556+
trans.gen_(index);
557557
}
558558

559559
// Make sure there are no remaining borrows for variables

Diff for: compiler/rustc_hir/src/hir.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3218,10 +3218,10 @@ impl<'hir> Item<'hir> {
32183218
ItemKind::Static(ty, mutbl, body), (ty, *mutbl, *body);
32193219

32203220
expect_const, (&'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
3221-
ItemKind::Const(ty, gen, body), (ty, gen, *body);
3221+
ItemKind::Const(ty, generics, body), (ty, generics, *body);
32223222

32233223
expect_fn, (&FnSig<'hir>, &'hir Generics<'hir>, BodyId),
3224-
ItemKind::Fn(sig, gen, body), (sig, gen, *body);
3224+
ItemKind::Fn(sig, generics, body), (sig, generics, *body);
32253225

32263226
expect_macro, (&ast::MacroDef, MacroKind), ItemKind::Macro(def, mk), (def, *mk);
32273227

@@ -3233,25 +3233,25 @@ impl<'hir> Item<'hir> {
32333233
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm(asm), asm;
32343234

32353235
expect_ty_alias, (&'hir Ty<'hir>, &'hir Generics<'hir>),
3236-
ItemKind::TyAlias(ty, gen), (ty, gen);
3236+
ItemKind::TyAlias(ty, generics), (ty, generics);
32373237

32383238
expect_opaque_ty, &OpaqueTy<'hir>, ItemKind::OpaqueTy(ty), ty;
32393239

3240-
expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, gen), (def, gen);
3240+
expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, generics), (def, generics);
32413241

32423242
expect_struct, (&VariantData<'hir>, &'hir Generics<'hir>),
3243-
ItemKind::Struct(data, gen), (data, gen);
3243+
ItemKind::Struct(data, generics), (data, generics);
32443244

32453245
expect_union, (&VariantData<'hir>, &'hir Generics<'hir>),
3246-
ItemKind::Union(data, gen), (data, gen);
3246+
ItemKind::Union(data, generics), (data, generics);
32473247

32483248
expect_trait,
32493249
(IsAuto, Safety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
3250-
ItemKind::Trait(is_auto, safety, gen, bounds, items),
3251-
(*is_auto, *safety, gen, bounds, items);
3250+
ItemKind::Trait(is_auto, safety, generics, bounds, items),
3251+
(*is_auto, *safety, generics, bounds, items);
32523252

32533253
expect_trait_alias, (&'hir Generics<'hir>, GenericBounds<'hir>),
3254-
ItemKind::TraitAlias(gen, bounds), (gen, bounds);
3254+
ItemKind::TraitAlias(generics, bounds), (generics, bounds);
32553255

32563256
expect_impl, &'hir Impl<'hir>, ItemKind::Impl(imp), imp;
32573257
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25542554
.and_then(|node| node.generics())
25552555
.into_iter()
25562556
.flat_map(|generics| generics.params)
2557-
.find(|gen| &gen.def_id.to_def_id() == res_def_id)
2557+
.find(|param| &param.def_id.to_def_id() == res_def_id)
25582558
} else {
25592559
None
25602560
}

Diff for: compiler/rustc_macros/src/diagnostics/diagnostic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl<'a> DiagnosticDerive<'a> {
7171
});
7272

7373
// A lifetime of `'a` causes conflicts, but `_sess` is fine.
74+
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
75+
#[allow(keyword_idents_2024)]
7476
let mut imp = structure.gen_impl(quote! {
7577
gen impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for @Self
7678
where G: rustc_errors::EmissionGuarantee
@@ -148,6 +150,8 @@ impl<'a> LintDiagnosticDerive<'a> {
148150
}
149151
});
150152

153+
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
154+
#[allow(keyword_idents_2024)]
151155
let mut imp = structure.gen_impl(quote! {
152156
gen impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for @Self {
153157
#[track_caller]

Diff for: compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ impl SubdiagnosticDerive {
8686

8787
let diag = &self.diag;
8888
let f = &self.f;
89+
90+
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
91+
#[allow(keyword_idents_2024)]
8992
let ret = structure.gen_impl(quote! {
9093
gen impl rustc_errors::Subdiagnostic for @Self {
9194
fn add_to_diag_with<__G, __F>(
@@ -100,6 +103,7 @@ impl SubdiagnosticDerive {
100103
}
101104
}
102105
});
106+
103107
ret
104108
}
105109
}

Diff for: compiler/rustc_middle/src/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,14 @@ macro_rules! extra_body_methods {
10161016
macro_rules! super_body {
10171017
($self:ident, $body:ident, $($mutability:ident, $invalidate:tt)?) => {
10181018
let span = $body.span;
1019-
if let Some(gen) = &$($mutability)? $body.coroutine {
1020-
if let Some(yield_ty) = $(& $mutability)? gen.yield_ty {
1019+
if let Some(coroutine) = &$($mutability)? $body.coroutine {
1020+
if let Some(yield_ty) = $(& $mutability)? coroutine.yield_ty {
10211021
$self.visit_ty(
10221022
yield_ty,
10231023
TyContext::YieldTy(SourceInfo::outermost(span))
10241024
);
10251025
}
1026-
if let Some(resume_ty) = $(& $mutability)? gen.resume_ty {
1026+
if let Some(resume_ty) = $(& $mutability)? coroutine.resume_ty {
10271027
$self.visit_ty(
10281028
resume_ty,
10291029
TyContext::ResumeTy(SourceInfo::outermost(span))

Diff for: compiler/rustc_mir_dataflow/src/framework/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ where
402402
/// building up a `GenKillSet` and then throwing it away.
403403
pub trait GenKill<T> {
404404
/// Inserts `elem` into the state vector.
405-
fn gen(&mut self, elem: T);
405+
fn gen_(&mut self, elem: T);
406406

407407
/// Removes `elem` from the state vector.
408408
fn kill(&mut self, elem: T);
409409

410410
/// Calls `gen` for each element in `elems`.
411411
fn gen_all(&mut self, elems: impl IntoIterator<Item = T>) {
412412
for elem in elems {
413-
self.gen(elem);
413+
self.gen_(elem);
414414
}
415415
}
416416

@@ -424,44 +424,44 @@ pub trait GenKill<T> {
424424

425425
/// Stores a transfer function for a gen/kill problem.
426426
///
427-
/// Calling `gen`/`kill` on a `GenKillSet` will "build up" a transfer function so that it can be
428-
/// applied multiple times efficiently. When there are multiple calls to `gen` and/or `kill` for
427+
/// Calling `gen_`/`kill` on a `GenKillSet` will "build up" a transfer function so that it can be
428+
/// applied multiple times efficiently. When there are multiple calls to `gen_` and/or `kill` for
429429
/// the same element, the most recent one takes precedence.
430430
#[derive(Clone)]
431431
pub struct GenKillSet<T> {
432-
gen: HybridBitSet<T>,
432+
gen_: HybridBitSet<T>,
433433
kill: HybridBitSet<T>,
434434
}
435435

436436
impl<T: Idx> GenKillSet<T> {
437437
/// Creates a new transfer function that will leave the dataflow state unchanged.
438438
pub fn identity(universe: usize) -> Self {
439439
GenKillSet {
440-
gen: HybridBitSet::new_empty(universe),
440+
gen_: HybridBitSet::new_empty(universe),
441441
kill: HybridBitSet::new_empty(universe),
442442
}
443443
}
444444

445445
pub fn apply(&self, state: &mut impl BitSetExt<T>) {
446-
state.union(&self.gen);
446+
state.union(&self.gen_);
447447
state.subtract(&self.kill);
448448
}
449449
}
450450

451451
impl<T: Idx> GenKill<T> for GenKillSet<T> {
452-
fn gen(&mut self, elem: T) {
453-
self.gen.insert(elem);
452+
fn gen_(&mut self, elem: T) {
453+
self.gen_.insert(elem);
454454
self.kill.remove(elem);
455455
}
456456

457457
fn kill(&mut self, elem: T) {
458458
self.kill.insert(elem);
459-
self.gen.remove(elem);
459+
self.gen_.remove(elem);
460460
}
461461
}
462462

463463
impl<T: Idx> GenKill<T> for BitSet<T> {
464-
fn gen(&mut self, elem: T) {
464+
fn gen_(&mut self, elem: T) {
465465
self.insert(elem);
466466
}
467467

@@ -471,7 +471,7 @@ impl<T: Idx> GenKill<T> for BitSet<T> {
471471
}
472472

473473
impl<T: Idx> GenKill<T> for ChunkedBitSet<T> {
474-
fn gen(&mut self, elem: T) {
474+
fn gen_(&mut self, elem: T) {
475475
self.insert(elem);
476476
}
477477

@@ -481,11 +481,11 @@ impl<T: Idx> GenKill<T> for ChunkedBitSet<T> {
481481
}
482482

483483
impl<T, S: GenKill<T>> GenKill<T> for MaybeReachable<S> {
484-
fn gen(&mut self, elem: T) {
484+
fn gen_(&mut self, elem: T) {
485485
match self {
486486
// If the state is not reachable, adding an element does nothing.
487487
MaybeReachable::Unreachable => {}
488-
MaybeReachable::Reachable(set) => set.gen(elem),
488+
MaybeReachable::Reachable(set) => set.gen_(elem),
489489
}
490490
}
491491

@@ -499,7 +499,7 @@ impl<T, S: GenKill<T>> GenKill<T> for MaybeReachable<S> {
499499
}
500500

501501
impl<T: Idx> GenKill<T> for lattice::Dual<BitSet<T>> {
502-
fn gen(&mut self, elem: T) {
502+
fn gen_(&mut self, elem: T) {
503503
self.0.insert(elem);
504504
}
505505

Diff for: compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ where
9797
Rvalue::AddressOf(_, borrowed_place)
9898
| Rvalue::Ref(_, BorrowKind::Mut { .. } | BorrowKind::Shared, borrowed_place) => {
9999
if !borrowed_place.is_indirect() {
100-
self.trans.gen(borrowed_place.local);
100+
self.trans.gen_(borrowed_place.local);
101101
}
102102
}
103103

@@ -131,7 +131,7 @@ where
131131
//
132132
// [#61069]: https://github.com/rust-lang/rust/pull/61069
133133
if !dropped_place.is_indirect() {
134-
self.trans.gen(dropped_place.local);
134+
self.trans.gen_(dropped_place.local);
135135
}
136136
}
137137

@@ -159,8 +159,8 @@ pub fn borrowed_locals(body: &Body<'_>) -> BitSet<Local> {
159159

160160
impl GenKill<Local> for Borrowed {
161161
#[inline]
162-
fn gen(&mut self, elem: Local) {
163-
self.0.gen(elem)
162+
fn gen_(&mut self, elem: Local) {
163+
self.0.gen_(elem)
164164
}
165165
#[inline]
166166
fn kill(&mut self, _: Local) {

Diff for: compiler/rustc_mir_dataflow/src/impls/initialized.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<'a, 'mir, 'tcx> MaybeInitializedPlaces<'a, 'mir, 'tcx> {
283283
) {
284284
match state {
285285
DropFlagState::Absent => trans.kill(path),
286-
DropFlagState::Present => trans.gen(path),
286+
DropFlagState::Present => trans.gen_(path),
287287
}
288288
}
289289
}
@@ -295,7 +295,7 @@ impl<'a, 'tcx> MaybeUninitializedPlaces<'a, '_, 'tcx> {
295295
state: DropFlagState,
296296
) {
297297
match state {
298-
DropFlagState::Absent => trans.gen(path),
298+
DropFlagState::Absent => trans.gen_(path),
299299
DropFlagState::Present => trans.kill(path),
300300
}
301301
}
@@ -309,7 +309,7 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
309309
) {
310310
match state {
311311
DropFlagState::Absent => trans.kill(path),
312-
DropFlagState::Present => trans.gen(path),
312+
DropFlagState::Present => trans.gen_(path),
313313
}
314314
}
315315
}
@@ -331,7 +331,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
331331
MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len()));
332332
drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| {
333333
assert!(s == DropFlagState::Present);
334-
state.gen(path);
334+
state.gen_(path);
335335
});
336336
}
337337
}
@@ -362,7 +362,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
362362
&& let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref())
363363
{
364364
on_all_children_bits(self.move_data(), mpi, |child| {
365-
trans.gen(child);
365+
trans.gen_(child);
366366
})
367367
}
368368
}
@@ -400,7 +400,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, '_, 'tcx> {
400400
self.move_data(),
401401
self.move_data().rev_lookup.find(place.as_ref()),
402402
|mpi| {
403-
trans.gen(mpi);
403+
trans.gen_(mpi);
404404
},
405405
);
406406
});
@@ -572,7 +572,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, '_, 'tcx> {
572572
self.move_data(),
573573
enum_place,
574574
variant,
575-
|mpi| trans.gen(mpi),
575+
|mpi| trans.gen_(mpi),
576576
);
577577
});
578578
}
@@ -643,7 +643,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
643643
self.move_data(),
644644
self.move_data().rev_lookup.find(place.as_ref()),
645645
|mpi| {
646-
trans.gen(mpi);
646+
trans.gen_(mpi);
647647
},
648648
);
649649
});
@@ -738,7 +738,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, '_, 'tcx> {
738738

739739
let call_loc = self.body.terminator_loc(block);
740740
for init_index in &init_loc_map[call_loc] {
741-
trans.gen(*init_index);
741+
trans.gen_(*init_index);
742742
}
743743
}
744744
}

Diff for: compiler/rustc_mir_dataflow/src/impls/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
self.0.kill(place.local);
117117
}
118118
}
119-
Some(DefUse::Use) => self.0.gen(place.local),
119+
Some(DefUse::Use) => self.0.gen_(place.local),
120120
None => {}
121121
}
122122

@@ -154,7 +154,7 @@ impl DefUse {
154154
fn apply(trans: &mut impl GenKill<Local>, place: Place<'_>, context: PlaceContext) {
155155
match DefUse::for_place(place, context) {
156156
Some(DefUse::Def) => trans.kill(place.local),
157-
Some(DefUse::Use) => trans.gen(place.local),
157+
Some(DefUse::Use) => trans.gen_(place.local),
158158
None => {}
159159
}
160160
}

0 commit comments

Comments
 (0)