Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: pretty-print Unevaluated expressions in types. #44562

Merged
merged 1 commit into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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