Skip to content

Commit dc20733

Browse files
Stop using the gen keyword in the compiler
1 parent 88fa119 commit dc20733

File tree

10 files changed

+53
-50
lines changed

10 files changed

+53
-50
lines changed

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

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
}

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
}

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))

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

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) {

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
}

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
}

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
5454
_: Location,
5555
) {
5656
match stmt.kind {
57-
StatementKind::StorageLive(l) => trans.gen(l),
57+
StatementKind::StorageLive(l) => trans.gen_(l),
5858
StatementKind::StorageDead(l) => trans.kill(l),
5959
_ => (),
6060
}
@@ -127,7 +127,7 @@ impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageDead<'a> {
127127
) {
128128
match stmt.kind {
129129
StatementKind::StorageLive(l) => trans.kill(l),
130-
StatementKind::StorageDead(l) => trans.gen(l),
130+
StatementKind::StorageDead(l) => trans.gen_(l),
131131
_ => (),
132132
}
133133
}
@@ -208,7 +208,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
208208
StatementKind::Assign(box (place, _))
209209
| StatementKind::SetDiscriminant { box place, .. }
210210
| StatementKind::Deinit(box place) => {
211-
trans.gen(place.local);
211+
trans.gen_(place.local);
212212
}
213213

214214
// Nothing to do for these. Match exhaustively so this fails to compile when new
@@ -250,7 +250,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
250250

251251
match &terminator.kind {
252252
TerminatorKind::Call { destination, .. } => {
253-
trans.gen(destination.local);
253+
trans.gen_(destination.local);
254254
}
255255

256256
// Note that we do *not* gen the `resume_arg` of `Yield` terminators. The reason for
@@ -265,7 +265,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
265265
InlineAsmOperand::Out { place, .. }
266266
| InlineAsmOperand::InOut { out_place: place, .. } => {
267267
if let Some(place) = place {
268-
trans.gen(place.local);
268+
trans.gen_(place.local);
269269
}
270270
}
271271
InlineAsmOperand::In { .. }
@@ -341,7 +341,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
341341
_block: BasicBlock,
342342
return_places: CallReturnPlaces<'_, 'tcx>,
343343
) {
344-
return_places.for_each(|place| trans.gen(place.local));
344+
return_places.for_each(|place| trans.gen_(place.local));
345345
}
346346
}
347347

src/bootstrap/src/core/builder.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,9 @@ impl<'a> Builder<'a> {
19981998
if mode == Mode::Rustc {
19991999
rustflags.arg("-Zunstable-options");
20002000
rustflags.arg("-Wrustc::internal");
2001+
// FIXME(edition_2024): Change this to `-Wrust_2018_idioms` when all
2002+
// of the individual lints are satisfied.
2003+
rustflags.arg("-Wkeyword_idents_2024");
20012004
}
20022005

20032006
if self.config.rust_frame_pointers {

0 commit comments

Comments
 (0)