Skip to content

Commit 670cf11

Browse files
varkoryodaldevoid
andcommitted
Clean up push_const_name
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent c619754 commit 670cf11

File tree

1 file changed

+26
-14
lines changed
  • src/librustc_mir/monomorphize

1 file changed

+26
-14
lines changed

src/librustc_mir/monomorphize/item.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc::hir;
33
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
44
use rustc::mir::interpret::ConstValue;
55
use rustc::session::config::OptLevel;
6-
use rustc::ty::{self, Ty, TyCtxt, Const, ClosureSubsts, GeneratorSubsts, ParamConst};
6+
use rustc::ty::{self, Ty, TyCtxt, Const, ClosureSubsts, GeneratorSubsts};
77
use rustc::ty::subst::{SubstsRef, InternalSubsts};
88
use syntax::ast;
99
use syntax::attr::InlineAttr;
@@ -240,11 +240,11 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
240240
}
241241

242242
// Pushes the type name of the specified type to the provided string.
243-
// If 'debug' is true, printing normally unprintable types is allowed
244-
// (e.g. ty::GeneratorWitness). This parameter should only be set when
245-
// this method is being used for logging purposes (e.g. with debug! or info!)
246-
// When being used for codegen purposes, 'debug' should be set to 'false'
247-
// in order to catch unexpected types that should never end up in a type name
243+
// If `debug` is true, printing normally unprintable types is allowed
244+
// (e.g. `ty::GeneratorWitness`). This parameter should only be set when
245+
// this method is being used for logging purposes (e.g. with `debug!` or `info!`)
246+
// When being used for codegen purposes, `debug` should be set to `false`
247+
// in order to catch unexpected types that should never end up in a type name.
248248
pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String, debug: bool) {
249249
match t.sty {
250250
ty::Bool => output.push_str("bool"),
@@ -387,22 +387,34 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
387387
if debug {
388388
output.push_str(&format!("`{:?}`", t));
389389
} else {
390-
bug!("DefPathBasedNames: Trying to create type name for \
391-
unexpected type: {:?}", t);
390+
bug!(
391+
"DefPathBasedNames: trying to create type name for unexpected type: {:?}",
392+
t,
393+
);
392394
}
393395
}
394396
}
395397
}
396398

397-
// FIXME(const_generics): handle debug printing.
399+
// Pushes the the name of the specified const to the provided string.
400+
// If `debug` is true, usually-unprintable consts (such as `Infer`) will be printed,
401+
// as well as the unprintable types of constants (see `push_type_name` for more details).
398402
pub fn push_const_name(&self, c: &Const<'tcx>, output: &mut String, debug: bool) {
399403
match c.val {
400-
ConstValue::Infer(..) | ConstValue::Placeholder(_) => output.push_str("_"),
401-
ConstValue::Param(ParamConst { name, .. }) => {
402-
write!(output, "{}", name).unwrap();
404+
ConstValue::Scalar(..) | ConstValue::Slice(..) | ConstValue::ByRef(..) => {
405+
// FIXME(const_generics): we could probably do a better job here.
406+
write!(output, "{:?}", c).unwrap()
407+
}
408+
_ => {
409+
if debug {
410+
write!(output, "{:?}", c).unwrap()
411+
} else {
412+
bug!(
413+
"DefPathBasedNames: trying to create const name for unexpected const: {:?}",
414+
c,
415+
);
416+
}
403417
}
404-
ConstValue::Unevaluated(..) => output.push_str("_: _"),
405-
_ => write!(output, "{:?}", c).unwrap(),
406418
}
407419
output.push_str(": ");
408420
self.push_type_name(c.ty, output, debug);

0 commit comments

Comments
 (0)