@@ -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) ;
@@ -388,6 +392,24 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
388
392
}
389
393
}
390
394
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
+
391
413
fn build_static ( cx : & DocContext , tcx : & ty:: ctxt ,
392
414
did : ast:: DefId ,
393
415
mutable : bool ) -> clean:: Static {
0 commit comments