X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_middle%2Fsrc%2Fmir%2Fpretty.rs;h=f2ad591071114bb043961e8c8679a4211447c2e2;hb=976348603485b216b0d5314eca674a2b24df4c73;hp=8e1b887f87da75695eb5c41a6156250db02171e8;hpb=214b2a126bc6654bf60108aea2e8dce94b096b4b;p=rust.git diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 8e1b887f87d..3d9ac90a36e 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::MirSource; use rustc_middle::mir::*; -use rustc_middle::ty::{self, TyCtxt, TyS, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor}; use rustc_target::abi::Size; use std::ops::ControlFlow; @@ -94,10 +94,8 @@ pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) -> None => return false, Some(ref filters) => filters, }; - 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(); @@ -125,10 +123,9 @@ fn dump_matched_mir_node<'tcx, F>( 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, "`")?, @@ -167,8 +164,8 @@ fn dump_matched_mir_node<'tcx, F>( /// Returns the file basename portion (without extension) of a filename path /// where we should dump a MIR representation output files. -fn dump_file_basename( - tcx: TyCtxt<'_>, +fn dump_file_basename<'tcx>( + tcx: TyCtxt<'tcx>, pass_num: Option<&dyn Display>, pass_name: &str, disambiguator: &dyn Display, @@ -251,8 +248,8 @@ fn create_dump_file_with_basename( /// bit of MIR-related data. Used by `mir-dump`, but also by other /// bits of code (e.g., NLL inference) that dump graphviz data or /// other things, and hence takes the extension as an argument. -pub fn create_dump_file( - tcx: TyCtxt<'_>, +pub fn create_dump_file<'tcx>( + tcx: TyCtxt<'tcx>, extension: &str, pass_num: Option<&dyn Display>, pass_name: &str, @@ -419,7 +416,7 @@ struct ExtraComments<'tcx> { comments: Vec, } -impl ExtraComments<'tcx> { +impl<'tcx> ExtraComments<'tcx> { fn push(&mut self, lines: &str) { for line in lines.split('\n') { self.comments.push(line.to_string()); @@ -427,23 +424,23 @@ fn push(&mut self, lines: &str) { } } -fn use_verbose(ty: &&TyS<'tcx>, fn_def: bool) -> bool { - match ty.kind() { +fn use_verbose<'tcx>(ty: Ty<'tcx>, fn_def: bool) -> bool { + match *ty.kind() { ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false, // Unit type ty::Tuple(g_args) if g_args.is_empty() => false, - ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(&g_arg.expect_ty(), fn_def)), + ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(g_arg.expect_ty(), fn_def)), ty::Array(ty, _) => use_verbose(ty, fn_def), ty::FnDef(..) => fn_def, _ => true, } } -impl Visitor<'tcx> for ExtraComments<'tcx> { +impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { self.super_constant(constant, location); let Constant { span, user_ty, literal } = constant; - if use_verbose(&literal.ty(), true) { + if use_verbose(literal.ty(), true) { self.push("mir::Constant"); self.push(&format!( "+ span: {}", @@ -462,9 +459,10 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { } } - fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) { + fn visit_const(&mut self, constant: ty::Const<'tcx>, _: Location) { self.super_const(constant); - let ty::Const { ty, val, .. } = constant; + let ty = constant.ty(); + let val = constant.val(); if use_verbose(ty, false) { self.push("ty::Const"); self.push(&format!("+ ty: {:?}", ty)); @@ -476,8 +474,8 @@ fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) { ty::ConstKind::Unevaluated(uv) => format!( "Unevaluated({}, {:?}, {:?})", self.tcx.def_path_str(uv.def.did), - uv.substs(self.tcx), - uv.promoted + uv.substs, + uv.promoted, ), ty::ConstKind::Value(val) => format!("Value({:?})", val), ty::ConstKind::Error(_) => "Error".to_string(), @@ -683,14 +681,8 @@ fn alloc_ids_from_const(val: ConstValue<'_>) -> impl Iterator + } struct CollectAllocIds(BTreeSet); impl<'tcx> TypeVisitor<'tcx> for CollectAllocIds { - fn tcx_for_anon_const_substs(&self) -> Option> { - // `AllocId`s are only inside of `ConstKind::Value` which - // can't be part of the anon const default substs. - None - } - - fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { - if let ty::ConstKind::Value(val) = c.val { + fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { + if let ty::ConstKind::Value(val) = c.val() { self.0.extend(alloc_ids_from_const(val)); } c.super_visit_with(self) @@ -762,7 +754,7 @@ fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow( +pub fn display_allocation<'a, 'tcx, Tag, Extra>( tcx: TyCtxt<'tcx>, alloc: &'a Allocation, ) -> RenderAllocation<'a, 'tcx, Tag, Extra> { @@ -775,7 +767,9 @@ pub struct RenderAllocation<'a, 'tcx, Tag, Extra> { alloc: &'a Allocation, } -impl std::fmt::Display for RenderAllocation<'a, 'tcx, Tag, Extra> { +impl<'a, 'tcx, Tag: Provenance, Extra> std::fmt::Display + for RenderAllocation<'a, 'tcx, Tag, Extra> +{ fn fmt(&self, w: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let RenderAllocation { tcx, alloc } = *self; write!(w, "size: {}, align: {})", alloc.size().bytes(), alloc.align.bytes())?; @@ -818,7 +812,7 @@ fn write_allocation_newline( /// The `prefix` argument allows callers to add an arbitrary prefix before each line (even if there /// is only one line). Note that your prefix should contain a trailing space as the lines are /// printed directly after it. -fn write_allocation_bytes( +fn write_allocation_bytes<'tcx, Tag: Provenance, Extra>( tcx: TyCtxt<'tcx>, alloc: &Allocation, w: &mut dyn std::fmt::Write, @@ -962,10 +956,10 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn Write) -> io::Res _ => 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, "(")?;