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.
This commit is contained in:
Dylan DPC 2022-07-02 12:23:41 +05:30 committed by GitHub
commit 05aebf8f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 193 additions and 150 deletions

View File

@ -92,9 +92,9 @@ impl LocalsStateAtExit {
struct HasStorageDead(BitSet<Local>); struct HasStorageDead(BitSet<Local>);
impl<'tcx> Visitor<'tcx> for HasStorageDead { impl<'tcx> Visitor<'tcx> for HasStorageDead {
fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) { fn visit_local(&mut self, local: Local, ctx: PlaceContext, _: Location) {
if ctx == PlaceContext::NonUse(NonUseContext::StorageDead) { if ctx == PlaceContext::NonUse(NonUseContext::StorageDead) {
self.0.insert(*local); self.0.insert(local);
} }
} }
} }
@ -223,7 +223,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
self.super_assign(assigned_place, rvalue, location) self.super_assign(assigned_place, rvalue, location)
} }
fn visit_local(&mut self, temp: &Local, context: PlaceContext, location: Location) { fn visit_local(&mut self, temp: Local, context: PlaceContext, location: Location) {
if !context.is_use() { if !context.is_use() {
return; return;
} }
@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
// check whether we (earlier) saw a 2-phase borrow like // check whether we (earlier) saw a 2-phase borrow like
// //
// TMP = &mut place // TMP = &mut place
if let Some(&borrow_index) = self.pending_activations.get(temp) { if let Some(&borrow_index) = self.pending_activations.get(&temp) {
let borrow_data = &mut self.location_map[borrow_index.as_usize()]; let borrow_data = &mut self.location_map[borrow_index.as_usize()];
// Watch out: the use of TMP in the borrow itself // Watch out: the use of TMP in the borrow itself

View File

@ -18,8 +18,8 @@ struct AllLocalUsesVisitor {
} }
impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor { impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor {
fn visit_local(&mut self, local: &Local, _context: PlaceContext, location: Location) { fn visit_local(&mut self, local: Local, _context: PlaceContext, location: Location) {
if *local == self.for_local { if local == self.for_local {
self.uses.insert(location); self.uses.insert(location);
} }
} }

View File

@ -106,7 +106,7 @@ enum DefUseResult {
} }
impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> { impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
let local_ty = self.body.local_decls[local].ty; let local_ty = self.body.local_decls[local].ty;
let mut found_it = false; let mut found_it = false;

View File

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

View File

@ -54,7 +54,7 @@ impl UseFactsExtractor<'_, '_> {
} }
impl<'a, 'tcx> Visitor<'tcx> for UseFactsExtractor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for UseFactsExtractor<'a, 'tcx> {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
match def_use::categorize(context) { match def_use::categorize(context) {
Some(DefUse::Def) => self.insert_def(local, location), Some(DefUse::Def) => self.insert_def(local, location),
Some(DefUse::Use) => self.insert_use(local, location), Some(DefUse::Use) => self.insert_use(local, location),

View File

@ -333,9 +333,9 @@ struct TypeVerifier<'a, 'b, 'tcx> {
} }
impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
fn visit_span(&mut self, span: &Span) { fn visit_span(&mut self, span: Span) {
if !span.is_dummy() { if !span.is_dummy() {
self.last_span = *span; self.last_span = span;
} }
} }

View File

@ -91,8 +91,8 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc
self.super_statement(statement, location); self.super_statement(statement, location);
} }
fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) { fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) {
if place_context.is_place_assignment() && self.temporary_used_locals.contains(local) { if place_context.is_place_assignment() && self.temporary_used_locals.contains(&local) {
// Propagate the Local assigned at this Location as a used mutable local variable // Propagate the Local assigned at this Location as a used mutable local variable
for moi in &self.mbcx.move_data.loc_map[location] { for moi in &self.mbcx.move_data.loc_map[location] {
let mpi = &self.mbcx.move_data.moves[*moi].path; let mpi = &self.mbcx.move_data.moves[*moi].path;

View File

@ -143,13 +143,13 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx,
// now that we have moved to the "slice of projections" representation. // now that we have moved to the "slice of projections" representation.
if let mir::ProjectionElem::Index(local) = elem { if let mir::ProjectionElem::Index(local) = elem {
self.visit_local( self.visit_local(
&local, local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location, location,
); );
} }
} else { } else {
self.visit_local(&place_ref.local, context, location); self.visit_local(place_ref.local, context, location);
} }
} }
} }
@ -185,7 +185,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
self.process_place(&place.as_ref(), context, location); self.process_place(&place.as_ref(), context, location);
} }
fn visit_local(&mut self, &local: &mir::Local, context: PlaceContext, location: Location) { fn visit_local(&mut self, local: mir::Local, context: PlaceContext, location: Location) {
match context { match context {
PlaceContext::MutatingUse(MutatingUseContext::Call) PlaceContext::MutatingUse(MutatingUseContext::Call)
| PlaceContext::MutatingUse(MutatingUseContext::Yield) => { | PlaceContext::MutatingUse(MutatingUseContext::Yield) => {

View File

@ -418,7 +418,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
PlaceContext::MutatingUse(MutatingUseContext::Borrow) PlaceContext::MutatingUse(MutatingUseContext::Borrow)
} }
}; };
self.visit_local(&reborrowed_place_ref.local, ctx, location); self.visit_local(reborrowed_place_ref.local, ctx, location);
self.visit_projection(reborrowed_place_ref, ctx, location); self.visit_projection(reborrowed_place_ref, ctx, location);
return; return;
} }
@ -431,7 +431,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
} }
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf), Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf),
}; };
self.visit_local(&reborrowed_place_ref.local, ctx, location); self.visit_local(reborrowed_place_ref.local, ctx, location);
self.visit_projection(reborrowed_place_ref, ctx, location); self.visit_projection(reborrowed_place_ref, ctx, location);
return; return;
} }

View File

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

View File

@ -196,8 +196,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
if self.body.local_decls.get(*local).is_none() { if self.body.local_decls.get(local).is_none() {
self.fail( self.fail(
location, location,
format!("local {:?} has no corresponding declaration in `body.local_decls`", local), format!("local {:?} has no corresponding declaration in `body.local_decls`", local),
@ -208,7 +208,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
// Uses of locals must occur while the local's storage is allocated. // Uses of locals must occur while the local's storage is allocated.
self.storage_liveness.seek_after_primary_effect(location); self.storage_liveness.seek_after_primary_effect(location);
let locals_with_storage = self.storage_liveness.get(); let locals_with_storage = self.storage_liveness.get();
if !locals_with_storage.contains(*local) { if !locals_with_storage.contains(local) {
self.fail(location, format!("use of local {:?}, which has no storage here", local)); self.fail(location, format!("use of local {:?}, which has no storage here", local));
} }
} }
@ -823,8 +823,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
self.super_terminator(terminator, location); self.super_terminator(terminator, location);
} }
fn visit_source_scope(&mut self, scope: &SourceScope) { fn visit_source_scope(&mut self, scope: SourceScope) {
if self.body.source_scopes.get(*scope).is_none() { if self.body.source_scopes.get(scope).is_none() {
self.tcx.sess.diagnostic().delay_span_bug( self.tcx.sess.diagnostic().delay_span_bug(
self.body.span, self.body.span,
&format!( &format!(

View File

@ -24,8 +24,8 @@ struct FindLocalAssignmentVisitor {
} }
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor { impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) { fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) {
if self.needle != *local { if self.needle != local {
return; return;
} }

View File

@ -30,9 +30,11 @@
//! For example, the `super_basic_block_data` method begins like this: //! For example, the `super_basic_block_data` method begins like this:
//! //!
//! ```ignore (pseudo-rust) //! ```ignore (pseudo-rust)
//! fn super_basic_block_data(&mut self, //! fn super_basic_block_data(
//! block: BasicBlock, //! &mut self,
//! data: & $($mutability)? BasicBlockData<'tcx>) { //! block: BasicBlock,
//! data: & $($mutability)? BasicBlockData<'tcx>
//! ) {
//! let BasicBlockData { //! let BasicBlockData {
//! statements, //! statements,
//! terminator, //! terminator,
@ -78,106 +80,135 @@ macro_rules! make_mir_visitor {
self.super_body(body); self.super_body(body);
} }
fn visit_basic_block_data(&mut self, fn visit_basic_block_data(
block: BasicBlock, &mut self,
data: & $($mutability)? BasicBlockData<'tcx>) { block: BasicBlock,
data: & $($mutability)? BasicBlockData<'tcx>,
) {
self.super_basic_block_data(block, data); self.super_basic_block_data(block, data);
} }
fn visit_source_scope_data(&mut self, fn visit_source_scope_data(
scope_data: & $($mutability)? SourceScopeData<'tcx>) { &mut self,
scope_data: & $($mutability)? SourceScopeData<'tcx>,
) {
self.super_source_scope_data(scope_data); self.super_source_scope_data(scope_data);
} }
fn visit_statement(&mut self, fn visit_statement(
statement: & $($mutability)? Statement<'tcx>, &mut self,
location: Location) { statement: & $($mutability)? Statement<'tcx>,
location: Location,
) {
self.super_statement(statement, location); self.super_statement(statement, location);
} }
fn visit_assign(&mut self, fn visit_assign(
place: & $($mutability)? Place<'tcx>, &mut self,
rvalue: & $($mutability)? Rvalue<'tcx>, place: & $($mutability)? Place<'tcx>,
location: Location) { rvalue: & $($mutability)? Rvalue<'tcx>,
location: Location,
) {
self.super_assign(place, rvalue, location); self.super_assign(place, rvalue, location);
} }
fn visit_terminator(&mut self, fn visit_terminator(
terminator: & $($mutability)? Terminator<'tcx>, &mut self,
location: Location) { terminator: & $($mutability)? Terminator<'tcx>,
location: Location,
) {
self.super_terminator(terminator, location); self.super_terminator(terminator, location);
} }
fn visit_assert_message(&mut self, fn visit_assert_message(
msg: & $($mutability)? AssertMessage<'tcx>, &mut self,
location: Location) { msg: & $($mutability)? AssertMessage<'tcx>,
location: Location,
) {
self.super_assert_message(msg, location); self.super_assert_message(msg, location);
} }
fn visit_rvalue(&mut self, fn visit_rvalue(
rvalue: & $($mutability)? Rvalue<'tcx>, &mut self,
location: Location) { rvalue: & $($mutability)? Rvalue<'tcx>,
location: Location,
) {
self.super_rvalue(rvalue, location); self.super_rvalue(rvalue, location);
} }
fn visit_operand(&mut self, fn visit_operand(
operand: & $($mutability)? Operand<'tcx>, &mut self,
location: Location) { operand: & $($mutability)? Operand<'tcx>,
location: Location,
) {
self.super_operand(operand, location); self.super_operand(operand, location);
} }
fn visit_ascribe_user_ty(&mut self, fn visit_ascribe_user_ty(
place: & $($mutability)? Place<'tcx>, &mut self,
variance: & $($mutability)? ty::Variance, place: & $($mutability)? Place<'tcx>,
user_ty: & $($mutability)? UserTypeProjection, variance: & $($mutability)? ty::Variance,
location: Location) { user_ty: & $($mutability)? UserTypeProjection,
location: Location,
) {
self.super_ascribe_user_ty(place, variance, user_ty, location); self.super_ascribe_user_ty(place, variance, user_ty, location);
} }
fn visit_coverage(&mut self, fn visit_coverage(
coverage: & $($mutability)? Coverage, &mut self,
location: Location) { coverage: & $($mutability)? Coverage,
location: Location,
) {
self.super_coverage(coverage, location); self.super_coverage(coverage, location);
} }
fn visit_retag(&mut self, fn visit_retag(
kind: & $($mutability)? RetagKind, &mut self,
place: & $($mutability)? Place<'tcx>, kind: & $($mutability)? RetagKind,
location: Location) { place: & $($mutability)? Place<'tcx>,
location: Location,
) {
self.super_retag(kind, place, location); self.super_retag(kind, place, location);
} }
fn visit_place(&mut self, fn visit_place(
place: & $($mutability)? Place<'tcx>, &mut self,
context: PlaceContext, place: & $($mutability)? Place<'tcx>,
location: Location) { context: PlaceContext,
location: Location,
) {
self.super_place(place, context, location); self.super_place(place, context, location);
} }
visit_place_fns!($($mutability)?); visit_place_fns!($($mutability)?);
fn visit_constant(&mut self, fn visit_constant(
constant: & $($mutability)? Constant<'tcx>, &mut self,
location: Location) { constant: & $($mutability)? Constant<'tcx>,
location: Location,
) {
self.super_constant(constant, location); self.super_constant(constant, location);
} }
// The macro results in a false positive of sorts, where &mut Span fn visit_span(
// is fine, but &Span is not; just allow the lint. &mut self,
#[allow(rustc::pass_by_value)] span: $(& $mutability)? Span,
fn visit_span(&mut self, ) {
span: & $($mutability)? Span) {
self.super_span(span); self.super_span(span);
} }
fn visit_source_info(&mut self, fn visit_source_info(
source_info: & $($mutability)? SourceInfo) { &mut self,
source_info: & $($mutability)? SourceInfo,
) {
self.super_source_info(source_info); self.super_source_info(source_info);
} }
fn visit_ty(&mut self, fn visit_ty(
ty: $(& $mutability)? Ty<'tcx>, &mut self,
_: TyContext) { ty: $(& $mutability)? Ty<'tcx>,
_: TyContext,
) {
self.super_ty(ty); self.super_ty(ty);
} }
@ -196,45 +227,56 @@ macro_rules! make_mir_visitor {
self.super_user_type_annotation(index, ty); self.super_user_type_annotation(index, ty);
} }
fn visit_region(&mut self, fn visit_region(
region: $(& $mutability)? ty::Region<'tcx>, &mut self,
_: Location) { region: $(& $mutability)? ty::Region<'tcx>,
_: Location,
) {
self.super_region(region); self.super_region(region);
} }
fn visit_const(&mut self, fn visit_const(
constant: $(& $mutability)? ty::Const<'tcx>, &mut self,
_: Location) { constant: $(& $mutability)? ty::Const<'tcx>,
_: Location,
) {
self.super_const(constant); self.super_const(constant);
} }
fn visit_substs(&mut self, fn visit_substs(
substs: & $($mutability)? SubstsRef<'tcx>, &mut self,
_: Location) { substs: & $($mutability)? SubstsRef<'tcx>,
_: Location,
) {
self.super_substs(substs); self.super_substs(substs);
} }
fn visit_local_decl(&mut self, fn visit_local_decl(
local: Local, &mut self,
local_decl: & $($mutability)? LocalDecl<'tcx>) { local: Local,
local_decl: & $($mutability)? LocalDecl<'tcx>,
) {
self.super_local_decl(local, local_decl); self.super_local_decl(local, local_decl);
} }
fn visit_var_debug_info(&mut self, fn visit_var_debug_info(
var_debug_info: & $($mutability)* VarDebugInfo<'tcx>) { &mut self,
var_debug_info: & $($mutability)* VarDebugInfo<'tcx>,
) {
self.super_var_debug_info(var_debug_info); self.super_var_debug_info(var_debug_info);
} }
#[allow(rustc::pass_by_value)] fn visit_local(
fn visit_local(&mut self, &mut self,
_local: & $($mutability)? Local, _local: $(& $mutability)? Local,
_context: PlaceContext, _context: PlaceContext,
_location: Location) { _location: Location,
} ) {}
#[allow(rustc::pass_by_value)] fn visit_source_scope(
fn visit_source_scope(&mut self, &mut self,
scope: & $($mutability)? SourceScope) { scope: $(& $mutability)? SourceScope,
) {
self.super_source_scope(scope); self.super_source_scope(scope);
} }
@ -296,7 +338,7 @@ macro_rules! make_mir_visitor {
self.visit_var_debug_info(var_debug_info); self.visit_var_debug_info(var_debug_info);
} }
self.visit_span(&$($mutability)? body.span); self.visit_span($(& $mutability)? body.span);
for const_ in &$($mutability)? body.required_consts { for const_ in &$($mutability)? body.required_consts {
let location = START_BLOCK.start_location(); let location = START_BLOCK.start_location();
@ -338,14 +380,14 @@ macro_rules! make_mir_visitor {
local_data: _, local_data: _,
} = scope_data; } = scope_data;
self.visit_span(span); self.visit_span($(& $mutability)? *span);
if let Some(parent_scope) = parent_scope { if let Some(parent_scope) = parent_scope {
self.visit_source_scope(parent_scope); self.visit_source_scope($(& $mutability)? *parent_scope);
} }
if let Some((callee, callsite_span)) = inlined { if let Some((callee, callsite_span)) = inlined {
let location = START_BLOCK.start_location(); let location = START_BLOCK.start_location();
self.visit_span(callsite_span); self.visit_span($(& $mutability)? *callsite_span);
let ty::Instance { def: callee_def, substs: callee_substs } = callee; let ty::Instance { def: callee_def, substs: callee_substs } = callee;
match callee_def { match callee_def {
@ -368,7 +410,7 @@ macro_rules! make_mir_visitor {
self.visit_substs(callee_substs, location); self.visit_substs(callee_substs, location);
} }
if let Some(inlined_parent_scope) = inlined_parent_scope { if let Some(inlined_parent_scope) = inlined_parent_scope {
self.visit_source_scope(inlined_parent_scope); self.visit_source_scope($(& $mutability)? *inlined_parent_scope);
} }
} }
@ -410,14 +452,14 @@ macro_rules! make_mir_visitor {
} }
StatementKind::StorageLive(local) => { StatementKind::StorageLive(local) => {
self.visit_local( self.visit_local(
local, $(& $mutability)? *local,
PlaceContext::NonUse(NonUseContext::StorageLive), PlaceContext::NonUse(NonUseContext::StorageLive),
location location
); );
} }
StatementKind::StorageDead(local) => { StatementKind::StorageDead(local) => {
self.visit_local( self.visit_local(
local, $(& $mutability)? *local,
PlaceContext::NonUse(NonUseContext::StorageDead), PlaceContext::NonUse(NonUseContext::StorageDead),
location location
); );
@ -483,7 +525,7 @@ macro_rules! make_mir_visitor {
// cannot be changed by any visitor, though. // cannot be changed by any visitor, though.
let $($mutability)? local = RETURN_PLACE; let $($mutability)? local = RETURN_PLACE;
self.visit_local( self.visit_local(
& $($mutability)? local, $(& $mutability)? local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move), PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
location, location,
); );
@ -840,8 +882,10 @@ macro_rules! make_mir_visitor {
self.visit_source_info(source_info); self.visit_source_info(source_info);
} }
fn super_var_debug_info(&mut self, fn super_var_debug_info(
var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) { &mut self,
var_debug_info: & $($mutability)? VarDebugInfo<'tcx>
) {
let VarDebugInfo { let VarDebugInfo {
name: _, name: _,
source_info, source_info,
@ -861,21 +905,23 @@ macro_rules! make_mir_visitor {
} }
} }
#[allow(rustc::pass_by_value)] fn super_source_scope(
fn super_source_scope(&mut self, &mut self,
_scope: & $($mutability)? SourceScope) { _scope: $(& $mutability)? SourceScope
} ) {}
fn super_constant(&mut self, fn super_constant(
constant: & $($mutability)? Constant<'tcx>, &mut self,
location: Location) { constant: & $($mutability)? Constant<'tcx>,
location: Location
) {
let Constant { let Constant {
span, span,
user_ty, user_ty,
literal, literal,
} = constant; } = constant;
self.visit_span(span); self.visit_span($(& $mutability)? *span);
drop(user_ty); // no visit method for this drop(user_ty); // no visit method for this
match literal { match literal {
ConstantKind::Ty(ct) => self.visit_const($(& $mutability)? *ct, location), ConstantKind::Ty(ct) => self.visit_const($(& $mutability)? *ct, location),
@ -883,10 +929,7 @@ macro_rules! make_mir_visitor {
} }
} }
// The macro results in a false positive of sorts, where &mut Span fn super_span(&mut self, _span: $(& $mutability)? Span) {
// is fine, but &Span is not; just allow the lint.
#[allow(rustc::pass_by_value)]
fn super_span(&mut self, _span: & $($mutability)? Span) {
} }
fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) { fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) {
@ -895,8 +938,8 @@ macro_rules! make_mir_visitor {
scope, scope,
} = source_info; } = source_info;
self.visit_span(span); self.visit_span($(& $mutability)? *span);
self.visit_source_scope(scope); self.visit_source_scope($(& $mutability)? *scope);
} }
fn super_user_type_projection( fn super_user_type_projection(
@ -910,7 +953,7 @@ macro_rules! make_mir_visitor {
_index: UserTypeAnnotationIndex, _index: UserTypeAnnotationIndex,
ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>, ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
) { ) {
self.visit_span(& $($mutability)? ty.span); self.visit_span($(& $mutability)? ty.span);
self.visit_ty($(& $mutability)? ty.inferred_ty, TyContext::UserTy(ty.span)); self.visit_ty($(& $mutability)? ty.inferred_ty, TyContext::UserTy(ty.span));
} }
@ -1058,7 +1101,7 @@ macro_rules! visit_place_fns {
} }
} }
self.visit_local(&place.local, context, location); self.visit_local(place.local, context, location);
self.visit_projection(place.as_ref(), context, location); self.visit_projection(place.as_ref(), context, location);
} }
@ -1091,7 +1134,7 @@ macro_rules! visit_place_fns {
} }
ProjectionElem::Index(local) => { ProjectionElem::Index(local) => {
self.visit_local( self.visit_local(
&local, local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location, location,
); );

View File

@ -81,7 +81,7 @@ where
// deinitialized, although clearly it is only partially deinitialized. This analysis is not // deinitialized, although clearly it is only partially deinitialized. This analysis is not
// actually used anywhere at the moment, so this is not critical, but this does need to be fixed // actually used anywhere at the moment, so this is not critical, but this does need to be fixed
// before it starts being used again. // before it starts being used again.
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, NonUseContext}; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, NonUseContext};
match context { match context {
// These are handled specially in `call_return_effect` and `yield_resume_effect`. // These are handled specially in `call_return_effect` and `yield_resume_effect`.

View File

@ -111,7 +111,7 @@ where
} }
} }
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
// Because we do not call `super_place` above, `visit_local` is only called for locals that // Because we do not call `super_place` above, `visit_local` is only called for locals that
// do not appear as part of a `Place` in the MIR. This handles cases like the implicit use // do not appear as part of a `Place` in the MIR. This handles cases like the implicit use
// of the return place in a `Return` terminator or the index in an `Index` projection. // of the return place in a `Return` terminator or the index in an `Index` projection.

View File

@ -288,12 +288,12 @@ impl<'a, 'mir, 'tcx, T> Visitor<'tcx> for MoveVisitor<'a, 'mir, 'tcx, T>
where where
T: GenKill<Local>, T: GenKill<Local>,
{ {
fn visit_local(&mut self, local: &Local, context: PlaceContext, loc: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context { if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context {
let mut borrowed_locals = self.borrowed_locals.borrow_mut(); let mut borrowed_locals = self.borrowed_locals.borrow_mut();
borrowed_locals.seek_before_primary_effect(loc); borrowed_locals.seek_before_primary_effect(loc);
if !borrowed_locals.contains(*local) { if !borrowed_locals.contains(local) {
self.trans.kill(*local); self.trans.kill(local);
} }
} }
} }

View File

@ -88,12 +88,12 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta
} }
impl Visitor<'_> for LocalUseVisitor { impl Visitor<'_> for LocalUseVisitor {
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
if context.is_mutating_use() { if context.is_mutating_use() {
self.local_mutating_uses[*local] = self.local_mutating_uses[*local].saturating_add(1); self.local_mutating_uses[local] = self.local_mutating_uses[local].saturating_add(1);
if context.is_place_assignment() { if context.is_place_assignment() {
self.local_assignment_locations[*local] = Some(location); self.local_assignment_locations[local] = Some(location);
} }
} }
} }

View File

@ -882,7 +882,7 @@ impl CanConstProp {
} }
impl Visitor<'_> for CanConstProp { impl Visitor<'_> for CanConstProp {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
use rustc_middle::mir::visit::PlaceContext::*; use rustc_middle::mir::visit::PlaceContext::*;
match context { match context {
// Projections are fine, because `&mut foo.x` will be caught by // Projections are fine, because `&mut foo.x` will be caught by

View File

@ -773,7 +773,7 @@ impl CanConstProp {
} }
impl Visitor<'_> for CanConstProp { impl Visitor<'_> for CanConstProp {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
use rustc_middle::mir::visit::PlaceContext::*; use rustc_middle::mir::visit::PlaceContext::*;
match context { match context {
// Projections are fine, because `&mut foo.x` will be caught by // Projections are fine, because `&mut foo.x` will be caught by

View File

@ -219,7 +219,7 @@ impl IsReturnPlaceRead {
} }
impl<'tcx> Visitor<'tcx> for IsReturnPlaceRead { impl<'tcx> Visitor<'tcx> for IsReturnPlaceRead {
fn visit_local(&mut self, &l: &Local, ctxt: PlaceContext, _: Location) { fn visit_local(&mut self, l: Local, ctxt: PlaceContext, _: Location) {
if l == mir::RETURN_PLACE && ctxt.is_use() && !ctxt.is_place_assignment() { if l == mir::RETURN_PLACE && ctxt.is_use() && !ctxt.is_place_assignment() {
self.0 = true; self.0 = true;
} }

View File

@ -509,12 +509,12 @@ impl<'tcx> Visitor<'tcx> for UsedLocals {
} }
} }
fn visit_local(&mut self, local: &Local, _ctx: PlaceContext, _location: Location) { fn visit_local(&mut self, local: Local, _ctx: PlaceContext, _location: Location) {
if self.increment { if self.increment {
self.use_count[*local] += 1; self.use_count[local] += 1;
} else { } else {
assert_ne!(self.use_count[*local], 0); assert_ne!(self.use_count[local], 0);
self.use_count[*local] -= 1; self.use_count[local] -= 1;
} }
} }
} }

View File

@ -462,14 +462,14 @@ impl LocalUseCounter {
} }
impl Visitor<'_> for LocalUseCounter { impl Visitor<'_> for LocalUseCounter {
fn visit_local(&mut self, local: &Local, context: PlaceContext, _location: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, _location: Location) {
if context.is_storage_marker() if context.is_storage_marker()
|| context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) || context == PlaceContext::NonUse(NonUseContext::VarDebugInfo)
{ {
return; return;
} }
self.local_uses[*local] += 1; self.local_uses[local] += 1;
} }
} }

View File

@ -928,7 +928,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
fn visit_local( fn visit_local(
&mut self, &mut self,
_place_local: &Local, _place_local: Local,
_context: mir::visit::PlaceContext, _context: mir::visit::PlaceContext,
_location: Location, _location: Location,
) { ) {