Skip to content

Commit

Permalink
Rollup merge of rust-lang#44562 - eddyb:ugh-rustdoc, r=nikomatsakis
Browse files Browse the repository at this point in the history
rustdoc: pretty-print Unevaluated expressions in types.

Fixes rust-lang#44555.

r? @nikomatsakis
  • Loading branch information
alexcrichton authored Sep 16, 2017
2 parents ed3f09c + 06478d1 commit 3752ec2
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<'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 3752ec2

Please sign in to comment.