rollup merge of #19774: tomjakubowski/rustdoc-consts-statics
Build `clean::ConstantItem` values in the `inline` module and pretty-print the AST for inlined const items. Doc strings are still missing from inlined constants (see #19773). Partially address #18156, #19722, #19185 Fix #15821 r? @alexcrichton
This commit is contained in:
commit
3673486c6d
@ -104,6 +104,10 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
|
||||
record_extern_fqn(cx, did, clean::TypeStatic);
|
||||
clean::StaticItem(build_static(cx, tcx, did, mtbl))
|
||||
}
|
||||
def::DefConst(did) => {
|
||||
record_extern_fqn(cx, did, clean::TypeConst);
|
||||
clean::ConstantItem(build_const(cx, tcx, did))
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
let fqn = csearch::get_item_path(tcx, did);
|
||||
@ -388,6 +392,24 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_const(cx: &DocContext, tcx: &ty::ctxt,
|
||||
did: ast::DefId) -> clean::Constant {
|
||||
use rustc::middle::const_eval;
|
||||
use syntax::print::pprust;
|
||||
|
||||
let expr = const_eval::lookup_const_by_id(tcx, did).unwrap_or_else(|| {
|
||||
panic!("expected lookup_const_by_id to succeed for {}", did);
|
||||
});
|
||||
debug!("converting constant expr {} to snippet", expr);
|
||||
let sn = pprust::expr_to_string(expr);
|
||||
debug!("got snippet {}", sn);
|
||||
|
||||
clean::Constant {
|
||||
type_: ty::lookup_item_type(tcx, did).ty.clean(cx),
|
||||
expr: sn
|
||||
}
|
||||
}
|
||||
|
||||
fn build_static(cx: &DocContext, tcx: &ty::ctxt,
|
||||
did: ast::DefId,
|
||||
mutable: bool) -> clean::Static {
|
||||
|
@ -1201,6 +1201,7 @@ pub enum TypeKind {
|
||||
TypeEnum,
|
||||
TypeFunction,
|
||||
TypeModule,
|
||||
TypeConst,
|
||||
TypeStatic,
|
||||
TypeStruct,
|
||||
TypeTrait,
|
||||
@ -1841,7 +1842,7 @@ impl Clean<Item> for doctree::Static {
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, Encodable, Decodable)]
|
||||
#[deriving(Clone, Encodable, Decodable, Show)]
|
||||
pub struct Constant {
|
||||
pub type_: Type,
|
||||
pub expr: String,
|
||||
|
@ -76,6 +76,7 @@ impl ItemType {
|
||||
clean::TypeTrait => ItemType::Trait,
|
||||
clean::TypeModule => ItemType::Module,
|
||||
clean::TypeStatic => ItemType::Static,
|
||||
clean::TypeConst => ItemType::Constant,
|
||||
clean::TypeVariant => ItemType::Variant,
|
||||
clean::TypeTypedef => ItemType::Typedef,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user