use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::MirSource;
use rustc_middle::mir::*;
-use rustc_middle::ty::{self, TyCtxt};
+use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
use rustc_target::abi::Size;
+use std::ops::ControlFlow;
const INDENT: &str = " ";
/// Alignment for lining up comments following MIR statements
}
pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) -> bool {
- let filters = match tcx.sess.opts.debugging_opts.dump_mir {
- None => return false,
- Some(ref filters) => filters,
+ let Some(ref filters) = tcx.sess.opts.debugging_opts.dump_mir else {
+ return false;
};
- let node_path = ty::print::with_forced_impl_filename_line(|| {
- // see notes on #41697 below
- tcx.def_path_str(def_id)
- });
+ // see notes on #41697 below
+ let node_path = ty::print::with_forced_impl_filename_line!(tcx.def_path_str(def_id));
filters.split('|').any(|or_filter| {
or_filter.split('&').all(|and_filter| {
let and_filter_trimmed = and_filter.trim();
let _: io::Result<()> = try {
let mut file =
create_dump_file(tcx, "mir", pass_num, pass_name, disambiguator, body.source)?;
- let def_path = ty::print::with_forced_impl_filename_line(|| {
- // see notes on #41697 above
- tcx.def_path_str(body.source.def_id())
- });
+ // see notes on #41697 above
+ let def_path =
+ ty::print::with_forced_impl_filename_line!(tcx.def_path_str(body.source.def_id()));
write!(file, "// MIR for `{}", def_path)?;
match body.source.promoted {
None => write!(file, "`")?,
)?;
}
- let children = match scope_tree.get(&parent) {
- Some(children) => children,
- None => return Ok(()),
+ let Some(children) = scope_tree.get(&parent) else {
+ return Ok(());
};
for &child in children {
fn alloc_ids_from_alloc(alloc: &Allocation) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
alloc.relocations().values().map(|id| *id)
}
-
fn alloc_ids_from_const(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {
match val {
ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _size)) => {
}
}
}
-
struct CollectAllocIds(BTreeSet<AllocId>);
-
- impl<'tcx> Visitor<'tcx> for CollectAllocIds {
- fn visit_const(&mut self, c: ty::Const<'tcx>, _loc: Location) {
+ impl<'tcx> TypeVisitor<'tcx> for CollectAllocIds {
+ fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::ConstKind::Value(val) = c.val() {
self.0.extend(alloc_ids_from_const(val));
}
- }
-
- fn visit_constant(&mut self, c: &Constant<'tcx>, loc: Location) {
- match c.literal {
- ConstantKind::Ty(c) => self.visit_const(c, loc),
- ConstantKind::Val(val, _) => {
- self.0.extend(alloc_ids_from_const(val));
- }
- }
+ c.super_visit_with(self)
}
}
-
let mut visitor = CollectAllocIds(Default::default());
- visitor.visit_body(body);
-
+ body.visit_with(&mut visitor);
// `seen` contains all seen allocations, including the ones we have *not* printed yet.
// The protocol is to first `insert` into `seen`, and only if that returns `true`
// then push to `todo`.
_ => bug!("Unexpected def kind {:?}", kind),
}
- ty::print::with_forced_impl_filename_line(|| {
+ ty::print::with_forced_impl_filename_line! {
// see notes on #41697 elsewhere
- write!(w, "{}", tcx.def_path_str(def_id))
- })?;
+ write!(w, "{}", tcx.def_path_str(def_id))?
+ }
if body.source.promoted.is_none() && is_function {
write!(w, "(")?;