Skip to content

Commit 4dc01c4

Browse files
authored
Rollup merge of rust-lang#44562 - eddyb:ugh-rustdoc, r=nikomatsakis
rustdoc: pretty-print Unevaluated expressions in types. Fixes rust-lang#44555. r? @nikomatsakis
2 parents eab1648 + 06478d1 commit 4dc01c4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl hir::print::PpAnn for InlinedConst {
473473
}
474474
}
475475

476-
fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
476+
pub fn print_inlined_const(cx: &DocContext, did: DefId) -> String {
477477
let body = cx.tcx.extern_const_body(did);
478478
let inlined = InlinedConst {
479479
nested_bodies: cx.tcx.item_body_nested_bodies(did)

src/librustdoc/clean/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,12 @@ impl Clean<Type> for hir::Ty {
17931793
let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap();
17941794
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
17951795
n.to_string()
1796+
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
1797+
if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
1798+
print_const_expr(cx, cx.tcx.hir.body_owned_by(node_id))
1799+
} else {
1800+
inline::print_inlined_const(cx, def_id)
1801+
}
17961802
} else {
17971803
format!("{:?}", n)
17981804
};
@@ -1909,6 +1915,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
19091915
ty::TyArray(ty, n) => {
19101916
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
19111917
n.to_string()
1918+
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
1919+
if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
1920+
print_const_expr(cx, cx.tcx.hir.body_owned_by(node_id))
1921+
} else {
1922+
inline::print_inlined_const(cx, def_id)
1923+
}
19121924
} else {
19131925
format!("{:?}", n)
19141926
};

0 commit comments

Comments
 (0)