1
Fork 0

Replace GetDefId with inherent methods

Now that it's only implemented for `Type`, using inherent methods
instead means that imports are no longer necessary. Also, `GetDefId` is
only meant to be used with `Type`, so it shouldn't be a trait.
This commit is contained in:
Noah Lev 2021-10-21 20:05:38 -07:00
parent 7fb1306275
commit bf0cc90050
7 changed files with 20 additions and 32 deletions

View file

@ -14,9 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};
use crate::clean::{
self, utils, Attributes, AttributesExt, GetDefId, ItemId, NestedAttributesExt, Type,
};
use crate::clean::{self, utils, Attributes, AttributesExt, ItemId, NestedAttributesExt, Type};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;

View file

@ -1451,24 +1451,6 @@ crate enum Type {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Type, 72);
crate trait GetDefId {
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
/// This will return [`None`] when called on a primitive [`clean::Type`].
/// Use [`Self::def_id_full`] if you want to include primitives.
///
/// [`clean`]: crate::clean
/// [`clean::Type`]: crate::clean::Type
// FIXME: get rid of this function and always use `def_id_full`
fn def_id(&self) -> Option<DefId>;
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
///
/// See [`Self::def_id`] for more.
///
/// [clean]: crate::clean
fn def_id_full(&self, cache: &Cache) -> Option<DefId>;
}
impl Type {
crate fn primitive_type(&self) -> Option<PrimitiveType> {
match *self {
@ -1549,14 +1531,24 @@ impl Type {
};
cache.and_then(|c| Primitive(t).def_id_full(c))
}
}
impl GetDefId for Type {
fn def_id(&self) -> Option<DefId> {
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
/// This will return [`None`] when called on a primitive [`clean::Type`].
/// Use [`Self::def_id_full`] if you want to include primitives.
///
/// [`clean`]: crate::clean
/// [`clean::Type`]: crate::clean::Type
// FIXME: get rid of this function and always use `def_id_full`
crate fn def_id(&self) -> Option<DefId> {
self.inner_def_id(None)
}
fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
///
/// See [`Self::def_id`] for more.
///
/// [clean]: crate::clean
crate fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
self.inner_def_id(Some(cache))
}
}

View file

@ -6,7 +6,7 @@ use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;
use crate::clean::{self, GetDefId, ItemId, PrimitiveType};
use crate::clean::{self, ItemId, PrimitiveType};
use crate::config::RenderOptions;
use crate::fold::DocFolder;
use crate::formats::item_type::ItemType;

View file

@ -6,9 +6,7 @@ use rustc_span::symbol::Symbol;
use serde::ser::{Serialize, SerializeStruct, Serializer};
use crate::clean;
use crate::clean::types::{
FnDecl, FnRetTy, GenericBound, Generics, GetDefId, Type, WherePredicate,
};
use crate::clean::types::{FnDecl, FnRetTy, GenericBound, Generics, Type, WherePredicate};
use crate::formats::cache::Cache;
use crate::formats::item_type::ItemType;
use crate::html::markdown::short_markdown_summary;

View file

@ -57,7 +57,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use crate::clean::{self, GetDefId, ItemId, RenderedLink, SelfTy};
use crate::clean::{self, ItemId, RenderedLink, SelfTy};
use crate::docfs::PathError;
use crate::error::Error;
use crate::formats::cache::Cache;

View file

@ -21,7 +21,7 @@ use super::{
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context,
ImplRenderingParameters,
};
use crate::clean::{self, GetDefId};
use crate::clean::{self};
use crate::formats::item_type::ItemType;
use crate::formats::{AssocItemRender, Impl, RenderMode};
use crate::html::escape::Escape;

View file

@ -2,7 +2,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::middle::privacy::AccessLevels;
use std::mem;
use crate::clean::{self, GetDefId, Item, ItemIdSet};
use crate::clean::{self, Item, ItemIdSet};
use crate::fold::{strip_item, DocFolder};
crate struct Stripper<'a> {