@@ -3,7 +3,7 @@ use rustc::hir;
3
3
use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
4
4
use rustc:: mir:: interpret:: ConstValue ;
5
5
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 } ;
7
7
use rustc:: ty:: subst:: { SubstsRef , InternalSubsts } ;
8
8
use syntax:: ast;
9
9
use syntax:: attr:: InlineAttr ;
@@ -240,11 +240,11 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
240
240
}
241
241
242
242
// 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.
248
248
pub fn push_type_name ( & self , t : Ty < ' tcx > , output : & mut String , debug : bool ) {
249
249
match t. sty {
250
250
ty:: Bool => output. push_str ( "bool" ) ,
@@ -387,22 +387,34 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
387
387
if debug {
388
388
output. push_str ( & format ! ( "`{:?}`" , t) ) ;
389
389
} 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
+ ) ;
392
394
}
393
395
}
394
396
}
395
397
}
396
398
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).
398
402
pub fn push_const_name ( & self , c : & Const < ' tcx > , output : & mut String , debug : bool ) {
399
403
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
+ }
403
417
}
404
- ConstValue :: Unevaluated ( ..) => output. push_str ( "_: _" ) ,
405
- _ => write ! ( output, "{:?}" , c) . unwrap ( ) ,
406
418
}
407
419
output. push_str ( ": " ) ;
408
420
self . push_type_name ( c. ty , output, debug) ;
0 commit comments