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