Skip to content

Commit

Permalink
Remove in_band_lifetimes from rustc_mir_transform
Browse files Browse the repository at this point in the history
This one is a heavy `'tcx` user.

Two interesting ones:

This one had the `'tcx` declared on the function, despite the trait taking a `'tcx`:
```diff
-impl Visitor<'_> for UsedLocals {
+impl<'tcx> Visitor<'tcx> for UsedLocals {
     fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
```

This one use in-band for one, and underscore for the other:
```diff
-pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
+pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
```
  • Loading branch information
scottmcm committed Dec 8, 2021
1 parent 0b6f079 commit a124924
Show file tree
Hide file tree
Showing 35 changed files with 117 additions and 119 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/add_retag.rs
Expand Up @@ -34,7 +34,7 @@ fn is_stable(place: PlaceRef<'_>) -> bool {
}

/// Determine whether this type may be a reference (or box), and thus needs retagging.
fn may_be_reference(ty: Ty<'tcx>) -> bool {
fn may_be_reference(ty: Ty<'_>) -> bool {
match ty.kind() {
// Primitive types that are not references
ty::Bool
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/check_const_item_mutation.rs
Expand Up @@ -23,7 +23,7 @@ struct ConstMutationChecker<'a, 'tcx> {
target_local: Option<Local>,
}

impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
impl<'tcx> ConstMutationChecker<'_, 'tcx> {
fn is_const_item(&self, local: Local) -> Option<DefId> {
if let Some(box LocalInfo::ConstRef { def_id }) = self.body.local_decls[local].local_info {
Some(def_id)
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
fn visit_statement(&mut self, stmt: &Statement<'tcx>, loc: Location) {
if let StatementKind::Assign(box (lhs, _)) = &stmt.kind {
// Check for assignment to fields of a constant
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/check_packed_ref.rs
Expand Up @@ -66,7 +66,7 @@ fn builtin_derive_def_id(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
}
}

impl<'a, 'tcx> Visitor<'tcx> for PackedRefChecker<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
// Make sure we know where in the MIR we are.
self.source_info = terminator.source_info;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/check_unsafety.rs
Expand Up @@ -46,7 +46,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
self.source_info = terminator.source_info;
match terminator.kind {
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}
}

impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
impl<'tcx> UnsafetyChecker<'_, 'tcx> {
fn require_unsafe(&mut self, kind: UnsafetyViolationKind, details: UnsafetyViolationDetails) {
// Violations can turn out to be `UnsafeFn` during analysis, but they should not start out as such.
assert_ne!(kind, UnsafetyViolationKind::UnsafeFn);
Expand Down Expand Up @@ -397,7 +397,7 @@ struct UnusedUnsafeVisitor<'a> {
unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>,
}

impl<'a, 'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
impl<'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'_> {
type Map = intravisit::ErasedMap<'tcx>;

fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/const_debuginfo.rs
Expand Up @@ -89,7 +89,7 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta
eligable_locals
}

impl<'tcx> Visitor<'tcx> for LocalUseVisitor {
impl Visitor<'_> for LocalUseVisitor {
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) {
if context.is_mutating_use() {
self.local_mutating_uses[*local] = self.local_mutating_uses[*local].saturating_add(1);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/const_goto.rs
Expand Up @@ -54,7 +54,7 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
}
}

impl<'a, 'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'_, 'tcx> {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
let _: Option<_> = try {
let target = terminator.kind.as_goto()?;
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_mir_transform/src/const_prop.rs
Expand Up @@ -171,7 +171,7 @@ struct ConstPropMachine<'mir, 'tcx> {
can_const_prop: IndexVec<Local, ConstPropMode>,
}

impl<'mir, 'tcx> ConstPropMachine<'mir, 'tcx> {
impl ConstPropMachine<'_, '_> {
fn new(
only_propagate_inside_block_locals: BitSet<Local>,
can_const_prop: IndexVec<Local, ConstPropMode>,
Expand Down Expand Up @@ -308,14 +308,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
}

#[inline(always)]
fn stack(
fn stack<'a>(
ecx: &'a InterpCx<'mir, 'tcx, Self>,
) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
&ecx.machine.stack
}

#[inline(always)]
fn stack_mut(
fn stack_mut<'a>(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> {
&mut ecx.machine.stack
Expand All @@ -336,7 +336,7 @@ struct ConstPropagator<'mir, 'tcx> {
source_info: Option<SourceInfo>,
}

impl<'mir, 'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'mir, 'tcx> {
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;

#[inline]
Expand All @@ -345,21 +345,21 @@ impl<'mir, 'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'mir, 'tcx> {
}
}

impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> {
impl HasDataLayout for ConstPropagator<'_, '_> {
#[inline]
fn data_layout(&self) -> &TargetDataLayout {
&self.tcx.data_layout
}
}

impl<'mir, 'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> {
impl<'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'_, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
}

impl<'mir, 'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'mir, 'tcx> {
impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> {
#[inline]
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
Expand Down Expand Up @@ -971,7 +971,7 @@ struct CanConstProp {

impl CanConstProp {
/// Returns true if `local` can be propagated
fn check(
fn check<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>,
body: &Body<'tcx>,
Expand Down Expand Up @@ -1019,7 +1019,7 @@ impl CanConstProp {
}
}

impl<'tcx> Visitor<'tcx> for CanConstProp {
impl Visitor<'_> for CanConstProp {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
use rustc_middle::mir::visit::PlaceContext::*;
match context {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
}
}

impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Expand Up @@ -629,7 +629,7 @@ impl UsedExpressions {
}

/// Generates the MIR pass `CoverageSpan`-specific spanview dump file.
pub(super) fn dump_coverage_spanview(
pub(super) fn dump_coverage_spanview<'tcx>(
tcx: TyCtxt<'tcx>,
mir_body: &mir::Body<'tcx>,
basic_coverage_blocks: &CoverageGraph,
Expand All @@ -651,7 +651,7 @@ pub(super) fn dump_coverage_spanview(
}

/// Converts the computed `BasicCoverageBlockData`s into `SpanViewable`s.
fn span_viewables(
fn span_viewables<'tcx>(
tcx: TyCtxt<'tcx>,
mir_body: &mir::Body<'tcx>,
basic_coverage_blocks: &CoverageGraph,
Expand All @@ -670,7 +670,7 @@ fn span_viewables(
}

/// Generates the MIR pass coverage-specific graphviz dump file.
pub(super) fn dump_coverage_graphviz(
pub(super) fn dump_coverage_graphviz<'tcx>(
tcx: TyCtxt<'tcx>,
mir_body: &mir::Body<'tcx>,
pass_name: &str,
Expand Down Expand Up @@ -750,7 +750,7 @@ pub(super) fn dump_coverage_graphviz(
.expect("Unexpected error writing BasicCoverageBlock graphviz DOT file");
}

fn bcb_to_string_sections(
fn bcb_to_string_sections<'tcx>(
tcx: TyCtxt<'tcx>,
mir_body: &mir::Body<'tcx>,
debug_counters: &DebugCounters,
Expand Down Expand Up @@ -817,7 +817,7 @@ fn bcb_to_string_sections(

/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
/// values it might hold.
pub(super) fn term_type(kind: &TerminatorKind<'tcx>) -> &'static str {
pub(super) fn term_type(kind: &TerminatorKind<'_>) -> &'static str {
match kind {
TerminatorKind::Goto { .. } => "Goto",
TerminatorKind::SwitchInt { .. } => "SwitchInt",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/coverage/graph.rs
Expand Up @@ -27,7 +27,7 @@ pub(super) struct CoverageGraph {
}

impl CoverageGraph {
pub fn from_mir(mir_body: &mir::Body<'tcx>) -> Self {
pub fn from_mir(mir_body: &mir::Body<'_>) -> Self {
let (bcbs, bb_to_bcb) = Self::compute_basic_coverage_blocks(mir_body);

// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
Expand Down Expand Up @@ -74,7 +74,7 @@ impl CoverageGraph {
}

fn compute_basic_coverage_blocks(
mir_body: &mir::Body<'tcx>,
mir_body: &mir::Body<'_>,
) -> (
IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl graph::WithSuccessors for CoverageGraph {
}
}

impl graph::GraphPredecessors<'graph> for CoverageGraph {
impl<'graph> graph::GraphPredecessors<'graph> for CoverageGraph {
type Item = BasicCoverageBlock;
type Iter = std::iter::Copied<std::slice::Iter<'graph, BasicCoverageBlock>>;
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Expand Up @@ -443,7 +443,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
}

fn inject_edge_counter_basic_block(
mir_body: &mut mir::Body<'tcx>,
mir_body: &mut mir::Body<'_>,
from_bb: BasicBlock,
to_bb: BasicBlock,
) -> BasicBlock {
Expand All @@ -466,7 +466,7 @@ fn inject_edge_counter_basic_block(
}

fn inject_statement(
mir_body: &mut mir::Body<'tcx>,
mir_body: &mut mir::Body<'_>,
counter_kind: CoverageKind,
bb: BasicBlock,
some_code_region: Option<CodeRegion>,
Expand All @@ -488,7 +488,7 @@ fn inject_statement(
}

// Non-code expressions are injected into the coverage map, without generating executable code.
fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: CoverageKind) {
fn inject_intermediate_expression(mir_body: &mut mir::Body<'_>, expression: CoverageKind) {
debug_assert!(matches!(expression, CoverageKind::Expression { .. }));
debug!(" injecting non-code expression {:?}", expression);
let inject_in_bb = mir::START_BLOCK;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/coverage/query.rs
Expand Up @@ -137,7 +137,7 @@ fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, instance_def: ty::InstanceDef<'tcx>) ->
coverage_visitor.info
}

fn covered_file_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Symbol> {
fn covered_file_name(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
if tcx.is_mir_available(def_id) {
let body = mir_body(tcx, def_id);
for bb_data in body.basic_blocks().iter() {
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Expand Up @@ -21,7 +21,7 @@ pub(super) enum CoverageStatement {
}

impl CoverageStatement {
pub fn format(&self, tcx: TyCtxt<'tcx>, mir_body: &'a mir::Body<'tcx>) -> String {
pub fn format<'tcx>(&self, tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> String {
match *self {
Self::Statement(bb, span, stmt_index) => {
let stmt = &mir_body[bb].statements[stmt_index];
Expand Down Expand Up @@ -86,7 +86,7 @@ impl CoverageSpan {
}

pub fn for_statement(
statement: &Statement<'tcx>,
statement: &Statement<'_>,
span: Span,
expn_span: Span,
bcb: BasicCoverageBlock,
Expand Down Expand Up @@ -151,18 +151,18 @@ impl CoverageSpan {
self.bcb == other.bcb
}

pub fn format(&self, tcx: TyCtxt<'tcx>, mir_body: &'a mir::Body<'tcx>) -> String {
pub fn format<'tcx>(&self, tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> String {
format!(
"{}\n {}",
source_range_no_file(tcx, &self.span),
self.format_coverage_statements(tcx, mir_body).replace("\n", "\n "),
)
}

pub fn format_coverage_statements(
pub fn format_coverage_statements<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
mir_body: &'a mir::Body<'tcx>,
mir_body: &mir::Body<'tcx>,
) -> String {
let mut sorted_coverage_statements = self.coverage_statements.clone();
sorted_coverage_statements.sort_unstable_by_key(|covstmt| match *covstmt {
Expand Down Expand Up @@ -803,7 +803,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {

/// If the MIR `Statement` has a span contributive to computing coverage spans,
/// return it; otherwise return `None`.
pub(super) fn filtered_statement_span(statement: &'a Statement<'tcx>) -> Option<Span> {
pub(super) fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
match statement.kind {
// These statements have spans that are often outside the scope of the executed source code
// for their parent `BasicBlock`.
Expand Down Expand Up @@ -847,7 +847,7 @@ pub(super) fn filtered_statement_span(statement: &'a Statement<'tcx>) -> Option<

/// If the MIR `Terminator` has a span contributive to computing coverage spans,
/// return it; otherwise return `None`.
pub(super) fn filtered_terminator_span(terminator: &'a Terminator<'tcx>) -> Option<Span> {
pub(super) fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
match terminator.kind {
// These terminators have spans that don't positively contribute to computing a reasonable
// span of actually executed source code. (For example, SwitchInt terminators extracted from
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/coverage/tests.rs
Expand Up @@ -180,7 +180,7 @@ impl<'tcx> MockBlocks<'tcx> {
}
}

fn debug_basic_blocks(mir_body: &Body<'tcx>) -> String {
fn debug_basic_blocks<'tcx>(mir_body: &Body<'tcx>) -> String {
format!(
"{:?}",
mir_body
Expand Down Expand Up @@ -273,7 +273,7 @@ fn print_coverage_graphviz(
}

/// Create a mock `Body` with a simple flow.
fn goto_switchint() -> Body<'a> {
fn goto_switchint<'a>() -> Body<'a> {
let mut blocks = MockBlocks::new();
let start = blocks.call(None);
let goto = blocks.goto(Some(start));
Expand Down Expand Up @@ -363,7 +363,7 @@ fn test_covgraph_goto_switchint() {
}

/// Create a mock `Body` with a loop.
fn switchint_then_loop_else_return() -> Body<'a> {
fn switchint_then_loop_else_return<'a>() -> Body<'a> {
let mut blocks = MockBlocks::new();
let start = blocks.call(None);
let switchint = blocks.switchint(Some(start));
Expand Down Expand Up @@ -449,7 +449,7 @@ fn test_covgraph_switchint_then_loop_else_return() {
}

/// Create a mock `Body` with nested loops.
fn switchint_loop_then_inner_loop_else_break() -> Body<'a> {
fn switchint_loop_then_inner_loop_else_break<'a>() -> Body<'a> {
let mut blocks = MockBlocks::new();
let start = blocks.call(None);
let switchint = blocks.switchint(Some(start));
Expand Down

0 comments on commit a124924

Please sign in to comment.