Remove temporary GetDefId
impl for Path
This commit is contained in:
parent
4128a3dc1f
commit
a83112fe3e
8 changed files with 63 additions and 93 deletions
|
@ -447,7 +447,7 @@ crate fn build_impl(
|
||||||
};
|
};
|
||||||
let polarity = tcx.impl_polarity(did);
|
let polarity = tcx.impl_polarity(did);
|
||||||
let trait_ = associated_trait.clean(cx);
|
let trait_ = associated_trait.clean(cx);
|
||||||
if trait_.def_id() == tcx.lang_items().deref_trait() {
|
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
|
||||||
super::build_deref_target_impls(cx, &trait_items, ret);
|
super::build_deref_target_impls(cx, &trait_items, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@ crate fn build_impl(
|
||||||
let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
|
let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
|
||||||
trace!("merged_attrs={:?}", merged_attrs);
|
trace!("merged_attrs={:?}", merged_attrs);
|
||||||
|
|
||||||
trace!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());
|
trace!("build_impl: impl {:?} for {:?}", trait_.as_ref().map(|t| t.def_id()), for_.def_id());
|
||||||
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
|
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
|
||||||
did,
|
did,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -1883,7 +1883,7 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>
|
||||||
|
|
||||||
// If this impl block is an implementation of the Deref trait, then we
|
// If this impl block is an implementation of the Deref trait, then we
|
||||||
// need to try inlining the target's inherent impl blocks as well.
|
// need to try inlining the target's inherent impl blocks as well.
|
||||||
if trait_.def_id() == tcx.lang_items().deref_trait() {
|
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
|
||||||
build_deref_target_impls(cx, &items, &mut ret);
|
build_deref_target_impls(cx, &items, &mut ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1122,7 +1122,7 @@ impl GenericBound {
|
||||||
crate fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
|
crate fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
|
||||||
use rustc_hir::TraitBoundModifier as TBM;
|
use rustc_hir::TraitBoundModifier as TBM;
|
||||||
if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self {
|
if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self {
|
||||||
if trait_.def_id() == cx.tcx.lang_items().sized_trait() {
|
if Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1942,6 +1942,10 @@ crate struct Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
|
crate fn def_id(&self) -> DefId {
|
||||||
|
self.res.def_id()
|
||||||
|
}
|
||||||
|
|
||||||
crate fn last(&self) -> Symbol {
|
crate fn last(&self) -> Symbol {
|
||||||
self.segments.last().expect("segments were empty").name
|
self.segments.last().expect("segments were empty").name
|
||||||
}
|
}
|
||||||
|
@ -1992,17 +1996,6 @@ impl Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this is temporary
|
|
||||||
impl GetDefId for Path {
|
|
||||||
fn def_id(&self) -> Option<DefId> {
|
|
||||||
Some(self.res.def_id())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn def_id_full(&self, _: &Cache) -> Option<DefId> {
|
|
||||||
self.def_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
crate enum GenericArg {
|
crate enum GenericArg {
|
||||||
Lifetime(Lifetime),
|
Lifetime(Lifetime),
|
||||||
|
@ -2155,7 +2148,8 @@ crate struct Impl {
|
||||||
impl Impl {
|
impl Impl {
|
||||||
crate fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> {
|
crate fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> {
|
||||||
self.trait_
|
self.trait_
|
||||||
.def_id()
|
.as_ref()
|
||||||
|
.map(|t| t.def_id())
|
||||||
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect())
|
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,9 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
// masked crate then remove it completely.
|
// masked crate then remove it completely.
|
||||||
if let clean::ImplItem(ref i) = *item.kind {
|
if let clean::ImplItem(ref i) = *item.kind {
|
||||||
if self.cache.masked_crates.contains(&item.def_id.krate())
|
if self.cache.masked_crates.contains(&item.def_id.krate())
|
||||||
|| i.trait_.def_id().map_or(false, |d| self.cache.masked_crates.contains(&d.krate))
|
|| i.trait_
|
||||||
|
.as_ref()
|
||||||
|
.map_or(false, |t| self.cache.masked_crates.contains(&t.def_id().krate))
|
||||||
|| i.for_.def_id().map_or(false, |d| self.cache.masked_crates.contains(&d.krate))
|
|| i.for_.def_id().map_or(false, |d| self.cache.masked_crates.contains(&d.krate))
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
|
@ -221,11 +223,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
|
|
||||||
// Collect all the implementors of traits.
|
// Collect all the implementors of traits.
|
||||||
if let clean::ImplItem(ref i) = *item.kind {
|
if let clean::ImplItem(ref i) = *item.kind {
|
||||||
if let Some(did) = i.trait_.def_id() {
|
if let Some(trait_) = &i.trait_ {
|
||||||
if i.blanket_impl.is_none() {
|
if i.blanket_impl.is_none() {
|
||||||
self.cache
|
self.cache
|
||||||
.implementors
|
.implementors
|
||||||
.entry(did)
|
.entry(trait_.def_id())
|
||||||
.or_default()
|
.or_default()
|
||||||
.push(Impl { impl_item: item.clone() });
|
.push(Impl { impl_item: item.clone() });
|
||||||
}
|
}
|
||||||
|
@ -400,12 +402,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
clean::DynTrait(ref bounds, _)
|
clean::DynTrait(ref bounds, _)
|
||||||
| clean::BorrowedRef { type_: box clean::DynTrait(ref bounds, _), .. } => {
|
| clean::BorrowedRef { type_: box clean::DynTrait(ref bounds, _), .. } => {
|
||||||
if let Some(did) = bounds[0].trait_.def_id() {
|
self.cache.parent_stack.push(bounds[0].trait_.def_id());
|
||||||
self.cache.parent_stack.push(did);
|
true
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ref t => {
|
ref t => {
|
||||||
let prim_did = t
|
let prim_did = t
|
||||||
|
@ -439,9 +437,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
clean::DynTrait(ref bounds, _)
|
clean::DynTrait(ref bounds, _)
|
||||||
| clean::BorrowedRef { type_: box clean::DynTrait(ref bounds, _), .. } => {
|
| clean::BorrowedRef { type_: box clean::DynTrait(ref bounds, _), .. } => {
|
||||||
if let Some(did) = bounds[0].trait_.def_id() {
|
dids.insert(bounds[0].trait_.def_id());
|
||||||
dids.insert(did);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ref t => {
|
ref t => {
|
||||||
let did = t
|
let did = t
|
||||||
|
|
|
@ -7,8 +7,6 @@ use rustc_hir::def_id::DefId;
|
||||||
crate use renderer::{run_format, FormatRenderer};
|
crate use renderer::{run_format, FormatRenderer};
|
||||||
|
|
||||||
use crate::clean;
|
use crate::clean;
|
||||||
use crate::clean::types::GetDefId;
|
|
||||||
use crate::formats::cache::Cache;
|
|
||||||
|
|
||||||
/// Specifies whether rendering directly implemented trait items or ones from a certain Deref
|
/// Specifies whether rendering directly implemented trait items or ones from a certain Deref
|
||||||
/// impl.
|
/// impl.
|
||||||
|
@ -40,10 +38,6 @@ impl Impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn trait_did(&self) -> Option<DefId> {
|
crate fn trait_did(&self) -> Option<DefId> {
|
||||||
self.inner_impl().trait_.def_id()
|
self.inner_impl().trait_.as_ref().map(|t| t.def_id())
|
||||||
}
|
|
||||||
|
|
||||||
crate fn trait_did_full(&self, cache: &Cache) -> Option<DefId> {
|
|
||||||
self.inner_impl().trait_.def_id_full(cache)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -687,18 +687,12 @@ fn short_item_info(
|
||||||
|
|
||||||
// Render the list of items inside one of the sections "Trait Implementations",
|
// Render the list of items inside one of the sections "Trait Implementations",
|
||||||
// "Auto Trait Implementations," "Blanket Trait Implementations" (on struct/enum pages).
|
// "Auto Trait Implementations," "Blanket Trait Implementations" (on struct/enum pages).
|
||||||
fn render_impls(
|
fn render_impls(cx: &Context<'_>, w: &mut Buffer, impls: &[&&Impl], containing_item: &clean::Item) {
|
||||||
cx: &Context<'_>,
|
|
||||||
w: &mut Buffer,
|
|
||||||
traits: &[&&Impl],
|
|
||||||
containing_item: &clean::Item,
|
|
||||||
) {
|
|
||||||
let cache = cx.cache();
|
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
let mut impls = traits
|
let mut rendered_impls = impls
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
let did = i.trait_did_full(cache).unwrap();
|
let did = i.trait_did().unwrap();
|
||||||
let provided_trait_methods = i.inner_impl().provided_trait_methods(tcx);
|
let provided_trait_methods = i.inner_impl().provided_trait_methods(tcx);
|
||||||
let assoc_link = AssocItemLink::GotoSource(did.into(), &provided_trait_methods);
|
let assoc_link = AssocItemLink::GotoSource(did.into(), &provided_trait_methods);
|
||||||
let mut buffer = if w.is_for_html() { Buffer::html() } else { Buffer::new() };
|
let mut buffer = if w.is_for_html() { Buffer::html() } else { Buffer::new() };
|
||||||
|
@ -722,8 +716,8 @@ fn render_impls(
|
||||||
buffer.into_inner()
|
buffer.into_inner()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
impls.sort();
|
rendered_impls.sort();
|
||||||
w.write_str(&impls.join(""));
|
w.write_str(&rendered_impls.join(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn naive_assoc_href(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>) -> String {
|
fn naive_assoc_href(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>) -> String {
|
||||||
|
@ -1068,13 +1062,11 @@ fn render_assoc_items(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if !traits.is_empty() {
|
if !traits.is_empty() {
|
||||||
let deref_impl = traits.iter().find(|t| {
|
let deref_impl =
|
||||||
t.inner_impl().trait_.def_id_full(cache) == cx.tcx().lang_items().deref_trait()
|
traits.iter().find(|t| t.trait_did() == cx.tcx().lang_items().deref_trait());
|
||||||
});
|
|
||||||
if let Some(impl_) = deref_impl {
|
if let Some(impl_) = deref_impl {
|
||||||
let has_deref_mut = traits.iter().any(|t| {
|
let has_deref_mut =
|
||||||
t.inner_impl().trait_.def_id_full(cache) == cx.tcx().lang_items().deref_mut_trait()
|
traits.iter().any(|t| t.trait_did() == cx.tcx().lang_items().deref_mut_trait());
|
||||||
});
|
|
||||||
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut);
|
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut);
|
||||||
}
|
}
|
||||||
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) =
|
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) =
|
||||||
|
@ -1192,45 +1184,39 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
|
||||||
|
|
||||||
fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
|
fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
|
||||||
let mut out = Buffer::html();
|
let mut out = Buffer::html();
|
||||||
let mut trait_ = String::new();
|
|
||||||
|
|
||||||
if let Some(did) = decl.output.def_id_full(cx.cache()) {
|
if let Some(did) = decl.output.def_id_full(cx.cache()) {
|
||||||
if let Some(impls) = cx.cache().impls.get(&did) {
|
if let Some(impls) = cx.cache().impls.get(&did) {
|
||||||
for i in impls {
|
for i in impls {
|
||||||
let impl_ = i.inner_impl();
|
let impl_ = i.inner_impl();
|
||||||
if impl_.trait_.def_id().map_or(false, |d| {
|
if let Some(trait_) = &impl_.trait_ {
|
||||||
cx.cache().traits.get(&d).map(|t| t.is_notable).unwrap_or(false)
|
let trait_did = trait_.def_id();
|
||||||
}) {
|
|
||||||
if out.is_empty() {
|
if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable) {
|
||||||
|
if out.is_empty() {
|
||||||
|
write!(
|
||||||
|
&mut out,
|
||||||
|
"<div class=\"notable\">Notable traits for {}</div>\
|
||||||
|
<code class=\"content\">",
|
||||||
|
impl_.for_.print(cx)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//use the "where" class here to make it small
|
||||||
write!(
|
write!(
|
||||||
&mut out,
|
&mut out,
|
||||||
"<div class=\"notable\">Notable traits for {}</div>\
|
"<span class=\"where fmt-newline\">{}</span>",
|
||||||
<code class=\"content\">",
|
impl_.print(false, cx)
|
||||||
impl_.for_.print(cx)
|
|
||||||
);
|
);
|
||||||
trait_.push_str(&impl_.for_.print(cx).to_string());
|
for it in &impl_.items {
|
||||||
}
|
if let clean::TypedefItem(ref tydef, _) = *it.kind {
|
||||||
|
out.push_str("<span class=\"where fmt-newline\"> ");
|
||||||
//use the "where" class here to make it small
|
let empty_set = FxHashSet::default();
|
||||||
write!(
|
let src_link =
|
||||||
&mut out,
|
AssocItemLink::GotoSource(trait_did.into(), &empty_set);
|
||||||
"<span class=\"where fmt-newline\">{}</span>",
|
assoc_type(&mut out, it, &[], Some(&tydef.type_), src_link, "", cx);
|
||||||
impl_.print(false, cx)
|
out.push_str(";</span>");
|
||||||
);
|
}
|
||||||
let t_did = impl_.trait_.def_id_full(cx.cache()).unwrap();
|
|
||||||
for it in &impl_.items {
|
|
||||||
if let clean::TypedefItem(ref tydef, _) = *it.kind {
|
|
||||||
out.push_str("<span class=\"where fmt-newline\"> ");
|
|
||||||
assoc_type(
|
|
||||||
&mut out,
|
|
||||||
it,
|
|
||||||
&[],
|
|
||||||
Some(&tydef.type_),
|
|
||||||
AssocItemLink::GotoSource(t_did.into(), &FxHashSet::default()),
|
|
||||||
"",
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
out.push_str(";</span>");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1273,7 +1259,7 @@ fn render_impl(
|
||||||
) {
|
) {
|
||||||
let cache = cx.cache();
|
let cache = cx.cache();
|
||||||
let traits = &cache.traits;
|
let traits = &cache.traits;
|
||||||
let trait_ = i.trait_did_full(cache).map(|did| &traits[&did]);
|
let trait_ = i.trait_did().map(|did| &traits[&did]);
|
||||||
let mut close_tags = String::new();
|
let mut close_tags = String::new();
|
||||||
|
|
||||||
// For trait implementations, the `interesting` output contains all methods that have doc
|
// For trait implementations, the `interesting` output contains all methods that have doc
|
||||||
|
@ -1503,7 +1489,7 @@ fn render_impl(
|
||||||
if i.items.iter().any(|m| m.name == n) {
|
if i.items.iter().any(|m| m.name == n) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let did = i.trait_.as_ref().unwrap().def_id_full(cx.cache()).unwrap();
|
let did = i.trait_.as_ref().unwrap().def_id();
|
||||||
let provided_methods = i.provided_trait_methods(cx.tcx());
|
let provided_methods = i.provided_trait_methods(cx.tcx());
|
||||||
let assoc_link = AssocItemLink::GotoSource(did.into(), &provided_methods);
|
let assoc_link = AssocItemLink::GotoSource(did.into(), &provided_methods);
|
||||||
|
|
||||||
|
@ -1887,9 +1873,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.iter().any(|i| i.inner_impl().trait_.is_some()) {
|
if v.iter().any(|i| i.inner_impl().trait_.is_some()) {
|
||||||
if let Some(impl_) = v.iter().filter(|i| i.inner_impl().trait_.is_some()).find(|i| {
|
if let Some(impl_) =
|
||||||
i.inner_impl().trait_.def_id_full(cache) == cx.tcx().lang_items().deref_trait()
|
v.iter().find(|i| i.trait_did() == cx.tcx().lang_items().deref_trait())
|
||||||
}) {
|
{
|
||||||
sidebar_deref_methods(cx, out, impl_, v);
|
sidebar_deref_methods(cx, out, impl_, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1987,9 +1973,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let deref_mut = v.iter().filter(|i| i.inner_impl().trait_.is_some()).any(|i| {
|
let deref_mut = v.iter().any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
|
||||||
i.inner_impl().trait_.def_id_full(c) == cx.tcx().lang_items().deref_mut_trait()
|
|
||||||
});
|
|
||||||
let inner_impl = target
|
let inner_impl = target
|
||||||
.def_id_full(c)
|
.def_id_full(c)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
|
|
|
@ -57,7 +57,9 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
|
||||||
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
|
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
|
||||||
for it in &new_items {
|
for it in &new_items {
|
||||||
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
|
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
|
||||||
if cleaner.keep_impl(for_) && trait_.def_id() == cx.tcx.lang_items().deref_trait() {
|
if cleaner.keep_impl(for_)
|
||||||
|
&& trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait()
|
||||||
|
{
|
||||||
let target = items
|
let target = items
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|item| match *item.kind {
|
.find_map(|item| match *item.kind {
|
||||||
|
|
|
@ -134,7 +134,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(did) = imp.trait_.def_id() {
|
if let Some(did) = imp.trait_.as_ref().map(|t| t.def_id()) {
|
||||||
if did.is_local() && !self.retained.contains(&did.into()) {
|
if did.is_local() && !self.retained.contains(&did.into()) {
|
||||||
debug!("ImplStripper: impl item for stripped trait; removing");
|
debug!("ImplStripper: impl item for stripped trait; removing");
|
||||||
return None;
|
return None;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue