Skip to content

Commit 20df0e9

Browse files
committed
Add -Z span_free_rvalues.
This is solely a hack to make comparing test output plausible; it makes closures print as [closure@node_id] instead of [closure@span-with-host-path] in debug printouts.
1 parent 54eeef1 commit 20df0e9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/librustc/mir/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
12241224

12251225
AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
12261226
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
1227-
let name = format!("[closure@{:?}]", tcx.hir.span(node_id));
1227+
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
1228+
format!("[closure@{:?}]", node_id)
1229+
} else {
1230+
format!("[closure@{:?}]", tcx.hir.span(node_id))
1231+
};
12281232
let mut struct_fmt = fmt.debug_struct(&name);
12291233

12301234
tcx.with_freevars(node_id, |freevars| {

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
893893
DB_OPTIONS, db_type_desc, dbsetters,
894894
verbose: bool = (false, parse_bool, [UNTRACKED],
895895
"in general, enable more debug printouts"),
896+
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
897+
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
896898
time_passes: bool = (false, parse_bool, [UNTRACKED],
897899
"measure time of each rustc pass"),
898900
count_llvm_insns: bool = (false, parse_bool,

src/librustc/util/ppaux.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,11 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
789789
write!(f, "[closure")?;
790790

791791
if let Some(node_id) = tcx.hir.as_local_node_id(did) {
792-
write!(f, "@{:?}", tcx.hir.span(node_id))?;
792+
if tcx.sess.opts.debugging_opts.span_free_formats {
793+
write!(f, "@{:?}", node_id)?;
794+
} else {
795+
write!(f, "@{:?}", tcx.hir.span(node_id))?;
796+
}
793797
let mut sep = " ";
794798
tcx.with_freevars(node_id, |freevars| {
795799
for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) {

0 commit comments

Comments
 (0)