Skip to content

Commit b66eb69

Browse files
committed
Refactored verbose print into a function
Also handle Tuple and Array separately, which was not explicitly checked. Fixes #79799.
1 parent 602899c commit b66eb69

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

compiler/rustc_mir/src/util/pretty.rs

+33-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use rustc_middle::mir::interpret::{
1717
};
1818
use rustc_middle::mir::visit::Visitor;
1919
use rustc_middle::mir::*;
20-
use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
20+
use rustc_middle::ty::subst::GenericArgKind;
21+
use rustc_middle::ty::{self, TyCtxt, TyS, TypeFoldable, TypeVisitor};
2122
use rustc_target::abi::Size;
2223
use std::ops::ControlFlow;
2324

@@ -408,6 +409,33 @@ impl ExtraComments<'tcx> {
408409
}
409410
}
410411

412+
fn use_verbose(ty: &&TyS<'tcx>) -> bool {
413+
match ty.kind() {
414+
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false,
415+
// Unit type
416+
ty::Tuple(g_args) if g_args.is_empty() => false,
417+
ty::Tuple(g_args) => {
418+
// could have used `try_fold` here but it seems a bit silly that
419+
// the accumulator is useless
420+
let mut should_be_verbose = false;
421+
for g_arg in g_args.iter() {
422+
if match g_arg.unpack() {
423+
GenericArgKind::Type(ty) => use_verbose(&ty),
424+
GenericArgKind::Const(ty::Const { ty, val: _ }) => use_verbose(ty),
425+
_ => false,
426+
} {
427+
should_be_verbose = true;
428+
break;
429+
}
430+
}
431+
should_be_verbose
432+
}
433+
ty::Array(ty, _) => use_verbose(ty),
434+
ty::FnDef(..) => false,
435+
_ => true,
436+
}
437+
}
438+
411439
impl Visitor<'tcx> for ExtraComments<'tcx> {
412440
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
413441
self.super_constant(constant, location);
@@ -430,16 +458,10 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
430458
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) {
431459
self.super_const(constant);
432460
let ty::Const { ty, val, .. } = constant;
433-
match ty.kind() {
434-
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => {}
435-
// Unit type
436-
ty::Tuple(tys) if tys.is_empty() => {}
437-
ty::FnDef(..) => {}
438-
_ => {
439-
self.push("ty::Const");
440-
self.push(&format!("+ ty: {:?}", ty));
441-
self.push(&format!("+ val: {:?}", val));
442-
}
461+
if use_verbose(ty) {
462+
self.push("ty::Const");
463+
self.push(&format!("+ ty: {:?}", ty));
464+
self.push(&format!("+ val: {:?}", val));
443465
}
444466
}
445467

0 commit comments

Comments
 (0)