Skip to content

Commit

Permalink
rustdoc: pretty-print Unevaluated expressions in types.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 14, 2017
1 parent 84bbd14 commit 06478d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl hir::print::PpAnn for InlinedConst {
}
}

fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
pub fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
let body = cx.tcx.extern_const_body(did);
let inlined = InlinedConst {
nested_bodies: cx.tcx.item_body_nested_bodies(did)
Expand Down
12 changes: 12 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,12 @@ impl Clean<Type> for hir::Ty {
let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap();
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
n.to_string()
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
print_const_expr(cx, cx.tcx.hir.body_owned_by(node_id))
} else {
inline::print_inlined_const(cx, def_id)
}
} else {
format!("{:?}", n)
};
Expand Down Expand Up @@ -1909,6 +1915,12 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
ty::TyArray(ty, n) => {
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
n.to_string()
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
print_const_expr(cx, cx.tcx.hir.body_owned_by(node_id))
} else {
inline::print_inlined_const(cx, def_id)
}
} else {
format!("{:?}", n)
};
Expand Down

0 comments on commit 06478d1

Please sign in to comment.