Rework rustdoc const type
This commit is contained in:
parent
f5fe425c92
commit
0cde85523f
11 changed files with 812 additions and 615 deletions
|
@ -9,7 +9,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
use rustc_metadata::creader::LoadedMacro;
|
use rustc_metadata::creader::LoadedMacro;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_mir::const_eval::is_min_const_fn;
|
use rustc_mir::const_eval::is_min_const_fn;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
|
@ -490,24 +490,17 @@ fn build_module(
|
||||||
clean::Module { items, is_crate: false }
|
clean::Module { items, is_crate: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String {
|
crate fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
|
||||||
if let Some(did) = did.as_local() {
|
if let Some(did) = did.as_local() {
|
||||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(did);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
|
||||||
rustc_hir_pretty::id_to_string(&cx.tcx.hir(), hir_id)
|
rustc_hir_pretty::id_to_string(&tcx.hir(), hir_id)
|
||||||
} else {
|
} else {
|
||||||
cx.tcx.rendered_const(did)
|
tcx.rendered_const(did)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_const(cx: &mut DocContext<'_>, did: DefId) -> clean::Constant {
|
fn build_const(cx: &mut DocContext<'_>, did: DefId) -> clean::Constant {
|
||||||
clean::Constant {
|
clean::Constant::Inline { type_: cx.tcx.type_of(did).clean(cx), did }
|
||||||
type_: cx.tcx.type_of(did).clean(cx),
|
|
||||||
expr: print_inlined_const(cx, did),
|
|
||||||
value: clean::utils::print_evaluated_const(cx, did),
|
|
||||||
is_literal: did.as_local().map_or(false, |did| {
|
|
||||||
clean::utils::is_literal_expr(cx, cx.tcx.hir().local_def_id_to_hir_id(did))
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
|
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
|
||||||
|
|
|
@ -393,14 +393,12 @@ impl Clean<Lifetime> for hir::GenericParam<'_> {
|
||||||
|
|
||||||
impl Clean<Constant> for hir::ConstArg {
|
impl Clean<Constant> for hir::ConstArg {
|
||||||
fn clean(&self, cx: &mut DocContext<'_>) -> Constant {
|
fn clean(&self, cx: &mut DocContext<'_>) -> Constant {
|
||||||
Constant {
|
Constant::Generic {
|
||||||
type_: cx
|
type_: cx
|
||||||
.tcx
|
.tcx
|
||||||
.type_of(cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id())
|
.type_of(cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id())
|
||||||
.clean(cx),
|
.clean(cx),
|
||||||
expr: print_const_expr(cx.tcx, self.value.body),
|
body: self.value.body,
|
||||||
value: None,
|
|
||||||
is_literal: is_literal_expr(cx, self.value.body.hir_id),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1135,7 +1133,7 @@ impl Clean<Item> for ty::AssocItem {
|
||||||
ty::AssocKind::Const => {
|
ty::AssocKind::Const => {
|
||||||
let ty = tcx.type_of(self.def_id);
|
let ty = tcx.type_of(self.def_id);
|
||||||
let default = if self.defaultness.has_value() {
|
let default = if self.defaultness.has_value() {
|
||||||
Some(inline::print_inlined_const(cx, self.def_id))
|
Some(inline::print_inlined_const(cx.tcx, self.def_id))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -1745,12 +1743,8 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
|
impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
|
||||||
fn clean(&self, cx: &mut DocContext<'_>) -> Constant {
|
fn clean(&self, cx: &mut DocContext<'_>) -> Constant {
|
||||||
Constant {
|
// FIXME: instead of storing `format!("{}", self)`, store `self` directly instead.
|
||||||
type_: self.ty.clean(cx),
|
Constant::TyConst { type_: self.ty.clean(cx), expr: format!("{}", self) }
|
||||||
expr: format!("{}", self),
|
|
||||||
value: None,
|
|
||||||
is_literal: false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1951,11 +1945,10 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
|
||||||
ItemKind::Static(ty, mutability, body_id) => {
|
ItemKind::Static(ty, mutability, body_id) => {
|
||||||
StaticItem(Static { type_: ty.clean(cx), mutability, expr: Some(body_id) })
|
StaticItem(Static { type_: ty.clean(cx), mutability, expr: Some(body_id) })
|
||||||
}
|
}
|
||||||
ItemKind::Const(ty, body_id) => ConstantItem(Constant {
|
ItemKind::Const(ty, body_id) => ConstantItem(Constant::Const {
|
||||||
type_: ty.clean(cx),
|
type_: ty.clean(cx),
|
||||||
expr: print_const_expr(cx.tcx, body_id),
|
body: body_id,
|
||||||
value: print_evaluated_const(cx, def_id),
|
did: def_id,
|
||||||
is_literal: is_literal_expr(cx, body_id.hir_id),
|
|
||||||
}),
|
}),
|
||||||
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
|
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
|
||||||
bounds: ty.bounds.clean(cx),
|
bounds: ty.bounds.clean(cx),
|
||||||
|
|
|
@ -32,8 +32,9 @@ use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
use crate::clean::cfg::Cfg;
|
use crate::clean::cfg::Cfg;
|
||||||
use crate::clean::external_path;
|
use crate::clean::external_path;
|
||||||
use crate::clean::inline;
|
use crate::clean::inline::{self, print_inlined_const};
|
||||||
use crate::clean::types::Type::{QPath, ResolvedPath};
|
use crate::clean::types::Type::{QPath, ResolvedPath};
|
||||||
|
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
|
||||||
use crate::clean::Clean;
|
use crate::clean::Clean;
|
||||||
use crate::core::DocContext;
|
use crate::core::DocContext;
|
||||||
use crate::formats::cache::Cache;
|
use crate::formats::cache::Cache;
|
||||||
|
@ -1986,11 +1987,64 @@ crate struct Static {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
crate struct Constant {
|
crate enum Constant {
|
||||||
crate type_: Type,
|
/// Typed constant value.
|
||||||
crate expr: String,
|
TyConst { type_: Type, expr: String },
|
||||||
crate value: Option<String>,
|
/// A constant (expression) that’s not an item or associated item. These are usually found
|
||||||
crate is_literal: bool,
|
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
|
||||||
|
/// used to define explicit discriminant values for enum variants.
|
||||||
|
Generic { type_: Type, body: BodyId },
|
||||||
|
/// Inlined constant (from another crate).
|
||||||
|
Inline { type_: Type, did: DefId },
|
||||||
|
/// const FOO: u32 = ...;
|
||||||
|
Const { type_: Type, did: DefId, body: BodyId },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Constant {
|
||||||
|
crate fn expr(&self, tcx: TyCtxt<'_>) -> String {
|
||||||
|
match self {
|
||||||
|
Self::TyConst { expr, .. } => expr.clone(),
|
||||||
|
Self::Inline { did, .. } => print_inlined_const(tcx, *did),
|
||||||
|
Self::Const { body, .. } | Self::Generic { body, .. } => print_const_expr(tcx, *body),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
crate fn value(&self, tcx: TyCtxt<'_>) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Self::TyConst { .. } | Self::Generic { .. } => None,
|
||||||
|
Self::Inline { did, .. } | Self::Const { did, .. } => print_evaluated_const(tcx, *did),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
crate fn is_literal(&self, tcx: TyCtxt<'_>) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::TyConst { .. } => false,
|
||||||
|
Self::Inline { did, .. } => did
|
||||||
|
.as_local()
|
||||||
|
.map_or(false, |did| is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(did))),
|
||||||
|
Self::Const { body, .. } | Self::Generic { body, .. } => {
|
||||||
|
is_literal_expr(tcx, body.hir_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
crate fn type_(&self) -> &Type {
|
||||||
|
match *self {
|
||||||
|
Self::TyConst { ref type_, .. }
|
||||||
|
| Self::Inline { ref type_, .. }
|
||||||
|
| Self::Const { ref type_, .. }
|
||||||
|
| Self::Generic { ref type_, .. } => type_,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
crate fn to_type(self) -> Type {
|
||||||
|
match self {
|
||||||
|
Self::TyConst { type_, .. }
|
||||||
|
| Self::Inline { type_, .. }
|
||||||
|
| Self::Const { type_, .. }
|
||||||
|
| Self::Generic { type_, .. } => type_,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -301,7 +301,7 @@ crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
|
||||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
|
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
|
||||||
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(hir_id))
|
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(hir_id))
|
||||||
} else {
|
} else {
|
||||||
inline::print_inlined_const(cx, def.did)
|
inline::print_inlined_const(cx.tcx, def.did)
|
||||||
};
|
};
|
||||||
if let Some(promoted) = promoted {
|
if let Some(promoted) = promoted {
|
||||||
s.push_str(&format!("::{:?}", promoted))
|
s.push_str(&format!("::{:?}", promoted))
|
||||||
|
@ -324,15 +324,15 @@ crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<String> {
|
crate fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<String> {
|
||||||
cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
|
tcx.const_eval_poly(def_id).ok().and_then(|val| {
|
||||||
let ty = cx.tcx.type_of(def_id);
|
let ty = tcx.type_of(def_id);
|
||||||
match (val, ty.kind()) {
|
match (val, ty.kind()) {
|
||||||
(_, &ty::Ref(..)) => None,
|
(_, &ty::Ref(..)) => None,
|
||||||
(ConstValue::Scalar(_), &ty::Adt(_, _)) => None,
|
(ConstValue::Scalar(_), &ty::Adt(_, _)) => None,
|
||||||
(ConstValue::Scalar(_), _) => {
|
(ConstValue::Scalar(_), _) => {
|
||||||
let const_ = ty::Const::from_value(cx.tcx, val, ty);
|
let const_ = ty::Const::from_value(tcx, val, ty);
|
||||||
Some(print_const_with_custom_print_scalar(cx, const_))
|
Some(print_const_with_custom_print_scalar(tcx, const_))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const<'tcx>) -> String {
|
fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: &'tcx ty::Const<'tcx>) -> String {
|
||||||
// Use a slightly different format for integer types which always shows the actual value.
|
// Use a slightly different format for integer types which always shows the actual value.
|
||||||
// For all other types, fallback to the original `pretty_print_const`.
|
// For all other types, fallback to the original `pretty_print_const`.
|
||||||
match (ct.val, ct.ty.kind()) {
|
match (ct.val, ct.ty.kind()) {
|
||||||
|
@ -357,8 +357,8 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
|
||||||
format!("{}{}", format_integer_with_underscore_sep(&int.to_string()), ui.name_str())
|
format!("{}{}", format_integer_with_underscore_sep(&int.to_string()), ui.name_str())
|
||||||
}
|
}
|
||||||
(ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Int(i)) => {
|
(ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Int(i)) => {
|
||||||
let ty = cx.tcx.lift(ct.ty).unwrap();
|
let ty = tcx.lift(ct.ty).unwrap();
|
||||||
let size = cx.tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size;
|
let size = tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size;
|
||||||
let data = int.assert_bits(size);
|
let data = int.assert_bits(size);
|
||||||
let sign_extended_data = size.sign_extend(data) as i128;
|
let sign_extended_data = size.sign_extend(data) as i128;
|
||||||
|
|
||||||
|
@ -372,8 +372,8 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn is_literal_expr(cx: &DocContext<'_>, hir_id: hir::HirId) -> bool {
|
crate fn is_literal_expr(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
||||||
if let hir::Node::Expr(expr) = cx.tcx.hir().get(hir_id) {
|
if let hir::Node::Expr(expr) = tcx.hir().get(hir_id) {
|
||||||
if let hir::ExprKind::Lit(_) = &expr.kind {
|
if let hir::ExprKind::Lit(_) = &expr.kind {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path, id: hir::HirId) -> Ty
|
||||||
return Generic(kw::SelfUpper);
|
return Generic(kw::SelfUpper);
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
|
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
|
||||||
return Generic(Symbol::intern(&format!("{:#}", path.print(&cx.cache))));
|
return Generic(Symbol::intern(&format!("{:#}", path.print(&cx.cache, cx.tcx))));
|
||||||
}
|
}
|
||||||
Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true,
|
Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -67,8 +67,8 @@ use crate::formats::item_type::ItemType;
|
||||||
use crate::formats::{AssocItemRender, FormatRenderer, Impl, RenderMode};
|
use crate::formats::{AssocItemRender, FormatRenderer, Impl, RenderMode};
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{
|
use crate::html::format::{
|
||||||
href, print_abi_with_space, print_default_space, print_generic_bounds, Buffer, Function,
|
href, print_abi_with_space, print_default_space, print_generic_bounds, print_where_clause,
|
||||||
PrintWithSpace, WhereClause,
|
Buffer, PrintWithSpace,
|
||||||
};
|
};
|
||||||
use crate::html::layout;
|
use crate::html::layout;
|
||||||
use crate::html::markdown::{self, ErrorCodes, Markdown, MarkdownHtml, MarkdownSummaryLine};
|
use crate::html::markdown::{self, ErrorCodes, Markdown, MarkdownHtml, MarkdownSummaryLine};
|
||||||
|
@ -918,7 +918,7 @@ fn assoc_const(
|
||||||
it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
||||||
naive_assoc_href(it, link, cx.cache()),
|
naive_assoc_href(it, link, cx.cache()),
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
ty.print(cx.cache())
|
ty.print(cx.cache(), cx.tcx())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,6 +930,7 @@ fn assoc_type(
|
||||||
link: AssocItemLink<'_>,
|
link: AssocItemLink<'_>,
|
||||||
extra: &str,
|
extra: &str,
|
||||||
cache: &Cache,
|
cache: &Cache,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
) {
|
) {
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
|
@ -939,10 +940,10 @@ fn assoc_type(
|
||||||
it.name.as_ref().unwrap()
|
it.name.as_ref().unwrap()
|
||||||
);
|
);
|
||||||
if !bounds.is_empty() {
|
if !bounds.is_empty() {
|
||||||
write!(w, ": {}", print_generic_bounds(bounds, cache))
|
write!(w, ": {}", print_generic_bounds(bounds, cache, tcx))
|
||||||
}
|
}
|
||||||
if let Some(default) = default {
|
if let Some(default) = default {
|
||||||
write!(w, " = {}", default.print(cache))
|
write!(w, " = {}", default.print(cache, tcx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1017,7 +1018,7 @@ fn render_assoc_item(
|
||||||
let defaultness = print_default_space(meth.is_default());
|
let defaultness = print_default_space(meth.is_default());
|
||||||
let abi = print_abi_with_space(header.abi).to_string();
|
let abi = print_abi_with_space(header.abi).to_string();
|
||||||
// NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
|
// NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
|
||||||
let generics_len = format!("{:#}", g.print(cx.cache())).len();
|
let generics_len = format!("{:#}", g.print(cx.cache(), tcx)).len();
|
||||||
let mut header_len = "fn ".len()
|
let mut header_len = "fn ".len()
|
||||||
+ vis.len()
|
+ vis.len()
|
||||||
+ constness.len()
|
+ constness.len()
|
||||||
|
@ -1049,11 +1050,10 @@ fn render_assoc_item(
|
||||||
abi,
|
abi,
|
||||||
href = href,
|
href = href,
|
||||||
name = name,
|
name = name,
|
||||||
generics = g.print(cx.cache()),
|
generics = g.print(cx.cache(), cx.tcx()),
|
||||||
decl = Function { decl: d, header_len, indent, asyncness: header.asyncness }
|
decl = d.full_print(cx.cache(), cx.tcx(), header_len, indent, header.asyncness),
|
||||||
.print(cx.cache()),
|
spotlight = spotlight_decl(&d, cx.cache(), cx.tcx()),
|
||||||
spotlight = spotlight_decl(&d, cx.cache()),
|
where_clause = print_where_clause(g, cx.cache(), cx.tcx(), indent, end_newline),
|
||||||
where_clause = WhereClause { gens: g, indent, end_newline }.print(cx.cache())
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
match *item.kind {
|
match *item.kind {
|
||||||
|
@ -1081,6 +1081,7 @@ fn render_assoc_item(
|
||||||
link,
|
link,
|
||||||
if parent == ItemType::Trait { " " } else { "" },
|
if parent == ItemType::Trait { " " } else { "" },
|
||||||
cx.cache(),
|
cx.cache(),
|
||||||
|
cx.tcx(),
|
||||||
),
|
),
|
||||||
_ => panic!("render_assoc_item called on non-associated-item"),
|
_ => panic!("render_assoc_item called on non-associated-item"),
|
||||||
}
|
}
|
||||||
|
@ -1169,9 +1170,9 @@ fn render_assoc_items(
|
||||||
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
|
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
|
||||||
let id = cx.derive_id(small_url_encode(format!(
|
let id = cx.derive_id(small_url_encode(format!(
|
||||||
"deref-methods-{:#}",
|
"deref-methods-{:#}",
|
||||||
type_.print(cx.cache())
|
type_.print(cx.cache(), cx.tcx())
|
||||||
)));
|
)));
|
||||||
debug!("Adding {} to deref id map", type_.print(cx.cache()));
|
debug!("Adding {} to deref id map", type_.print(cx.cache(), cx.tcx()));
|
||||||
cx.deref_id_map
|
cx.deref_id_map
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(type_.def_id_full(cx.cache()).unwrap(), id.clone());
|
.insert(type_.def_id_full(cx.cache()).unwrap(), id.clone());
|
||||||
|
@ -1182,8 +1183,8 @@ fn render_assoc_items(
|
||||||
<a href=\"#{id}\" class=\"anchor\"></a>\
|
<a href=\"#{id}\" class=\"anchor\"></a>\
|
||||||
</h2>",
|
</h2>",
|
||||||
id = id,
|
id = id,
|
||||||
trait_ = trait_.print(cx.cache()),
|
trait_ = trait_.print(cx.cache(), cx.tcx()),
|
||||||
type_ = type_.print(cx.cache()),
|
type_ = type_.print(cx.cache(), cx.tcx()),
|
||||||
);
|
);
|
||||||
RenderMode::ForDeref { mut_: deref_mut_ }
|
RenderMode::ForDeref { mut_: deref_mut_ }
|
||||||
}
|
}
|
||||||
|
@ -1335,7 +1336,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, cache: &Cache) -> bo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
|
fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache, tcx: TyCtxt<'_>) -> String {
|
||||||
let mut out = Buffer::html();
|
let mut out = Buffer::html();
|
||||||
let mut trait_ = String::new();
|
let mut trait_ = String::new();
|
||||||
|
|
||||||
|
@ -1351,16 +1352,16 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
|
||||||
&mut out,
|
&mut out,
|
||||||
"<h3 class=\"notable\">Notable traits for {}</h3>\
|
"<h3 class=\"notable\">Notable traits for {}</h3>\
|
||||||
<code class=\"content\">",
|
<code class=\"content\">",
|
||||||
impl_.for_.print(cache)
|
impl_.for_.print(cache, tcx)
|
||||||
);
|
);
|
||||||
trait_.push_str(&impl_.for_.print(cache).to_string());
|
trait_.push_str(&impl_.for_.print(cache, tcx).to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
//use the "where" class here to make it small
|
//use the "where" class here to make it small
|
||||||
write!(
|
write!(
|
||||||
&mut out,
|
&mut out,
|
||||||
"<span class=\"where fmt-newline\">{}</span>",
|
"<span class=\"where fmt-newline\">{}</span>",
|
||||||
impl_.print(cache, false)
|
impl_.print(cache, false, tcx)
|
||||||
);
|
);
|
||||||
let t_did = impl_.trait_.def_id_full(cache).unwrap();
|
let t_did = impl_.trait_.def_id_full(cache).unwrap();
|
||||||
for it in &impl_.items {
|
for it in &impl_.items {
|
||||||
|
@ -1374,6 +1375,7 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
|
||||||
AssocItemLink::GotoSource(t_did, &FxHashSet::default()),
|
AssocItemLink::GotoSource(t_did, &FxHashSet::default()),
|
||||||
"",
|
"",
|
||||||
cache,
|
cache,
|
||||||
|
tcx,
|
||||||
);
|
);
|
||||||
out.push_str(";</span>");
|
out.push_str(";</span>");
|
||||||
}
|
}
|
||||||
|
@ -1419,9 +1421,12 @@ fn render_impl(
|
||||||
let id = cx.derive_id(match i.inner_impl().trait_ {
|
let id = cx.derive_id(match i.inner_impl().trait_ {
|
||||||
Some(ref t) => {
|
Some(ref t) => {
|
||||||
if is_on_foreign_type {
|
if is_on_foreign_type {
|
||||||
get_id_for_impl_on_foreign_type(&i.inner_impl().for_, t, cx.cache())
|
get_id_for_impl_on_foreign_type(&i.inner_impl().for_, t, cx.cache(), cx.tcx())
|
||||||
} else {
|
} else {
|
||||||
format!("impl-{}", small_url_encode(format!("{:#}", t.print(cx.cache()))))
|
format!(
|
||||||
|
"impl-{}",
|
||||||
|
small_url_encode(format!("{:#}", t.print(cx.cache(), cx.tcx())))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => "impl".to_string(),
|
None => "impl".to_string(),
|
||||||
|
@ -1433,7 +1438,7 @@ fn render_impl(
|
||||||
};
|
};
|
||||||
if let Some(use_absolute) = use_absolute {
|
if let Some(use_absolute) = use_absolute {
|
||||||
write!(w, "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", id, aliases);
|
write!(w, "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", id, aliases);
|
||||||
write!(w, "{}", i.inner_impl().print(cx.cache(), use_absolute));
|
write!(w, "{}", i.inner_impl().print(cx.cache(), use_absolute, cx.tcx()));
|
||||||
if show_def_docs {
|
if show_def_docs {
|
||||||
for it in &i.inner_impl().items {
|
for it in &i.inner_impl().items {
|
||||||
if let clean::TypedefItem(ref tydef, _) = *it.kind {
|
if let clean::TypedefItem(ref tydef, _) = *it.kind {
|
||||||
|
@ -1446,6 +1451,7 @@ fn render_impl(
|
||||||
AssocItemLink::Anchor(None),
|
AssocItemLink::Anchor(None),
|
||||||
"",
|
"",
|
||||||
cx.cache(),
|
cx.cache(),
|
||||||
|
cx.tcx(),
|
||||||
);
|
);
|
||||||
w.write_str(";</span>");
|
w.write_str(";</span>");
|
||||||
}
|
}
|
||||||
|
@ -1458,7 +1464,7 @@ fn render_impl(
|
||||||
"<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
|
"<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
|
||||||
id,
|
id,
|
||||||
aliases,
|
aliases,
|
||||||
i.inner_impl().print(cx.cache(), false)
|
i.inner_impl().print(cx.cache(), false, cx.tcx())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
||||||
|
@ -1558,6 +1564,7 @@ fn render_impl(
|
||||||
link.anchor(&id),
|
link.anchor(&id),
|
||||||
"",
|
"",
|
||||||
cx.cache(),
|
cx.cache(),
|
||||||
|
cx.tcx(),
|
||||||
);
|
);
|
||||||
w.write_str("</code></h4>");
|
w.write_str("</code></h4>");
|
||||||
}
|
}
|
||||||
|
@ -1579,7 +1586,16 @@ fn render_impl(
|
||||||
clean::AssocTypeItem(ref bounds, ref default) => {
|
clean::AssocTypeItem(ref bounds, ref default) => {
|
||||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||||
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, extra_class);
|
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, extra_class);
|
||||||
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "", cx.cache());
|
assoc_type(
|
||||||
|
w,
|
||||||
|
item,
|
||||||
|
bounds,
|
||||||
|
default.as_ref(),
|
||||||
|
link.anchor(&id),
|
||||||
|
"",
|
||||||
|
cx.cache(),
|
||||||
|
cx.tcx(),
|
||||||
|
);
|
||||||
w.write_str("</code></h4>");
|
w.write_str("</code></h4>");
|
||||||
}
|
}
|
||||||
clean::StrippedItem(..) => return,
|
clean::StrippedItem(..) => return,
|
||||||
|
@ -1922,9 +1938,10 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|it| {
|
.filter_map(|it| {
|
||||||
if let Some(ref i) = it.inner_impl().trait_ {
|
if let Some(ref i) = it.inner_impl().trait_ {
|
||||||
let i_display = format!("{:#}", i.print(cx.cache()));
|
let i_display = format!("{:#}", i.print(cx.cache(), cx.tcx()));
|
||||||
let out = Escape(&i_display);
|
let out = Escape(&i_display);
|
||||||
let encoded = small_url_encode(format!("{:#}", i.print(cx.cache())));
|
let encoded =
|
||||||
|
small_url_encode(format!("{:#}", i.print(cx.cache(), cx.tcx())));
|
||||||
let generated = format!(
|
let generated = format!(
|
||||||
"<a href=\"#impl-{}\">{}{}</a>",
|
"<a href=\"#impl-{}\">{}{}</a>",
|
||||||
encoded,
|
encoded,
|
||||||
|
@ -1988,6 +2005,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
|
||||||
|
|
||||||
fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &Vec<Impl>) {
|
fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &Vec<Impl>) {
|
||||||
let c = cx.cache();
|
let c = cx.cache();
|
||||||
|
let tcx = cx.tcx();
|
||||||
|
|
||||||
debug!("found Deref: {:?}", impl_);
|
debug!("found Deref: {:?}", impl_);
|
||||||
if let Some((target, real_target)) =
|
if let Some((target, real_target)) =
|
||||||
|
@ -2036,8 +2054,11 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
|
||||||
out,
|
out,
|
||||||
"<a class=\"sidebar-title\" href=\"#{}\">Methods from {}<Target={}></a>",
|
"<a class=\"sidebar-title\" href=\"#{}\">Methods from {}<Target={}></a>",
|
||||||
id,
|
id,
|
||||||
Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(c))),
|
Escape(&format!(
|
||||||
Escape(&format!("{:#}", real_target.print(c))),
|
"{:#}",
|
||||||
|
impl_.inner_impl().trait_.as_ref().unwrap().print(c, tcx)
|
||||||
|
)),
|
||||||
|
Escape(&format!("{:#}", real_target.print(c, tcx))),
|
||||||
);
|
);
|
||||||
// We want links' order to be reproducible so we don't use unstable sort.
|
// We want links' order to be reproducible so we don't use unstable sort.
|
||||||
ret.sort();
|
ret.sort();
|
||||||
|
@ -2094,17 +2115,26 @@ fn get_id_for_impl_on_foreign_type(
|
||||||
for_: &clean::Type,
|
for_: &clean::Type,
|
||||||
trait_: &clean::Type,
|
trait_: &clean::Type,
|
||||||
cache: &Cache,
|
cache: &Cache,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
) -> String {
|
) -> String {
|
||||||
small_url_encode(format!("impl-{:#}-for-{:#}", trait_.print(cache), for_.print(cache)))
|
small_url_encode(format!(
|
||||||
|
"impl-{:#}-for-{:#}",
|
||||||
|
trait_.print(cache, tcx),
|
||||||
|
for_.print(cache, tcx)
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_for_impl_name(item: &clean::Item, cache: &Cache) -> Option<(String, String)> {
|
fn extract_for_impl_name(
|
||||||
|
item: &clean::Item,
|
||||||
|
cache: &Cache,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
|
) -> Option<(String, String)> {
|
||||||
match *item.kind {
|
match *item.kind {
|
||||||
clean::ItemKind::ImplItem(ref i) => {
|
clean::ItemKind::ImplItem(ref i) => {
|
||||||
if let Some(ref trait_) = i.trait_ {
|
if let Some(ref trait_) = i.trait_ {
|
||||||
Some((
|
Some((
|
||||||
format!("{:#}", i.for_.print(cache)),
|
format!("{:#}", i.for_.print(cache, tcx)),
|
||||||
get_id_for_impl_on_foreign_type(&i.for_, trait_, cache),
|
get_id_for_impl_on_foreign_type(&i.for_, trait_, cache, tcx),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -2192,7 +2222,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
|
||||||
.def_id_full(cx.cache())
|
.def_id_full(cx.cache())
|
||||||
.map_or(false, |d| !cx.cache.paths.contains_key(&d))
|
.map_or(false, |d| !cx.cache.paths.contains_key(&d))
|
||||||
})
|
})
|
||||||
.filter_map(|i| extract_for_impl_name(&i.impl_item, cx.cache()))
|
.filter_map(|i| extract_for_impl_name(&i.impl_item, cx.cache(), cx.tcx()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if !res.is_empty() {
|
if !res.is_empty() {
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::formats::cache::Cache;
|
||||||
use crate::formats::item_type::ItemType;
|
use crate::formats::item_type::ItemType;
|
||||||
use crate::formats::{AssocItemRender, FormatRenderer, Impl, RenderMode};
|
use crate::formats::{AssocItemRender, FormatRenderer, Impl, RenderMode};
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{print_abi_with_space, Buffer, Function, PrintWithSpace, WhereClause};
|
use crate::html::format::{print_abi_with_space, print_where_clause, Buffer, PrintWithSpace};
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
use crate::html::markdown::MarkdownSummaryLine;
|
use crate::html::markdown::MarkdownSummaryLine;
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
||||||
w,
|
w,
|
||||||
"<tr><td><code>{}{}</code></td></tr>",
|
"<tr><td><code>{}{}</code></td></tr>",
|
||||||
myitem.visibility.print_with_space(cx.tcx(), myitem.def_id, cx.cache()),
|
myitem.visibility.print_with_space(cx.tcx(), myitem.def_id, cx.cache()),
|
||||||
import.print(cx.cache())
|
import.print(cx.cache(), cx.tcx()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
|
||||||
f.header.unsafety.print_with_space(),
|
f.header.unsafety.print_with_space(),
|
||||||
print_abi_with_space(f.header.abi),
|
print_abi_with_space(f.header.abi),
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
f.generics.print(cx.cache())
|
f.generics.print(cx.cache(), cx.tcx())
|
||||||
)
|
)
|
||||||
.len();
|
.len();
|
||||||
w.write_str("<pre class=\"rust fn\">");
|
w.write_str("<pre class=\"rust fn\">");
|
||||||
|
@ -387,18 +387,16 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
|
||||||
unsafety = f.header.unsafety.print_with_space(),
|
unsafety = f.header.unsafety.print_with_space(),
|
||||||
abi = print_abi_with_space(f.header.abi),
|
abi = print_abi_with_space(f.header.abi),
|
||||||
name = it.name.as_ref().unwrap(),
|
name = it.name.as_ref().unwrap(),
|
||||||
generics = f.generics.print(cx.cache()),
|
generics = f.generics.print(cx.cache(), cx.tcx()),
|
||||||
where_clause =
|
where_clause = print_where_clause(&f.generics, cx.cache(), cx.tcx(), 0, true),
|
||||||
WhereClause { gens: &f.generics, indent: 0, end_newline: true }.print(cx.cache()),
|
decl = f.decl.full_print(cx.cache(), cx.tcx(), header_len, 0, f.header.asyncness),
|
||||||
decl = Function { decl: &f.decl, header_len, indent: 0, asyncness: f.header.asyncness }
|
spotlight = spotlight_decl(&f.decl, cx.cache(), cx.tcx()),
|
||||||
.print(cx.cache()),
|
|
||||||
spotlight = spotlight_decl(&f.decl, cx.cache()),
|
|
||||||
);
|
);
|
||||||
document(w, cx, it, None)
|
document(w, cx, it, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) {
|
fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) {
|
||||||
let bounds = bounds(&t.bounds, false, cx.cache());
|
let bounds = bounds(&t.bounds, false, cx.cache(), cx.tcx());
|
||||||
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
|
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
|
||||||
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
|
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
|
||||||
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
|
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
|
||||||
|
@ -415,13 +413,12 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
t.unsafety.print_with_space(),
|
t.unsafety.print_with_space(),
|
||||||
if t.is_auto { "auto " } else { "" },
|
if t.is_auto { "auto " } else { "" },
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
t.generics.print(cx.cache()),
|
t.generics.print(cx.cache(), cx.tcx()),
|
||||||
bounds
|
bounds
|
||||||
);
|
);
|
||||||
|
|
||||||
if !t.generics.where_predicates.is_empty() {
|
if !t.generics.where_predicates.is_empty() {
|
||||||
let where_ = WhereClause { gens: &t.generics, indent: 0, end_newline: true };
|
write!(w, "{}", print_where_clause(&t.generics, cx.cache(), cx.tcx(), 0, true));
|
||||||
write!(w, "{}", where_.print(cx.cache()));
|
|
||||||
} else {
|
} else {
|
||||||
w.write_str(" ");
|
w.write_str(" ");
|
||||||
}
|
}
|
||||||
|
@ -594,8 +591,8 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) =
|
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) =
|
||||||
local.iter().partition(|i| i.inner_impl().synthetic);
|
local.iter().partition(|i| i.inner_impl().synthetic);
|
||||||
|
|
||||||
synthetic.sort_by(|a, b| compare_impl(a, b, cx.cache()));
|
synthetic.sort_by(|a, b| compare_impl(a, b, cx.cache(), cx.tcx()));
|
||||||
concrete.sort_by(|a, b| compare_impl(a, b, cx.cache()));
|
concrete.sort_by(|a, b| compare_impl(a, b, cx.cache(), cx.tcx()));
|
||||||
|
|
||||||
if !foreign.is_empty() {
|
if !foreign.is_empty() {
|
||||||
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
|
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
|
||||||
|
@ -700,9 +697,9 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
|
||||||
w,
|
w,
|
||||||
"trait {}{}{} = {};</pre>",
|
"trait {}{}{} = {};</pre>",
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
t.generics.print(cx.cache()),
|
t.generics.print(cx.cache(), cx.tcx()),
|
||||||
WhereClause { gens: &t.generics, indent: 0, end_newline: true }.print(cx.cache()),
|
print_where_clause(&t.generics, cx.cache(), cx.tcx(), 0, true),
|
||||||
bounds(&t.bounds, true, cx.cache())
|
bounds(&t.bounds, true, cx.cache(), cx.tcx())
|
||||||
);
|
);
|
||||||
|
|
||||||
document(w, cx, it, None);
|
document(w, cx, it, None);
|
||||||
|
@ -721,10 +718,9 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
|
||||||
w,
|
w,
|
||||||
"type {}{}{where_clause} = impl {bounds};</pre>",
|
"type {}{}{where_clause} = impl {bounds};</pre>",
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
t.generics.print(cx.cache()),
|
t.generics.print(cx.cache(), cx.tcx()),
|
||||||
where_clause =
|
where_clause = print_where_clause(&t.generics, cx.cache(), cx.tcx(), 0, true),
|
||||||
WhereClause { gens: &t.generics, indent: 0, end_newline: true }.print(cx.cache()),
|
bounds = bounds(&t.bounds, false, cx.cache(), cx.tcx()),
|
||||||
bounds = bounds(&t.bounds, false, cx.cache())
|
|
||||||
);
|
);
|
||||||
|
|
||||||
document(w, cx, it, None);
|
document(w, cx, it, None);
|
||||||
|
@ -743,10 +739,9 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
|
||||||
w,
|
w,
|
||||||
"type {}{}{where_clause} = {type_};</pre>",
|
"type {}{}{where_clause} = {type_};</pre>",
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
t.generics.print(cx.cache()),
|
t.generics.print(cx.cache(), cx.tcx()),
|
||||||
where_clause =
|
where_clause = print_where_clause(&t.generics, cx.cache(), cx.tcx(), 0, true),
|
||||||
WhereClause { gens: &t.generics, indent: 0, end_newline: true }.print(cx.cache()),
|
type_ = t.type_.print(cx.cache(), cx.tcx()),
|
||||||
type_ = t.type_.print(cx.cache())
|
|
||||||
);
|
);
|
||||||
|
|
||||||
document(w, cx, it, None);
|
document(w, cx, it, None);
|
||||||
|
@ -793,7 +788,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
shortty = ItemType::StructField,
|
shortty = ItemType::StructField,
|
||||||
ty = ty.print(cx.cache())
|
ty = ty.print(cx.cache(), cx.tcx()),
|
||||||
);
|
);
|
||||||
if let Some(stability_class) = field.stability_class(cx.tcx()) {
|
if let Some(stability_class) = field.stability_class(cx.tcx()) {
|
||||||
write!(w, "<span class=\"stab {stab}\"></span>", stab = stability_class);
|
write!(w, "<span class=\"stab {stab}\"></span>", stab = stability_class);
|
||||||
|
@ -813,8 +808,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
"{}enum {}{}{}",
|
"{}enum {}{}{}",
|
||||||
it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
e.generics.print(cx.cache()),
|
e.generics.print(cx.cache(), cx.tcx()),
|
||||||
WhereClause { gens: &e.generics, indent: 0, end_newline: true }.print(cx.cache())
|
print_where_clause(&e.generics, cx.cache(), cx.tcx(), 0, true),
|
||||||
);
|
);
|
||||||
if e.variants.is_empty() && !e.variants_stripped {
|
if e.variants.is_empty() && !e.variants_stripped {
|
||||||
w.write_str(" {}");
|
w.write_str(" {}");
|
||||||
|
@ -832,7 +827,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
w.write_str(", ")
|
w.write_str(", ")
|
||||||
}
|
}
|
||||||
write!(w, "{}", ty.print(cx.cache()));
|
write!(w, "{}", ty.print(cx.cache(), cx.tcx()));
|
||||||
}
|
}
|
||||||
w.write_str(")");
|
w.write_str(")");
|
||||||
}
|
}
|
||||||
|
@ -879,7 +874,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
w.write_str(", ");
|
w.write_str(", ");
|
||||||
}
|
}
|
||||||
write!(w, "{}", ty.print(cx.cache()));
|
write!(w, "{}", ty.print(cx.cache(), cx.tcx()));
|
||||||
}
|
}
|
||||||
w.write_str(")");
|
w.write_str(")");
|
||||||
}
|
}
|
||||||
|
@ -916,7 +911,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
</span>",
|
</span>",
|
||||||
id = id,
|
id = id,
|
||||||
f = field.name.as_ref().unwrap(),
|
f = field.name.as_ref().unwrap(),
|
||||||
t = ty.print(cx.cache())
|
t = ty.print(cx.cache(), cx.tcx())
|
||||||
);
|
);
|
||||||
document(w, cx, field, Some(variant));
|
document(w, cx, field, Some(variant));
|
||||||
}
|
}
|
||||||
|
@ -987,19 +982,22 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
|
||||||
"{vis}const {name}: {typ}",
|
"{vis}const {name}: {typ}",
|
||||||
vis = it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
vis = it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
||||||
name = it.name.as_ref().unwrap(),
|
name = it.name.as_ref().unwrap(),
|
||||||
typ = c.type_.print(cx.cache()),
|
typ = c.type_().print(cx.cache(), cx.tcx()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if c.value.is_some() || c.is_literal {
|
let value = c.value(cx.tcx());
|
||||||
write!(w, " = {expr};", expr = Escape(&c.expr));
|
let is_literal = c.is_literal(cx.tcx());
|
||||||
|
let expr = c.expr(cx.tcx());
|
||||||
|
if value.is_some() || is_literal {
|
||||||
|
write!(w, " = {expr};", expr = Escape(&expr));
|
||||||
} else {
|
} else {
|
||||||
w.write_str(";");
|
w.write_str(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(value) = &c.value {
|
if !is_literal {
|
||||||
if !c.is_literal {
|
if let Some(value) = &value {
|
||||||
let value_lowercase = value.to_lowercase();
|
let value_lowercase = value.to_lowercase();
|
||||||
let expr_lowercase = c.expr.to_lowercase();
|
let expr_lowercase = expr.to_lowercase();
|
||||||
|
|
||||||
if value_lowercase != expr_lowercase
|
if value_lowercase != expr_lowercase
|
||||||
&& value_lowercase.trim_end_matches("i32") != expr_lowercase
|
&& value_lowercase.trim_end_matches("i32") != expr_lowercase
|
||||||
|
@ -1054,7 +1052,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
|
||||||
item_type = ItemType::StructField,
|
item_type = ItemType::StructField,
|
||||||
id = id,
|
id = id,
|
||||||
name = field.name.as_ref().unwrap(),
|
name = field.name.as_ref().unwrap(),
|
||||||
ty = ty.print(cx.cache())
|
ty = ty.print(cx.cache(), cx.tcx())
|
||||||
);
|
);
|
||||||
document(w, cx, field, Some(it));
|
document(w, cx, field, Some(it));
|
||||||
}
|
}
|
||||||
|
@ -1072,7 +1070,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
|
||||||
vis = it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
vis = it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()),
|
||||||
mutability = s.mutability.print_with_space(),
|
mutability = s.mutability.print_with_space(),
|
||||||
name = it.name.as_ref().unwrap(),
|
name = it.name.as_ref().unwrap(),
|
||||||
typ = s.type_.print(cx.cache())
|
typ = s.type_.print(cx.cache(), cx.tcx())
|
||||||
);
|
);
|
||||||
document(w, cx, it, None)
|
document(w, cx, it, None)
|
||||||
}
|
}
|
||||||
|
@ -1147,7 +1145,12 @@ pub(super) fn item_path(ty: ItemType, name: &str) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cache: &Cache) -> String {
|
fn bounds(
|
||||||
|
t_bounds: &[clean::GenericBound],
|
||||||
|
trait_alias: bool,
|
||||||
|
cache: &Cache,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
|
) -> String {
|
||||||
let mut bounds = String::new();
|
let mut bounds = String::new();
|
||||||
if !t_bounds.is_empty() {
|
if !t_bounds.is_empty() {
|
||||||
if !trait_alias {
|
if !trait_alias {
|
||||||
|
@ -1157,7 +1160,7 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cache: &Cache) ->
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
bounds.push_str(" + ");
|
bounds.push_str(" + ");
|
||||||
}
|
}
|
||||||
bounds.push_str(&p.print(cache).to_string());
|
bounds.push_str(&p.print(cache, tcx).to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bounds
|
bounds
|
||||||
|
@ -1187,9 +1190,14 @@ fn render_stability_since(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cache: &Cache) -> Ordering {
|
fn compare_impl<'a, 'b>(
|
||||||
let lhs = format!("{}", lhs.inner_impl().print(cache, false));
|
lhs: &'a &&Impl,
|
||||||
let rhs = format!("{}", rhs.inner_impl().print(cache, false));
|
rhs: &'b &&Impl,
|
||||||
|
cache: &Cache,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
|
) -> Ordering {
|
||||||
|
let lhs = format!("{}", lhs.inner_impl().print(cache, false, tcx));
|
||||||
|
let rhs = format!("{}", rhs.inner_impl().print(cache, false, tcx));
|
||||||
|
|
||||||
// lhs and rhs are formatted as HTML, which may be unnecessary
|
// lhs and rhs are formatted as HTML, which may be unnecessary
|
||||||
compare_names(&lhs, &rhs)
|
compare_names(&lhs, &rhs)
|
||||||
|
@ -1247,8 +1255,8 @@ fn render_union(
|
||||||
it.name.as_ref().unwrap()
|
it.name.as_ref().unwrap()
|
||||||
);
|
);
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", g.print(cx.cache()));
|
write!(w, "{}", g.print(cx.cache(), cx.tcx()));
|
||||||
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true }.print(cx.cache()));
|
write!(w, "{}", print_where_clause(&g, cx.cache(), cx.tcx(), 0, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(w, " {{\n{}", tab);
|
write!(w, " {{\n{}", tab);
|
||||||
|
@ -1259,7 +1267,7 @@ fn render_union(
|
||||||
" {}{}: {},\n{}",
|
" {}{}: {},\n{}",
|
||||||
field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
|
field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
|
||||||
field.name.as_ref().unwrap(),
|
field.name.as_ref().unwrap(),
|
||||||
ty.print(cx.cache()),
|
ty.print(cx.cache(), cx.tcx()),
|
||||||
tab
|
tab
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1289,16 +1297,12 @@ fn render_struct(
|
||||||
it.name.as_ref().unwrap()
|
it.name.as_ref().unwrap()
|
||||||
);
|
);
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", g.print(cx.cache()))
|
write!(w, "{}", g.print(cx.cache(), cx.tcx()))
|
||||||
}
|
}
|
||||||
match ty {
|
match ty {
|
||||||
CtorKind::Fictive => {
|
CtorKind::Fictive => {
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(
|
write!(w, "{}", print_where_clause(g, cx.cache(), cx.tcx(), 0, true),)
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
WhereClause { gens: g, indent: 0, end_newline: true }.print(cx.cache())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
let mut has_visible_fields = false;
|
let mut has_visible_fields = false;
|
||||||
w.write_str(" {");
|
w.write_str(" {");
|
||||||
|
@ -1310,7 +1314,7 @@ fn render_struct(
|
||||||
tab,
|
tab,
|
||||||
field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
|
field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
|
||||||
field.name.as_ref().unwrap(),
|
field.name.as_ref().unwrap(),
|
||||||
ty.print(cx.cache())
|
ty.print(cx.cache(), cx.tcx()),
|
||||||
);
|
);
|
||||||
has_visible_fields = true;
|
has_visible_fields = true;
|
||||||
}
|
}
|
||||||
|
@ -1341,7 +1345,7 @@ fn render_struct(
|
||||||
w,
|
w,
|
||||||
"{}{}",
|
"{}{}",
|
||||||
field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
|
field.visibility.print_with_space(cx.tcx(), field.def_id, cx.cache()),
|
||||||
ty.print(cx.cache())
|
ty.print(cx.cache(), cx.tcx()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -1349,22 +1353,14 @@ fn render_struct(
|
||||||
}
|
}
|
||||||
w.write_str(")");
|
w.write_str(")");
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(
|
write!(w, "{}", print_where_clause(g, cx.cache(), cx.tcx(), 0, false),)
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
WhereClause { gens: g, indent: 0, end_newline: false }.print(cx.cache())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
w.write_str(";");
|
w.write_str(";");
|
||||||
}
|
}
|
||||||
CtorKind::Const => {
|
CtorKind::Const => {
|
||||||
// Needed for PhantomData.
|
// Needed for PhantomData.
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(
|
write!(w, "{}", print_where_clause(g, cx.cache(), cx.tcx(), 0, false),)
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
WhereClause { gens: g, indent: 0, end_newline: false }.print(cx.cache())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
w.write_str(";");
|
w.write_str(";");
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,7 +430,7 @@ pub(super) fn write_shared(
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(Implementor {
|
Some(Implementor {
|
||||||
text: imp.inner_impl().print(cx.cache(), false).to_string(),
|
text: imp.inner_impl().print(cx.cache(), false, cx.tcx()).to_string(),
|
||||||
synthetic: imp.inner_impl().synthetic,
|
synthetic: imp.inner_impl().synthetic,
|
||||||
types: collect_paths_for_type(imp.inner_impl().for_.clone(), cx.cache()),
|
types: collect_paths_for_type(imp.inner_impl().for_.clone(), cx.cache()),
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl JsonRenderer<'_> {
|
||||||
let clean::Item { span, name, attrs, kind, visibility, def_id } = item;
|
let clean::Item { span, name, attrs, kind, visibility, def_id } = item;
|
||||||
let inner = match *kind {
|
let inner = match *kind {
|
||||||
clean::StrippedItem(_) => return None,
|
clean::StrippedItem(_) => return None,
|
||||||
x => from_clean_item_kind(x, self.tcx, &name),
|
kind => from_clean_item_kind(kind, self.tcx, &name),
|
||||||
};
|
};
|
||||||
Some(Item {
|
Some(Item {
|
||||||
id: from_def_id(def_id),
|
id: from_def_id(def_id),
|
||||||
|
@ -87,59 +87,78 @@ impl JsonRenderer<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate trait FromWithTcx<T> {
|
||||||
|
fn from_tcx(f: T, tcx: TyCtxt<'_>) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
crate trait IntoWithTcx<T> {
|
||||||
|
fn into_tcx(self, tcx: TyCtxt<'_>) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, U> IntoWithTcx<U> for T
|
||||||
|
where
|
||||||
|
U: FromWithTcx<T>,
|
||||||
|
{
|
||||||
|
fn into_tcx(self, tcx: TyCtxt<'_>) -> U {
|
||||||
|
U::from_tcx(self, tcx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
crate fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
|
crate fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let rustc_attr::Deprecation { since, note, is_since_rustc_version: _, suggestion: _ } = deprecation;
|
let rustc_attr::Deprecation { since, note, is_since_rustc_version: _, suggestion: _ } = deprecation;
|
||||||
Deprecation { since: since.map(|s| s.to_string()), note: note.map(|s| s.to_string()) }
|
Deprecation { since: since.map(|s| s.to_string()), note: note.map(|s| s.to_string()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::GenericArgs> for GenericArgs {
|
impl FromWithTcx<clean::GenericArgs> for GenericArgs {
|
||||||
fn from(args: clean::GenericArgs) -> Self {
|
fn from_tcx(args: clean::GenericArgs, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::GenericArgs::*;
|
use clean::GenericArgs::*;
|
||||||
match args {
|
match args {
|
||||||
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
|
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
|
||||||
args: args.into_iter().map(Into::into).collect(),
|
args: args.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
bindings: bindings.into_iter().map(Into::into).collect(),
|
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
},
|
},
|
||||||
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
||||||
inputs: inputs.into_iter().map(Into::into).collect(),
|
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
output: output.map(Into::into),
|
output: output.map(|a| a.into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::GenericArg> for GenericArg {
|
impl FromWithTcx<clean::GenericArg> for GenericArg {
|
||||||
fn from(arg: clean::GenericArg) -> Self {
|
fn from_tcx(arg: clean::GenericArg, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::GenericArg::*;
|
use clean::GenericArg::*;
|
||||||
match arg {
|
match arg {
|
||||||
Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
|
Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
|
||||||
Type(t) => GenericArg::Type(t.into()),
|
Type(t) => GenericArg::Type(t.into_tcx(tcx)),
|
||||||
Const(c) => GenericArg::Const(c.into()),
|
Const(c) => GenericArg::Const(c.into_tcx(tcx)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Constant> for Constant {
|
impl FromWithTcx<clean::Constant> for Constant {
|
||||||
fn from(constant: clean::Constant) -> Self {
|
fn from_tcx(constant: clean::Constant, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Constant { type_, expr, value, is_literal } = constant;
|
let expr = constant.expr(tcx);
|
||||||
Constant { type_: type_.into(), expr, value, is_literal }
|
let value = constant.value(tcx);
|
||||||
|
let is_literal = constant.is_literal(tcx);
|
||||||
|
Constant { type_: constant.to_type().into_tcx(tcx), expr, value, is_literal }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::TypeBinding> for TypeBinding {
|
impl FromWithTcx<clean::TypeBinding> for TypeBinding {
|
||||||
fn from(binding: clean::TypeBinding) -> Self {
|
fn from_tcx(binding: clean::TypeBinding, tcx: TyCtxt<'_>) -> Self {
|
||||||
TypeBinding { name: binding.name.to_string(), binding: binding.kind.into() }
|
TypeBinding { name: binding.name.to_string(), binding: binding.kind.into_tcx(tcx) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::TypeBindingKind> for TypeBindingKind {
|
impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
|
||||||
fn from(kind: clean::TypeBindingKind) -> Self {
|
fn from_tcx(kind: clean::TypeBindingKind, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::TypeBindingKind::*;
|
use clean::TypeBindingKind::*;
|
||||||
match kind {
|
match kind {
|
||||||
Equality { ty } => TypeBindingKind::Equality(ty.into()),
|
Equality { ty } => TypeBindingKind::Equality(ty.into_tcx(tcx)),
|
||||||
Constraint { bounds } => {
|
Constraint { bounds } => {
|
||||||
TypeBindingKind::Constraint(bounds.into_iter().map(Into::into).collect())
|
TypeBindingKind::Constraint(bounds.into_iter().map(|a| a.into_tcx(tcx)).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,32 +171,32 @@ crate fn from_def_id(did: DefId) -> Id {
|
||||||
fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>, name: &Option<Symbol>) -> ItemEnum {
|
fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>, name: &Option<Symbol>) -> ItemEnum {
|
||||||
use clean::ItemKind::*;
|
use clean::ItemKind::*;
|
||||||
match item {
|
match item {
|
||||||
ModuleItem(m) => ItemEnum::Module(m.into()),
|
ModuleItem(m) => ItemEnum::Module(m.into_tcx(tcx)),
|
||||||
ImportItem(i) => ItemEnum::Import(i.into()),
|
ImportItem(i) => ItemEnum::Import(i.into_tcx(tcx)),
|
||||||
StructItem(s) => ItemEnum::Struct(s.into()),
|
StructItem(s) => ItemEnum::Struct(s.into_tcx(tcx)),
|
||||||
UnionItem(u) => ItemEnum::Union(u.into()),
|
UnionItem(u) => ItemEnum::Union(u.into_tcx(tcx)),
|
||||||
StructFieldItem(f) => ItemEnum::StructField(f.into()),
|
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
|
||||||
EnumItem(e) => ItemEnum::Enum(e.into()),
|
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
|
||||||
VariantItem(v) => ItemEnum::Variant(v.into()),
|
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
|
||||||
FunctionItem(f) => ItemEnum::Function(f.into()),
|
FunctionItem(f) => ItemEnum::Function(f.into_tcx(tcx)),
|
||||||
ForeignFunctionItem(f) => ItemEnum::Function(f.into()),
|
ForeignFunctionItem(f) => ItemEnum::Function(f.into_tcx(tcx)),
|
||||||
TraitItem(t) => ItemEnum::Trait(t.into()),
|
TraitItem(t) => ItemEnum::Trait(t.into_tcx(tcx)),
|
||||||
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into()),
|
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
|
||||||
MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true)),
|
MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, tcx)),
|
||||||
TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false)),
|
TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, tcx)),
|
||||||
ImplItem(i) => ItemEnum::Impl(i.into()),
|
ImplItem(i) => ItemEnum::Impl(i.into_tcx(tcx)),
|
||||||
StaticItem(s) => ItemEnum::Static(from_clean_static(s, tcx)),
|
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
|
||||||
ForeignStaticItem(s) => ItemEnum::Static(from_clean_static(s, tcx)),
|
ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
|
||||||
ForeignTypeItem => ItemEnum::ForeignType,
|
ForeignTypeItem => ItemEnum::ForeignType,
|
||||||
TypedefItem(t, _) => ItemEnum::Typedef(t.into()),
|
TypedefItem(t, _) => ItemEnum::Typedef(t.into_tcx(tcx)),
|
||||||
OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into()),
|
OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into_tcx(tcx)),
|
||||||
ConstantItem(c) => ItemEnum::Constant(c.into()),
|
ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)),
|
||||||
MacroItem(m) => ItemEnum::Macro(m.source),
|
MacroItem(m) => ItemEnum::Macro(m.source),
|
||||||
ProcMacroItem(m) => ItemEnum::ProcMacro(m.into()),
|
ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)),
|
||||||
AssocConstItem(t, s) => ItemEnum::AssocConst { type_: t.into(), default: s },
|
AssocConstItem(t, s) => ItemEnum::AssocConst { type_: t.into_tcx(tcx), default: s },
|
||||||
AssocTypeItem(g, t) => ItemEnum::AssocType {
|
AssocTypeItem(g, t) => ItemEnum::AssocType {
|
||||||
bounds: g.into_iter().map(Into::into).collect(),
|
bounds: g.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
default: t.map(Into::into),
|
default: t.map(|x| x.into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
StrippedItem(inner) => from_clean_item_kind(*inner, tcx, name),
|
StrippedItem(inner) => from_clean_item_kind(*inner, tcx, name),
|
||||||
PrimitiveItem(_) | KeywordItem(_) => {
|
PrimitiveItem(_) | KeywordItem(_) => {
|
||||||
|
@ -190,18 +209,18 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>, name: &Option<Sy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Module> for Module {
|
impl FromWithTcx<clean::Module> for Module {
|
||||||
fn from(module: clean::Module) -> Self {
|
fn from_tcx(module: clean::Module, _tcx: TyCtxt<'_>) -> Self {
|
||||||
Module { is_crate: module.is_crate, items: ids(module.items) }
|
Module { is_crate: module.is_crate, items: ids(module.items) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Struct> for Struct {
|
impl FromWithTcx<clean::Struct> for Struct {
|
||||||
fn from(struct_: clean::Struct) -> Self {
|
fn from_tcx(struct_: clean::Struct, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Struct { struct_type, generics, fields, fields_stripped } = struct_;
|
let clean::Struct { struct_type, generics, fields, fields_stripped } = struct_;
|
||||||
Struct {
|
Struct {
|
||||||
struct_type: from_ctor_kind(struct_type),
|
struct_type: from_ctor_kind(struct_type),
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
fields_stripped,
|
fields_stripped,
|
||||||
fields: ids(fields),
|
fields: ids(fields),
|
||||||
impls: Vec::new(), // Added in JsonRenderer::item
|
impls: Vec::new(), // Added in JsonRenderer::item
|
||||||
|
@ -209,11 +228,11 @@ impl From<clean::Struct> for Struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Union> for Union {
|
impl FromWithTcx<clean::Union> for Union {
|
||||||
fn from(struct_: clean::Union) -> Self {
|
fn from_tcx(struct_: clean::Union, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Union { generics, fields, fields_stripped } = struct_;
|
let clean::Union { generics, fields, fields_stripped } = struct_;
|
||||||
Union {
|
Union {
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
fields_stripped,
|
fields_stripped,
|
||||||
fields: ids(fields),
|
fields: ids(fields),
|
||||||
impls: Vec::new(), // Added in JsonRenderer::item
|
impls: Vec::new(), // Added in JsonRenderer::item
|
||||||
|
@ -247,74 +266,81 @@ crate fn from_fn_header(header: &rustc_hir::FnHeader) -> HashSet<Qualifiers> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Function> for Function {
|
impl FromWithTcx<clean::Function> for Function {
|
||||||
fn from(function: clean::Function) -> Self {
|
fn from_tcx(function: clean::Function, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Function { decl, generics, header } = function;
|
let clean::Function { decl, generics, header } = function;
|
||||||
Function {
|
Function {
|
||||||
decl: decl.into(),
|
decl: decl.into_tcx(tcx),
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
header: from_fn_header(&header),
|
header: from_fn_header(&header),
|
||||||
abi: header.abi.to_string(),
|
abi: header.abi.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Generics> for Generics {
|
impl FromWithTcx<clean::Generics> for Generics {
|
||||||
fn from(generics: clean::Generics) -> Self {
|
fn from_tcx(generics: clean::Generics, tcx: TyCtxt<'_>) -> Self {
|
||||||
Generics {
|
Generics {
|
||||||
params: generics.params.into_iter().map(Into::into).collect(),
|
params: generics.params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
where_predicates: generics.where_predicates.into_iter().map(Into::into).collect(),
|
where_predicates: generics
|
||||||
|
.where_predicates
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.into_tcx(tcx))
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::GenericParamDef> for GenericParamDef {
|
impl FromWithTcx<clean::GenericParamDef> for GenericParamDef {
|
||||||
fn from(generic_param: clean::GenericParamDef) -> Self {
|
fn from_tcx(generic_param: clean::GenericParamDef, tcx: TyCtxt<'_>) -> Self {
|
||||||
GenericParamDef { name: generic_param.name.to_string(), kind: generic_param.kind.into() }
|
GenericParamDef {
|
||||||
|
name: generic_param.name.to_string(),
|
||||||
|
kind: generic_param.kind.into_tcx(tcx),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::GenericParamDefKind> for GenericParamDefKind {
|
impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
|
||||||
fn from(kind: clean::GenericParamDefKind) -> Self {
|
fn from_tcx(kind: clean::GenericParamDefKind, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::GenericParamDefKind::*;
|
use clean::GenericParamDefKind::*;
|
||||||
match kind {
|
match kind {
|
||||||
Lifetime => GenericParamDefKind::Lifetime,
|
Lifetime => GenericParamDefKind::Lifetime,
|
||||||
Type { did: _, bounds, default, synthetic: _ } => GenericParamDefKind::Type {
|
Type { did: _, bounds, default, synthetic: _ } => GenericParamDefKind::Type {
|
||||||
bounds: bounds.into_iter().map(Into::into).collect(),
|
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
default: default.map(Into::into),
|
default: default.map(|x| x.into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
Const { did: _, ty } => GenericParamDefKind::Const(ty.into()),
|
Const { did: _, ty } => GenericParamDefKind::Const(ty.into_tcx(tcx)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::WherePredicate> for WherePredicate {
|
impl FromWithTcx<clean::WherePredicate> for WherePredicate {
|
||||||
fn from(predicate: clean::WherePredicate) -> Self {
|
fn from_tcx(predicate: clean::WherePredicate, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::WherePredicate::*;
|
use clean::WherePredicate::*;
|
||||||
match predicate {
|
match predicate {
|
||||||
BoundPredicate { ty, bounds } => WherePredicate::BoundPredicate {
|
BoundPredicate { ty, bounds } => WherePredicate::BoundPredicate {
|
||||||
ty: ty.into(),
|
ty: ty.into_tcx(tcx),
|
||||||
bounds: bounds.into_iter().map(Into::into).collect(),
|
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
},
|
},
|
||||||
RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
|
RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
|
||||||
lifetime: lifetime.0.to_string(),
|
lifetime: lifetime.0.to_string(),
|
||||||
bounds: bounds.into_iter().map(Into::into).collect(),
|
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
},
|
},
|
||||||
EqPredicate { lhs, rhs } => {
|
EqPredicate { lhs, rhs } => {
|
||||||
WherePredicate::EqPredicate { lhs: lhs.into(), rhs: rhs.into() }
|
WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::GenericBound> for GenericBound {
|
impl FromWithTcx<clean::GenericBound> for GenericBound {
|
||||||
fn from(bound: clean::GenericBound) -> Self {
|
fn from_tcx(bound: clean::GenericBound, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::GenericBound::*;
|
use clean::GenericBound::*;
|
||||||
match bound {
|
match bound {
|
||||||
TraitBound(clean::PolyTrait { trait_, generic_params }, modifier) => {
|
TraitBound(clean::PolyTrait { trait_, generic_params }, modifier) => {
|
||||||
GenericBound::TraitBound {
|
GenericBound::TraitBound {
|
||||||
trait_: trait_.into(),
|
trait_: trait_.into_tcx(tcx),
|
||||||
generic_params: generic_params.into_iter().map(Into::into).collect(),
|
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
modifier: from_trait_bound_modifier(modifier),
|
modifier: from_trait_bound_modifier(modifier),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,47 +358,47 @@ crate fn from_trait_bound_modifier(modifier: rustc_hir::TraitBoundModifier) -> T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Type> for Type {
|
impl FromWithTcx<clean::Type> for Type {
|
||||||
fn from(ty: clean::Type) -> Self {
|
fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::Type::*;
|
use clean::Type::*;
|
||||||
match ty {
|
match ty {
|
||||||
ResolvedPath { path, param_names, did, is_generic: _ } => Type::ResolvedPath {
|
ResolvedPath { path, param_names, did, is_generic: _ } => Type::ResolvedPath {
|
||||||
name: path.whole_name(),
|
name: path.whole_name(),
|
||||||
id: from_def_id(did),
|
id: from_def_id(did),
|
||||||
args: path.segments.last().map(|args| Box::new(args.clone().args.into())),
|
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
|
||||||
param_names: param_names
|
param_names: param_names
|
||||||
.map(|v| v.into_iter().map(Into::into).collect())
|
.map(|v| v.into_iter().map(|x| x.into_tcx(tcx)).collect())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
},
|
},
|
||||||
Generic(s) => Type::Generic(s.to_string()),
|
Generic(s) => Type::Generic(s.to_string()),
|
||||||
Primitive(p) => Type::Primitive(p.as_str().to_string()),
|
Primitive(p) => Type::Primitive(p.as_str().to_string()),
|
||||||
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into())),
|
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
|
||||||
Tuple(t) => Type::Tuple(t.into_iter().map(Into::into).collect()),
|
Tuple(t) => Type::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()),
|
||||||
Slice(t) => Type::Slice(Box::new((*t).into())),
|
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
|
||||||
Array(t, s) => Type::Array { type_: Box::new((*t).into()), len: s },
|
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s },
|
||||||
ImplTrait(g) => Type::ImplTrait(g.into_iter().map(Into::into).collect()),
|
ImplTrait(g) => Type::ImplTrait(g.into_iter().map(|x| x.into_tcx(tcx)).collect()),
|
||||||
Never => Type::Never,
|
Never => Type::Never,
|
||||||
Infer => Type::Infer,
|
Infer => Type::Infer,
|
||||||
RawPointer(mutability, type_) => Type::RawPointer {
|
RawPointer(mutability, type_) => Type::RawPointer {
|
||||||
mutable: mutability == ast::Mutability::Mut,
|
mutable: mutability == ast::Mutability::Mut,
|
||||||
type_: Box::new((*type_).into()),
|
type_: Box::new((*type_).into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
BorrowedRef { lifetime, mutability, type_ } => Type::BorrowedRef {
|
BorrowedRef { lifetime, mutability, type_ } => Type::BorrowedRef {
|
||||||
lifetime: lifetime.map(|l| l.0.to_string()),
|
lifetime: lifetime.map(|l| l.0.to_string()),
|
||||||
mutable: mutability == ast::Mutability::Mut,
|
mutable: mutability == ast::Mutability::Mut,
|
||||||
type_: Box::new((*type_).into()),
|
type_: Box::new((*type_).into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
QPath { name, self_type, trait_ } => Type::QualifiedPath {
|
QPath { name, self_type, trait_ } => Type::QualifiedPath {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
self_type: Box::new((*self_type).into()),
|
self_type: Box::new((*self_type).into_tcx(tcx)),
|
||||||
trait_: Box::new((*trait_).into()),
|
trait_: Box::new((*trait_).into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::BareFunctionDecl> for FunctionPointer {
|
impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
|
||||||
fn from(bare_decl: clean::BareFunctionDecl) -> Self {
|
fn from_tcx(bare_decl: clean::BareFunctionDecl, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
|
let clean::BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
|
||||||
FunctionPointer {
|
FunctionPointer {
|
||||||
header: if let rustc_hir::Unsafety::Unsafe = unsafety {
|
header: if let rustc_hir::Unsafety::Unsafe = unsafety {
|
||||||
|
@ -382,24 +408,24 @@ impl From<clean::BareFunctionDecl> for FunctionPointer {
|
||||||
} else {
|
} else {
|
||||||
HashSet::new()
|
HashSet::new()
|
||||||
},
|
},
|
||||||
generic_params: generic_params.into_iter().map(Into::into).collect(),
|
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
decl: decl.into(),
|
decl: decl.into_tcx(tcx),
|
||||||
abi: abi.to_string(),
|
abi: abi.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::FnDecl> for FnDecl {
|
impl FromWithTcx<clean::FnDecl> for FnDecl {
|
||||||
fn from(decl: clean::FnDecl) -> Self {
|
fn from_tcx(decl: clean::FnDecl, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::FnDecl { inputs, output, c_variadic, attrs: _ } = decl;
|
let clean::FnDecl { inputs, output, c_variadic, attrs: _ } = decl;
|
||||||
FnDecl {
|
FnDecl {
|
||||||
inputs: inputs
|
inputs: inputs
|
||||||
.values
|
.values
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|arg| (arg.name.to_string(), arg.type_.into()))
|
.map(|arg| (arg.name.to_string(), arg.type_.into_tcx(tcx)))
|
||||||
.collect(),
|
.collect(),
|
||||||
output: match output {
|
output: match output {
|
||||||
clean::FnRetTy::Return(t) => Some(t.into()),
|
clean::FnRetTy::Return(t) => Some(t.into_tcx(tcx)),
|
||||||
clean::FnRetTy::DefaultReturn => None,
|
clean::FnRetTy::DefaultReturn => None,
|
||||||
},
|
},
|
||||||
c_variadic,
|
c_variadic,
|
||||||
|
@ -407,22 +433,22 @@ impl From<clean::FnDecl> for FnDecl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Trait> for Trait {
|
impl FromWithTcx<clean::Trait> for Trait {
|
||||||
fn from(trait_: clean::Trait) -> Self {
|
fn from_tcx(trait_: clean::Trait, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Trait { unsafety, items, generics, bounds, is_auto } = trait_;
|
let clean::Trait { unsafety, items, generics, bounds, is_auto } = trait_;
|
||||||
Trait {
|
Trait {
|
||||||
is_auto,
|
is_auto,
|
||||||
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
|
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
|
||||||
items: ids(items),
|
items: ids(items),
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
bounds: bounds.into_iter().map(Into::into).collect(),
|
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
implementors: Vec::new(), // Added in JsonRenderer::item
|
implementors: Vec::new(), // Added in JsonRenderer::item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Impl> for Impl {
|
impl FromWithTcx<clean::Impl> for Impl {
|
||||||
fn from(impl_: clean::Impl) -> Self {
|
fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Impl {
|
let clean::Impl {
|
||||||
unsafety,
|
unsafety,
|
||||||
generics,
|
generics,
|
||||||
|
@ -436,37 +462,41 @@ impl From<clean::Impl> for Impl {
|
||||||
} = impl_;
|
} = impl_;
|
||||||
Impl {
|
Impl {
|
||||||
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
|
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
provided_trait_methods: provided_trait_methods
|
provided_trait_methods: provided_trait_methods
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
trait_: trait_.map(Into::into),
|
trait_: trait_.map(|x| x.into_tcx(tcx)),
|
||||||
for_: for_.into(),
|
for_: for_.into_tcx(tcx),
|
||||||
items: ids(items),
|
items: ids(items),
|
||||||
negative: negative_polarity,
|
negative: negative_polarity,
|
||||||
synthetic,
|
synthetic,
|
||||||
blanket_impl: blanket_impl.map(Into::into),
|
blanket_impl: blanket_impl.map(|x| x.into_tcx(tcx)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn from_function_method(function: clean::Function, has_body: bool) -> Method {
|
crate fn from_function_method(
|
||||||
|
function: clean::Function,
|
||||||
|
has_body: bool,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
|
) -> Method {
|
||||||
let clean::Function { header, decl, generics } = function;
|
let clean::Function { header, decl, generics } = function;
|
||||||
Method {
|
Method {
|
||||||
decl: decl.into(),
|
decl: decl.into_tcx(tcx),
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
header: from_fn_header(&header),
|
header: from_fn_header(&header),
|
||||||
abi: header.abi.to_string(),
|
abi: header.abi.to_string(),
|
||||||
has_body,
|
has_body,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Enum> for Enum {
|
impl FromWithTcx<clean::Enum> for Enum {
|
||||||
fn from(enum_: clean::Enum) -> Self {
|
fn from_tcx(enum_: clean::Enum, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Enum { variants, generics, variants_stripped } = enum_;
|
let clean::Enum { variants, generics, variants_stripped } = enum_;
|
||||||
Enum {
|
Enum {
|
||||||
generics: generics.into(),
|
generics: generics.into_tcx(tcx),
|
||||||
variants_stripped,
|
variants_stripped,
|
||||||
variants: ids(variants),
|
variants: ids(variants),
|
||||||
impls: Vec::new(), // Added in JsonRenderer::item
|
impls: Vec::new(), // Added in JsonRenderer::item
|
||||||
|
@ -474,8 +504,8 @@ impl From<clean::Enum> for Enum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::VariantStruct> for Struct {
|
impl FromWithTcx<clean::VariantStruct> for Struct {
|
||||||
fn from(struct_: clean::VariantStruct) -> Self {
|
fn from_tcx(struct_: clean::VariantStruct, _tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::VariantStruct { struct_type, fields, fields_stripped } = struct_;
|
let clean::VariantStruct { struct_type, fields, fields_stripped } = struct_;
|
||||||
Struct {
|
Struct {
|
||||||
struct_type: from_ctor_kind(struct_type),
|
struct_type: from_ctor_kind(struct_type),
|
||||||
|
@ -487,19 +517,19 @@ impl From<clean::VariantStruct> for Struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Variant> for Variant {
|
impl FromWithTcx<clean::Variant> for Variant {
|
||||||
fn from(variant: clean::Variant) -> Self {
|
fn from_tcx(variant: clean::Variant, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::Variant::*;
|
use clean::Variant::*;
|
||||||
match variant {
|
match variant {
|
||||||
CLike => Variant::Plain,
|
CLike => Variant::Plain,
|
||||||
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),
|
Tuple(t) => Variant::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()),
|
||||||
Struct(s) => Variant::Struct(ids(s.fields)),
|
Struct(s) => Variant::Struct(ids(s.fields)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Import> for Import {
|
impl FromWithTcx<clean::Import> for Import {
|
||||||
fn from(import: clean::Import) -> Self {
|
fn from_tcx(import: clean::Import, _tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::ImportKind::*;
|
use clean::ImportKind::*;
|
||||||
match import.kind {
|
match import.kind {
|
||||||
Simple(s) => Import {
|
Simple(s) => Import {
|
||||||
|
@ -518,8 +548,8 @@ impl From<clean::Import> for Import {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::ProcMacro> for ProcMacro {
|
impl FromWithTcx<clean::ProcMacro> for ProcMacro {
|
||||||
fn from(mac: clean::ProcMacro) -> Self {
|
fn from_tcx(mac: clean::ProcMacro, _tcx: TyCtxt<'_>) -> Self {
|
||||||
ProcMacro {
|
ProcMacro {
|
||||||
kind: from_macro_kind(mac.kind),
|
kind: from_macro_kind(mac.kind),
|
||||||
helpers: mac.helpers.iter().map(|x| x.to_string()).collect(),
|
helpers: mac.helpers.iter().map(|x| x.to_string()).collect(),
|
||||||
|
@ -536,41 +566,43 @@ crate fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::Typedef> for Typedef {
|
impl FromWithTcx<clean::Typedef> for Typedef {
|
||||||
fn from(typedef: clean::Typedef) -> Self {
|
fn from_tcx(typedef: clean::Typedef, tcx: TyCtxt<'_>) -> Self {
|
||||||
let clean::Typedef { type_, generics, item_type: _ } = typedef;
|
let clean::Typedef { type_, generics, item_type: _ } = typedef;
|
||||||
Typedef { type_: type_.into(), generics: generics.into() }
|
Typedef { type_: type_.into_tcx(tcx), generics: generics.into_tcx(tcx) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::OpaqueTy> for OpaqueTy {
|
impl FromWithTcx<clean::OpaqueTy> for OpaqueTy {
|
||||||
fn from(opaque: clean::OpaqueTy) -> Self {
|
fn from_tcx(opaque: clean::OpaqueTy, tcx: TyCtxt<'_>) -> Self {
|
||||||
OpaqueTy {
|
OpaqueTy {
|
||||||
bounds: opaque.bounds.into_iter().map(Into::into).collect(),
|
bounds: opaque.bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
generics: opaque.generics.into(),
|
generics: opaque.generics.into_tcx(tcx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_clean_static(stat: clean::Static, tcx: TyCtxt<'_>) -> Static {
|
impl FromWithTcx<clean::Static> for Static {
|
||||||
Static {
|
fn from_tcx(stat: clean::Static, tcx: TyCtxt<'_>) -> Self {
|
||||||
type_: stat.type_.into(),
|
Static {
|
||||||
mutable: stat.mutability == ast::Mutability::Mut,
|
type_: stat.type_.into_tcx(tcx),
|
||||||
expr: stat.expr.map(|e| print_const_expr(tcx, e)).unwrap_or_default(),
|
mutable: stat.mutability == ast::Mutability::Mut,
|
||||||
|
expr: stat.expr.map(|e| print_const_expr(tcx, e)).unwrap_or_default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::TraitAlias> for TraitAlias {
|
impl FromWithTcx<clean::TraitAlias> for TraitAlias {
|
||||||
fn from(alias: clean::TraitAlias) -> Self {
|
fn from_tcx(alias: clean::TraitAlias, tcx: TyCtxt<'_>) -> Self {
|
||||||
TraitAlias {
|
TraitAlias {
|
||||||
generics: alias.generics.into(),
|
generics: alias.generics.into_tcx(tcx),
|
||||||
params: alias.bounds.into_iter().map(Into::into).collect(),
|
params: alias.bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ItemType> for ItemKind {
|
impl FromWithTcx<ItemType> for ItemKind {
|
||||||
fn from(kind: ItemType) -> Self {
|
fn from_tcx(kind: ItemType, _tcx: TyCtxt<'_>) -> Self {
|
||||||
use ItemType::*;
|
use ItemType::*;
|
||||||
match kind {
|
match kind {
|
||||||
Module => ItemKind::Module,
|
Module => ItemKind::Module,
|
||||||
|
|
|
@ -24,7 +24,7 @@ use crate::error::Error;
|
||||||
use crate::formats::cache::Cache;
|
use crate::formats::cache::Cache;
|
||||||
use crate::formats::FormatRenderer;
|
use crate::formats::FormatRenderer;
|
||||||
use crate::html::render::cache::ExternalLocation;
|
use crate::html::render::cache::ExternalLocation;
|
||||||
use crate::json::conversions::from_def_id;
|
use crate::json::conversions::{from_def_id, IntoWithTcx};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
crate struct JsonRenderer<'tcx> {
|
crate struct JsonRenderer<'tcx> {
|
||||||
|
@ -108,7 +108,7 @@ impl JsonRenderer<'tcx> {
|
||||||
.last()
|
.last()
|
||||||
.map(Clone::clone),
|
.map(Clone::clone),
|
||||||
visibility: types::Visibility::Public,
|
visibility: types::Visibility::Public,
|
||||||
inner: types::ItemEnum::Trait(trait_item.clone().into()),
|
inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
|
||||||
span: None,
|
span: None,
|
||||||
docs: Default::default(),
|
docs: Default::default(),
|
||||||
links: Default::default(),
|
links: Default::default(),
|
||||||
|
@ -225,7 +225,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
||||||
.map(|(k, (path, kind))| {
|
.map(|(k, (path, kind))| {
|
||||||
(
|
(
|
||||||
from_def_id(k),
|
from_def_id(k),
|
||||||
types::ItemSummary { crate_id: k.krate.as_u32(), path, kind: kind.into() },
|
types::ItemSummary {
|
||||||
|
crate_id: k.krate.as_u32(),
|
||||||
|
path,
|
||||||
|
kind: kind.into_tcx(self.tcx),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
|
@ -216,8 +216,8 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
|
||||||
if let Some(ref tr) = impl_.trait_ {
|
if let Some(ref tr) = impl_.trait_ {
|
||||||
debug!(
|
debug!(
|
||||||
"impl {:#} for {:#} in {}",
|
"impl {:#} for {:#} in {}",
|
||||||
tr.print(&self.ctx.cache),
|
tr.print(&self.ctx.cache, self.ctx.tcx),
|
||||||
impl_.for_.print(&self.ctx.cache),
|
impl_.for_.print(&self.ctx.cache, self.ctx.tcx),
|
||||||
filename,
|
filename,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -228,7 +228,11 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
|
||||||
// inherent impls *can* be documented, and those docs show up, but in most
|
// inherent impls *can* be documented, and those docs show up, but in most
|
||||||
// cases it doesn't make sense, as all methods on a type are in one single
|
// cases it doesn't make sense, as all methods on a type are in one single
|
||||||
// impl block
|
// impl block
|
||||||
debug!("impl {:#} in {}", impl_.for_.print(&self.ctx.cache), filename);
|
debug!(
|
||||||
|
"impl {:#} in {}",
|
||||||
|
impl_.for_.print(&self.ctx.cache, self.ctx.tcx),
|
||||||
|
filename
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue