Skip to content

Commit bf0cc90

Browse files
committed
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.
1 parent 7fb1306 commit bf0cc90

File tree

7 files changed

+20
-32
lines changed

7 files changed

+20
-32
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
1414
use rustc_span::hygiene::MacroKind;
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616

17-
use crate::clean::{
18-
self, utils, Attributes, AttributesExt, GetDefId, ItemId, NestedAttributesExt, Type,
19-
};
17+
use crate::clean::{self, utils, Attributes, AttributesExt, ItemId, NestedAttributesExt, Type};
2018
use crate::core::DocContext;
2119
use crate::formats::item_type::ItemType;
2220

src/librustdoc/clean/types.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,24 +1451,6 @@ crate enum Type {
14511451
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
14521452
rustc_data_structures::static_assert_size!(Type, 72);
14531453

1454-
crate trait GetDefId {
1455-
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
1456-
/// This will return [`None`] when called on a primitive [`clean::Type`].
1457-
/// Use [`Self::def_id_full`] if you want to include primitives.
1458-
///
1459-
/// [`clean`]: crate::clean
1460-
/// [`clean::Type`]: crate::clean::Type
1461-
// FIXME: get rid of this function and always use `def_id_full`
1462-
fn def_id(&self) -> Option<DefId>;
1463-
1464-
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
1465-
///
1466-
/// See [`Self::def_id`] for more.
1467-
///
1468-
/// [clean]: crate::clean
1469-
fn def_id_full(&self, cache: &Cache) -> Option<DefId>;
1470-
}
1471-
14721454
impl Type {
14731455
crate fn primitive_type(&self) -> Option<PrimitiveType> {
14741456
match *self {
@@ -1549,14 +1531,24 @@ impl Type {
15491531
};
15501532
cache.and_then(|c| Primitive(t).def_id_full(c))
15511533
}
1552-
}
15531534

1554-
impl GetDefId for Type {
1555-
fn def_id(&self) -> Option<DefId> {
1535+
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
1536+
/// This will return [`None`] when called on a primitive [`clean::Type`].
1537+
/// Use [`Self::def_id_full`] if you want to include primitives.
1538+
///
1539+
/// [`clean`]: crate::clean
1540+
/// [`clean::Type`]: crate::clean::Type
1541+
// FIXME: get rid of this function and always use `def_id_full`
1542+
crate fn def_id(&self) -> Option<DefId> {
15561543
self.inner_def_id(None)
15571544
}
15581545

1559-
fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
1546+
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
1547+
///
1548+
/// See [`Self::def_id`] for more.
1549+
///
1550+
/// [clean]: crate::clean
1551+
crate fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
15601552
self.inner_def_id(Some(cache))
15611553
}
15621554
}

src/librustdoc/formats/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::middle::privacy::AccessLevels;
66
use rustc_middle::ty::TyCtxt;
77
use rustc_span::symbol::sym;
88

9-
use crate::clean::{self, GetDefId, ItemId, PrimitiveType};
9+
use crate::clean::{self, ItemId, PrimitiveType};
1010
use crate::config::RenderOptions;
1111
use crate::fold::DocFolder;
1212
use crate::formats::item_type::ItemType;

src/librustdoc/html/render/cache.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use rustc_span::symbol::Symbol;
66
use serde::ser::{Serialize, SerializeStruct, Serializer};
77

88
use crate::clean;
9-
use crate::clean::types::{
10-
FnDecl, FnRetTy, GenericBound, Generics, GetDefId, Type, WherePredicate,
11-
};
9+
use crate::clean::types::{FnDecl, FnRetTy, GenericBound, Generics, Type, WherePredicate};
1210
use crate::formats::cache::Cache;
1311
use crate::formats::item_type::ItemType;
1412
use crate::html::markdown::short_markdown_summary;

src/librustdoc/html/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
5757
use serde::ser::SerializeSeq;
5858
use serde::{Serialize, Serializer};
5959

60-
use crate::clean::{self, GetDefId, ItemId, RenderedLink, SelfTy};
60+
use crate::clean::{self, ItemId, RenderedLink, SelfTy};
6161
use crate::docfs::PathError;
6262
use crate::error::Error;
6363
use crate::formats::cache::Cache;

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{
2121
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context,
2222
ImplRenderingParameters,
2323
};
24-
use crate::clean::{self, GetDefId};
24+
use crate::clean::{self};
2525
use crate::formats::item_type::ItemType;
2626
use crate::formats::{AssocItemRender, Impl, RenderMode};
2727
use crate::html::escape::Escape;

src/librustdoc/passes/stripper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_hir::def_id::DefId;
22
use rustc_middle::middle::privacy::AccessLevels;
33
use std::mem;
44

5-
use crate::clean::{self, GetDefId, Item, ItemIdSet};
5+
use crate::clean::{self, Item, ItemIdSet};
66
use crate::fold::{strip_item, DocFolder};
77

88
crate struct Stripper<'a> {

0 commit comments

Comments
 (0)