1
1
use crate :: monomorphize:: Instance ;
2
2
use rustc:: hir;
3
3
use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
4
+ use rustc:: mir:: interpret:: ConstValue ;
4
5
use rustc:: session:: config:: OptLevel ;
5
- use rustc:: ty:: { self , Ty , TyCtxt , ClosureSubsts , GeneratorSubsts } ;
6
+ use rustc:: ty:: { self , Ty , TyCtxt , Const , ClosureSubsts , GeneratorSubsts , LazyConst , ParamConst } ;
6
7
use rustc:: ty:: subst:: { SubstsRef , InternalSubsts } ;
7
8
use syntax:: ast;
8
9
use syntax:: attr:: InlineAttr ;
@@ -44,7 +45,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
44
45
fn is_generic_fn ( & self ) -> bool {
45
46
match * self . as_mono_item ( ) {
46
47
MonoItem :: Fn ( ref instance) => {
47
- instance. substs . types ( ) . next ( ) . is_some ( )
48
+ instance. substs . non_erasable_generics ( ) . next ( ) . is_some ( )
48
49
}
49
50
MonoItem :: Static ( ..) |
50
51
MonoItem :: GlobalAsm ( ..) => false ,
@@ -267,7 +268,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
267
268
ty:: Float ( ast:: FloatTy :: F64 ) => output. push_str ( "f64" ) ,
268
269
ty:: Adt ( adt_def, substs) => {
269
270
self . push_def_path ( adt_def. did , output) ;
270
- self . push_type_params ( substs, iter:: empty ( ) , output, debug) ;
271
+ self . push_generic_params ( substs, iter:: empty ( ) , output, debug) ;
271
272
} ,
272
273
ty:: Tuple ( component_types) => {
273
274
output. push ( '(' ) ;
@@ -312,7 +313,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
312
313
ty:: Dynamic ( ref trait_data, ..) => {
313
314
if let Some ( principal) = trait_data. principal ( ) {
314
315
self . push_def_path ( principal. def_id ( ) , output) ;
315
- self . push_type_params (
316
+ self . push_generic_params (
316
317
principal. skip_binder ( ) . substs ,
317
318
trait_data. projection_bounds ( ) ,
318
319
output,
@@ -373,7 +374,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
373
374
self . push_def_path ( def_id, output) ;
374
375
let generics = self . tcx . generics_of ( self . tcx . closure_base_def_id ( def_id) ) ;
375
376
let substs = substs. truncate_to ( self . tcx , generics) ;
376
- self . push_type_params ( substs, iter:: empty ( ) , output, debug) ;
377
+ self . push_generic_params ( substs, iter:: empty ( ) , output, debug) ;
377
378
}
378
379
ty:: Error |
379
380
ty:: Bound ( ..) |
@@ -394,6 +395,24 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
394
395
}
395
396
}
396
397
398
+ // FIXME(const_generics): handle debug printing.
399
+ pub fn push_const_name ( & self , c : & LazyConst < ' tcx > , output : & mut String , debug : bool ) {
400
+ match c {
401
+ LazyConst :: Unevaluated ( ..) => output. push_str ( "_: _" ) ,
402
+ LazyConst :: Evaluated ( Const { ty, val } ) => {
403
+ match val {
404
+ ConstValue :: Infer ( ..) => output. push_str ( "_" ) ,
405
+ ConstValue :: Param ( ParamConst { name, .. } ) => {
406
+ write ! ( output, "{}" , name) . unwrap ( ) ;
407
+ }
408
+ _ => write ! ( output, "{:?}" , c) . unwrap ( ) ,
409
+ }
410
+ output. push_str ( ": " ) ;
411
+ self . push_type_name ( ty, output, debug) ;
412
+ }
413
+ }
414
+ }
415
+
397
416
pub fn push_def_path ( & self ,
398
417
def_id : DefId ,
399
418
output : & mut String ) {
@@ -421,15 +440,15 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
421
440
output. pop ( ) ;
422
441
}
423
442
424
- fn push_type_params < I > ( & self ,
425
- substs : SubstsRef < ' tcx > ,
426
- projections : I ,
427
- output : & mut String ,
428
- debug : bool )
429
- where I : Iterator < Item =ty :: PolyExistentialProjection < ' tcx > >
430
- {
443
+ fn push_generic_params < I > (
444
+ & self ,
445
+ substs : SubstsRef < ' tcx > ,
446
+ projections : I ,
447
+ output : & mut String ,
448
+ debug : bool ,
449
+ ) where I : Iterator < Item =ty :: PolyExistentialProjection < ' tcx > > {
431
450
let mut projections = projections. peekable ( ) ;
432
- if substs. types ( ) . next ( ) . is_none ( ) && projections. peek ( ) . is_none ( ) {
451
+ if substs. non_erasable_generics ( ) . next ( ) . is_none ( ) && projections. peek ( ) . is_none ( ) {
433
452
return ;
434
453
}
435
454
@@ -449,6 +468,11 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
449
468
output. push_str ( ", " ) ;
450
469
}
451
470
471
+ for const_parameter in substs. consts ( ) {
472
+ self . push_const_name ( const_parameter, output, debug) ;
473
+ output. push_str ( ", " ) ;
474
+ }
475
+
452
476
output. pop ( ) ;
453
477
output. pop ( ) ;
454
478
@@ -460,6 +484,6 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
460
484
output : & mut String ,
461
485
debug : bool ) {
462
486
self . push_def_path ( instance. def_id ( ) , output) ;
463
- self . push_type_params ( instance. substs , iter:: empty ( ) , output, debug) ;
487
+ self . push_generic_params ( instance. substs , iter:: empty ( ) , output, debug) ;
464
488
}
465
489
}
0 commit comments