Skip to content

Commit 90690da

Browse files
authored
Rollup merge of #91638 - scottmcm:less-inband-2-of-28, r=petrochenkov
Remove `in_band_lifetimes` from `rustc_mir_transform` Like #91580, this was inspired by the conversation in #44524 about possibly removing the feature from the compiler. This crate is a heavy `'tcx` user, so is a nice case study. r? ``@petrochenkov`` Three 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>) { ``` A spurious name, since there's no single-use-lifetime warning: ```diff -pub fn run_passes(tcx: TyCtxt<'tcx>, body: &'mir mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>]) { +pub fn run_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>]) { ```
2 parents 4a76541 + a124924 commit 90690da

35 files changed

+117
-119
lines changed

compiler/rustc_mir_transform/src/add_retag.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn is_stable(place: PlaceRef<'_>) -> bool {
3434
}
3535

3636
/// Determine whether this type may be a reference (or box), and thus needs retagging.
37-
fn may_be_reference(ty: Ty<'tcx>) -> bool {
37+
fn may_be_reference(ty: Ty<'_>) -> bool {
3838
match ty.kind() {
3939
// Primitive types that are not references
4040
ty::Bool

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ConstMutationChecker<'a, 'tcx> {
2323
target_local: Option<Local>,
2424
}
2525

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

98-
impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
98+
impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
9999
fn visit_statement(&mut self, stmt: &Statement<'tcx>, loc: Location) {
100100
if let StatementKind::Assign(box (lhs, _)) = &stmt.kind {
101101
// Check for assignment to fields of a constant

compiler/rustc_mir_transform/src/check_packed_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn builtin_derive_def_id(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
6666
}
6767
}
6868

69-
impl<'a, 'tcx> Visitor<'tcx> for PackedRefChecker<'a, 'tcx> {
69+
impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
7070
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
7171
// Make sure we know where in the MIR we are.
7272
self.source_info = terminator.source_info;

compiler/rustc_mir_transform/src/check_unsafety.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
4646
}
4747
}
4848

49-
impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
49+
impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
5050
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
5151
self.source_info = terminator.source_info;
5252
match terminator.kind {
@@ -244,7 +244,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
244244
}
245245
}
246246

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

400-
impl<'a, 'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
400+
impl<'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'_> {
401401
type Map = intravisit::ErasedMap<'tcx>;
402402

403403
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {

compiler/rustc_mir_transform/src/const_debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta
8989
eligable_locals
9090
}
9191

92-
impl<'tcx> Visitor<'tcx> for LocalUseVisitor {
92+
impl Visitor<'_> for LocalUseVisitor {
9393
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) {
9494
if context.is_mutating_use() {
9595
self.local_mutating_uses[*local] = self.local_mutating_uses[*local].saturating_add(1);

compiler/rustc_mir_transform/src/const_goto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
5454
}
5555
}
5656

57-
impl<'a, 'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'a, 'tcx> {
57+
impl<'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'_, 'tcx> {
5858
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
5959
let _: Option<_> = try {
6060
let target = terminator.kind.as_goto()?;

compiler/rustc_mir_transform/src/const_prop.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct ConstPropMachine<'mir, 'tcx> {
171171
can_const_prop: IndexVec<Local, ConstPropMode>,
172172
}
173173

174-
impl<'mir, 'tcx> ConstPropMachine<'mir, 'tcx> {
174+
impl ConstPropMachine<'_, '_> {
175175
fn new(
176176
only_propagate_inside_block_locals: BitSet<Local>,
177177
can_const_prop: IndexVec<Local, ConstPropMode>,
@@ -308,14 +308,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
308308
}
309309

310310
#[inline(always)]
311-
fn stack(
311+
fn stack<'a>(
312312
ecx: &'a InterpCx<'mir, 'tcx, Self>,
313313
) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
314314
&ecx.machine.stack
315315
}
316316

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

339-
impl<'mir, 'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'mir, 'tcx> {
339+
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {
340340
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
341341

342342
#[inline]
@@ -345,21 +345,21 @@ impl<'mir, 'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'mir, 'tcx> {
345345
}
346346
}
347347

348-
impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> {
348+
impl HasDataLayout for ConstPropagator<'_, '_> {
349349
#[inline]
350350
fn data_layout(&self) -> &TargetDataLayout {
351351
&self.tcx.data_layout
352352
}
353353
}
354354

355-
impl<'mir, 'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> {
355+
impl<'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'_, 'tcx> {
356356
#[inline]
357357
fn tcx(&self) -> TyCtxt<'tcx> {
358358
self.tcx
359359
}
360360
}
361361

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

972972
impl CanConstProp {
973973
/// Returns true if `local` can be propagated
974-
fn check(
974+
fn check<'tcx>(
975975
tcx: TyCtxt<'tcx>,
976976
param_env: ParamEnv<'tcx>,
977977
body: &Body<'tcx>,
@@ -1019,7 +1019,7 @@ impl CanConstProp {
10191019
}
10201020
}
10211021

1022-
impl<'tcx> Visitor<'tcx> for CanConstProp {
1022+
impl Visitor<'_> for CanConstProp {
10231023
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
10241024
use rustc_middle::mir::visit::PlaceContext::*;
10251025
match context {
@@ -1079,7 +1079,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
10791079
}
10801080
}
10811081

1082-
impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
1082+
impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
10831083
fn tcx(&self) -> TyCtxt<'tcx> {
10841084
self.tcx
10851085
}

compiler/rustc_mir_transform/src/coverage/debug.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl UsedExpressions {
629629
}
630630

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

653653
/// Converts the computed `BasicCoverageBlockData`s into `SpanViewable`s.
654-
fn span_viewables(
654+
fn span_viewables<'tcx>(
655655
tcx: TyCtxt<'tcx>,
656656
mir_body: &mir::Body<'tcx>,
657657
basic_coverage_blocks: &CoverageGraph,
@@ -670,7 +670,7 @@ fn span_viewables(
670670
}
671671

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

753-
fn bcb_to_string_sections(
753+
fn bcb_to_string_sections<'tcx>(
754754
tcx: TyCtxt<'tcx>,
755755
mir_body: &mir::Body<'tcx>,
756756
debug_counters: &DebugCounters,
@@ -817,7 +817,7 @@ fn bcb_to_string_sections(
817817

818818
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
819819
/// values it might hold.
820-
pub(super) fn term_type(kind: &TerminatorKind<'tcx>) -> &'static str {
820+
pub(super) fn term_type(kind: &TerminatorKind<'_>) -> &'static str {
821821
match kind {
822822
TerminatorKind::Goto { .. } => "Goto",
823823
TerminatorKind::SwitchInt { .. } => "SwitchInt",

compiler/rustc_mir_transform/src/coverage/graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(super) struct CoverageGraph {
2727
}
2828

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

3333
// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
@@ -74,7 +74,7 @@ impl CoverageGraph {
7474
}
7575

7676
fn compute_basic_coverage_blocks(
77-
mir_body: &mir::Body<'tcx>,
77+
mir_body: &mir::Body<'_>,
7878
) -> (
7979
IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
8080
IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
@@ -267,7 +267,7 @@ impl graph::WithSuccessors for CoverageGraph {
267267
}
268268
}
269269

270-
impl graph::GraphPredecessors<'graph> for CoverageGraph {
270+
impl<'graph> graph::GraphPredecessors<'graph> for CoverageGraph {
271271
type Item = BasicCoverageBlock;
272272
type Iter = std::iter::Copied<std::slice::Iter<'graph, BasicCoverageBlock>>;
273273
}

compiler/rustc_mir_transform/src/coverage/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
443443
}
444444

445445
fn inject_edge_counter_basic_block(
446-
mir_body: &mut mir::Body<'tcx>,
446+
mir_body: &mut mir::Body<'_>,
447447
from_bb: BasicBlock,
448448
to_bb: BasicBlock,
449449
) -> BasicBlock {
@@ -466,7 +466,7 @@ fn inject_edge_counter_basic_block(
466466
}
467467

468468
fn inject_statement(
469-
mir_body: &mut mir::Body<'tcx>,
469+
mir_body: &mut mir::Body<'_>,
470470
counter_kind: CoverageKind,
471471
bb: BasicBlock,
472472
some_code_region: Option<CodeRegion>,
@@ -488,7 +488,7 @@ fn inject_statement(
488488
}
489489

490490
// Non-code expressions are injected into the coverage map, without generating executable code.
491-
fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: CoverageKind) {
491+
fn inject_intermediate_expression(mir_body: &mut mir::Body<'_>, expression: CoverageKind) {
492492
debug_assert!(matches!(expression, CoverageKind::Expression { .. }));
493493
debug!(" injecting non-code expression {:?}", expression);
494494
let inject_in_bb = mir::START_BLOCK;

compiler/rustc_mir_transform/src/coverage/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, instance_def: ty::InstanceDef<'tcx>) ->
137137
coverage_visitor.info
138138
}
139139

140-
fn covered_file_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Symbol> {
140+
fn covered_file_name(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
141141
if tcx.is_mir_available(def_id) {
142142
let body = mir_body(tcx, def_id);
143143
for bb_data in body.basic_blocks().iter() {

compiler/rustc_mir_transform/src/coverage/spans.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) enum CoverageStatement {
2121
}
2222

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

8888
pub fn for_statement(
89-
statement: &Statement<'tcx>,
89+
statement: &Statement<'_>,
9090
span: Span,
9191
expn_span: Span,
9292
bcb: BasicCoverageBlock,
@@ -151,18 +151,18 @@ impl CoverageSpan {
151151
self.bcb == other.bcb
152152
}
153153

154-
pub fn format(&self, tcx: TyCtxt<'tcx>, mir_body: &'a mir::Body<'tcx>) -> String {
154+
pub fn format<'tcx>(&self, tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> String {
155155
format!(
156156
"{}\n {}",
157157
source_range_no_file(tcx, &self.span),
158158
self.format_coverage_statements(tcx, mir_body).replace("\n", "\n "),
159159
)
160160
}
161161

162-
pub fn format_coverage_statements(
162+
pub fn format_coverage_statements<'tcx>(
163163
&self,
164164
tcx: TyCtxt<'tcx>,
165-
mir_body: &'a mir::Body<'tcx>,
165+
mir_body: &mir::Body<'tcx>,
166166
) -> String {
167167
let mut sorted_coverage_statements = self.coverage_statements.clone();
168168
sorted_coverage_statements.sort_unstable_by_key(|covstmt| match *covstmt {
@@ -803,7 +803,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
803803

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

848848
/// If the MIR `Terminator` has a span contributive to computing coverage spans,
849849
/// return it; otherwise return `None`.
850-
pub(super) fn filtered_terminator_span(terminator: &'a Terminator<'tcx>) -> Option<Span> {
850+
pub(super) fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
851851
match terminator.kind {
852852
// These terminators have spans that don't positively contribute to computing a reasonable
853853
// span of actually executed source code. (For example, SwitchInt terminators extracted from

compiler/rustc_mir_transform/src/coverage/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'tcx> MockBlocks<'tcx> {
180180
}
181181
}
182182

183-
fn debug_basic_blocks(mir_body: &Body<'tcx>) -> String {
183+
fn debug_basic_blocks<'tcx>(mir_body: &Body<'tcx>) -> String {
184184
format!(
185185
"{:?}",
186186
mir_body
@@ -273,7 +273,7 @@ fn print_coverage_graphviz(
273273
}
274274

275275
/// Create a mock `Body` with a simple flow.
276-
fn goto_switchint() -> Body<'a> {
276+
fn goto_switchint<'a>() -> Body<'a> {
277277
let mut blocks = MockBlocks::new();
278278
let start = blocks.call(None);
279279
let goto = blocks.goto(Some(start));
@@ -363,7 +363,7 @@ fn test_covgraph_goto_switchint() {
363363
}
364364

365365
/// Create a mock `Body` with a loop.
366-
fn switchint_then_loop_else_return() -> Body<'a> {
366+
fn switchint_then_loop_else_return<'a>() -> Body<'a> {
367367
let mut blocks = MockBlocks::new();
368368
let start = blocks.call(None);
369369
let switchint = blocks.switchint(Some(start));
@@ -449,7 +449,7 @@ fn test_covgraph_switchint_then_loop_else_return() {
449449
}
450450

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

0 commit comments

Comments
 (0)