提交 bf0cc900 编写于 作者: N Noah Lev

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.
上级 7fb13062
......@@ -14,9 +14,7 @@
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;
......
......@@ -1451,24 +1451,6 @@ impl FnRetTy {
#[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 @@ fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
};
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))
}
}
......
......@@ -6,7 +6,7 @@
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;
......
......@@ -6,9 +6,7 @@
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;
......
......@@ -57,7 +57,7 @@
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;
......
......@@ -21,7 +21,7 @@
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;
......
......@@ -2,7 +2,7 @@
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> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册