@@ -104,6 +104,10 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
104
104
record_extern_fqn ( cx, did, clean:: TypeStatic ) ;
105
105
clean:: StaticItem ( build_static ( cx, tcx, did, mtbl) )
106
106
}
107
+ def:: DefConst ( did) => {
108
+ record_extern_fqn ( cx, did, clean:: TypeConst ) ;
109
+ clean:: ConstantItem ( build_const ( cx, tcx, did) )
110
+ }
107
111
_ => return None ,
108
112
} ;
109
113
let fqn = csearch:: get_item_path ( tcx, did) ;
@@ -387,6 +391,24 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
387
391
}
388
392
}
389
393
394
+ fn build_const ( cx : & DocContext , tcx : & ty:: ctxt ,
395
+ did : ast:: DefId ) -> clean:: Constant {
396
+ use rustc:: middle:: const_eval;
397
+ use syntax:: print:: pprust;
398
+
399
+ let expr = const_eval:: lookup_const_by_id ( tcx, did) . unwrap_or_else ( || {
400
+ panic ! ( "expected lookup_const_by_id to succeed for {}" , did) ;
401
+ } ) ;
402
+ debug ! ( "converting constant expr {} to snippet" , expr) ;
403
+ let sn = pprust:: expr_to_string ( expr) ;
404
+ debug ! ( "got snippet {}" , sn) ;
405
+
406
+ clean:: Constant {
407
+ type_ : ty:: lookup_item_type ( tcx, did) . ty . clean ( cx) ,
408
+ expr : sn
409
+ }
410
+ }
411
+
390
412
fn build_static ( cx : & DocContext , tcx : & ty:: ctxt ,
391
413
did : ast:: DefId ,
392
414
mutable : bool ) -> clean:: Static {
0 commit comments