Skip to content

Commit 762f984

Browse files
authored
Unrolled build for rust-lang#137266
Rollup merge of rust-lang#137266 - nnethercote:mir-visitor-tweaks, r=compiler-errors MIR visitor tweaks Some minor improvements I found while looking at this code. r? `@tmandry`
2 parents 4e1356b + 5bb37ce commit 762f984

File tree

3 files changed

+160
-189
lines changed

3 files changed

+160
-189
lines changed

compiler/rustc_borrowck/src/diagnostics/find_use.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::VecDeque;
22

33
use rustc_data_structures::fx::FxIndexSet;
4-
use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor};
4+
use rustc_middle::mir::visit::{PlaceContext, Visitor};
55
use rustc_middle::mir::{self, Body, Local, Location};
66
use rustc_middle::ty::{RegionVid, TyCtxt};
77

@@ -45,7 +45,22 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
4545

4646
let block_data = &self.body[p.block];
4747

48-
match self.def_use(p, block_data.visitable(p.statement_index)) {
48+
let mut visitor = DefUseVisitor {
49+
body: self.body,
50+
tcx: self.tcx,
51+
region_vid: self.region_vid,
52+
def_use_result: None,
53+
};
54+
55+
let is_statement = p.statement_index < block_data.statements.len();
56+
57+
if is_statement {
58+
visitor.visit_statement(&block_data.statements[p.statement_index], p);
59+
} else {
60+
visitor.visit_terminator(block_data.terminator.as_ref().unwrap(), p);
61+
}
62+
63+
match visitor.def_use_result {
4964
Some(DefUseResult::Def) => {}
5065

5166
Some(DefUseResult::UseLive { local }) => {
@@ -57,7 +72,7 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
5772
}
5873

5974
None => {
60-
if p.statement_index < block_data.statements.len() {
75+
if is_statement {
6176
queue.push_back(p.successor_within_block());
6277
} else {
6378
queue.extend(
@@ -77,19 +92,6 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
7792

7893
None
7994
}
80-
81-
fn def_use(&self, location: Location, thing: &dyn MirVisitable<'tcx>) -> Option<DefUseResult> {
82-
let mut visitor = DefUseVisitor {
83-
body: self.body,
84-
tcx: self.tcx,
85-
region_vid: self.region_vid,
86-
def_use_result: None,
87-
};
88-
89-
thing.apply(location, &mut visitor);
90-
91-
visitor.def_use_result
92-
}
9395
}
9496

9597
struct DefUseVisitor<'a, 'tcx> {

compiler/rustc_middle/src/mir/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use tracing::{debug, trace};
3232
pub use self::query::*;
3333
use self::visit::TyContext;
3434
use crate::mir::interpret::{AllocRange, Scalar};
35-
use crate::mir::visit::MirVisitable;
3635
use crate::ty::codec::{TyDecoder, TyEncoder};
3736
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
3837
use crate::ty::visit::TypeVisitableExt;
@@ -1364,10 +1363,6 @@ impl<'tcx> BasicBlockData<'tcx> {
13641363
self.terminator.as_mut().expect("invalid terminator state")
13651364
}
13661365

1367-
pub fn visitable(&self, index: usize) -> &dyn MirVisitable<'tcx> {
1368-
if index < self.statements.len() { &self.statements[index] } else { &self.terminator }
1369-
}
1370-
13711366
/// Does the block have no statements and an unreachable terminator?
13721367
#[inline]
13731368
pub fn is_empty_unreachable(&self) -> bool {

0 commit comments

Comments
 (0)