Skip to content

Commit 05aebf8

Browse files
authored
Rollup merge of #98766 - lcnr:mir-visit-pass_by_value, r=oli-obk
cleanup mir visitor for `rustc::pass_by_value` by changing `& $($mutability)?` to `$(& $mutability)?` I also did some formatting changes because I started doing them for the visit methods I changed and then couldn't get myself to stop xx, I hope that's still fairly easy to review.
2 parents 5fe0997 + cf9c0a5 commit 05aebf8

File tree

23 files changed

+193
-150
lines changed

23 files changed

+193
-150
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ impl LocalsStateAtExit {
9292
struct HasStorageDead(BitSet<Local>);
9393

9494
impl<'tcx> Visitor<'tcx> for HasStorageDead {
95-
fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) {
95+
fn visit_local(&mut self, local: Local, ctx: PlaceContext, _: Location) {
9696
if ctx == PlaceContext::NonUse(NonUseContext::StorageDead) {
97-
self.0.insert(*local);
97+
self.0.insert(local);
9898
}
9999
}
100100
}
@@ -223,7 +223,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
223223
self.super_assign(assigned_place, rvalue, location)
224224
}
225225

226-
fn visit_local(&mut self, temp: &Local, context: PlaceContext, location: Location) {
226+
fn visit_local(&mut self, temp: Local, context: PlaceContext, location: Location) {
227227
if !context.is_use() {
228228
return;
229229
}
@@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
232232
// check whether we (earlier) saw a 2-phase borrow like
233233
//
234234
// TMP = &mut place
235-
if let Some(&borrow_index) = self.pending_activations.get(temp) {
235+
if let Some(&borrow_index) = self.pending_activations.get(&temp) {
236236
let borrow_data = &mut self.location_map[borrow_index.as_usize()];
237237

238238
// Watch out: the use of TMP in the borrow itself

Diff for: compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ struct AllLocalUsesVisitor {
1818
}
1919

2020
impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor {
21-
fn visit_local(&mut self, local: &Local, _context: PlaceContext, location: Location) {
22-
if *local == self.for_local {
21+
fn visit_local(&mut self, local: Local, _context: PlaceContext, location: Location) {
22+
if local == self.for_local {
2323
self.uses.insert(location);
2424
}
2525
}

Diff for: compiler/rustc_borrowck/src/diagnostics/find_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ enum DefUseResult {
106106
}
107107

108108
impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> {
109-
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
109+
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
110110
let local_ty = self.body.local_decls[local].ty;
111111

112112
let mut found_it = false;

Diff for: compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl LocalUseMapBuild<'_> {
157157
}
158158

159159
impl Visitor<'_> for LocalUseMapBuild<'_> {
160-
fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) {
160+
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
161161
if self.locals_with_use_data[local] {
162162
match def_use::categorize(context) {
163163
Some(DefUse::Def) => self.insert_def(local, location),

Diff for: compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl UseFactsExtractor<'_, '_> {
5454
}
5555

5656
impl<'a, 'tcx> Visitor<'tcx> for UseFactsExtractor<'a, 'tcx> {
57-
fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) {
57+
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
5858
match def_use::categorize(context) {
5959
Some(DefUse::Def) => self.insert_def(local, location),
6060
Some(DefUse::Use) => self.insert_use(local, location),

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ struct TypeVerifier<'a, 'b, 'tcx> {
333333
}
334334

335335
impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
336-
fn visit_span(&mut self, span: &Span) {
336+
fn visit_span(&mut self, span: Span) {
337337
if !span.is_dummy() {
338-
self.last_span = *span;
338+
self.last_span = span;
339339
}
340340
}
341341

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc
9191
self.super_statement(statement, location);
9292
}
9393

94-
fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) {
95-
if place_context.is_place_assignment() && self.temporary_used_locals.contains(local) {
94+
fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) {
95+
if place_context.is_place_assignment() && self.temporary_used_locals.contains(&local) {
9696
// Propagate the Local assigned at this Location as a used mutable local variable
9797
for moi in &self.mbcx.move_data.loc_map[location] {
9898
let mpi = &self.mbcx.move_data.moves[*moi].path;

Diff for: compiler/rustc_codegen_ssa/src/mir/analyze.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx,
143143
// now that we have moved to the "slice of projections" representation.
144144
if let mir::ProjectionElem::Index(local) = elem {
145145
self.visit_local(
146-
&local,
146+
local,
147147
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
148148
location,
149149
);
150150
}
151151
} else {
152-
self.visit_local(&place_ref.local, context, location);
152+
self.visit_local(place_ref.local, context, location);
153153
}
154154
}
155155
}
@@ -185,7 +185,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
185185
self.process_place(&place.as_ref(), context, location);
186186
}
187187

188-
fn visit_local(&mut self, &local: &mir::Local, context: PlaceContext, location: Location) {
188+
fn visit_local(&mut self, local: mir::Local, context: PlaceContext, location: Location) {
189189
match context {
190190
PlaceContext::MutatingUse(MutatingUseContext::Call)
191191
| PlaceContext::MutatingUse(MutatingUseContext::Yield) => {

Diff for: compiler/rustc_const_eval/src/transform/check_consts/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
418418
PlaceContext::MutatingUse(MutatingUseContext::Borrow)
419419
}
420420
};
421-
self.visit_local(&reborrowed_place_ref.local, ctx, location);
421+
self.visit_local(reborrowed_place_ref.local, ctx, location);
422422
self.visit_projection(reborrowed_place_ref, ctx, location);
423423
return;
424424
}
@@ -431,7 +431,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
431431
}
432432
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf),
433433
};
434-
self.visit_local(&reborrowed_place_ref.local, ctx, location);
434+
self.visit_local(reborrowed_place_ref.local, ctx, location);
435435
self.visit_projection(reborrowed_place_ref, ctx, location);
436436
return;
437437
}

Diff for: compiler/rustc_const_eval/src/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct Collector<'a, 'tcx> {
106106
}
107107

108108
impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
109-
fn visit_local(&mut self, &index: &Local, context: PlaceContext, location: Location) {
109+
fn visit_local(&mut self, index: Local, context: PlaceContext, location: Location) {
110110
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
111111
// We're only interested in temporaries and the return place
112112
match self.ccx.body.local_kind(index) {

Diff for: compiler/rustc_const_eval/src/transform/validate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
196196
}
197197

198198
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
199-
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) {
200-
if self.body.local_decls.get(*local).is_none() {
199+
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
200+
if self.body.local_decls.get(local).is_none() {
201201
self.fail(
202202
location,
203203
format!("local {:?} has no corresponding declaration in `body.local_decls`", local),
@@ -208,7 +208,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
208208
// Uses of locals must occur while the local's storage is allocated.
209209
self.storage_liveness.seek_after_primary_effect(location);
210210
let locals_with_storage = self.storage_liveness.get();
211-
if !locals_with_storage.contains(*local) {
211+
if !locals_with_storage.contains(local) {
212212
self.fail(location, format!("use of local {:?}, which has no storage here", local));
213213
}
214214
}
@@ -823,8 +823,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
823823
self.super_terminator(terminator, location);
824824
}
825825

826-
fn visit_source_scope(&mut self, scope: &SourceScope) {
827-
if self.body.source_scopes.get(*scope).is_none() {
826+
fn visit_source_scope(&mut self, scope: SourceScope) {
827+
if self.body.source_scopes.get(scope).is_none() {
828828
self.tcx.sess.diagnostic().delay_span_bug(
829829
self.body.span,
830830
&format!(

Diff for: compiler/rustc_const_eval/src/util/collect_writes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct FindLocalAssignmentVisitor {
2424
}
2525

2626
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
27-
fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) {
28-
if self.needle != *local {
27+
fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) {
28+
if self.needle != local {
2929
return;
3030
}
3131

0 commit comments

Comments
 (0)