summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/formats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:56 +0000
commit018c4950b9406055dec02ef0fb52f132e2bb1e2c (patch)
treea835ebdf2088ef88fa681f8fad45f09922c1ae9a /src/librustdoc/formats
parentAdding debian version 1.75.0+dfsg1-5. (diff)
downloadrustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.tar.xz
rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/formats')
-rw-r--r--src/librustdoc/formats/cache.rs36
-rw-r--r--src/librustdoc/formats/item_type.rs56
-rw-r--r--src/librustdoc/formats/mod.rs15
-rw-r--r--src/librustdoc/formats/renderer.rs8
4 files changed, 57 insertions, 58 deletions
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index abff77253..9802097ea 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -230,14 +230,14 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// If the impl is from a masked crate or references something from a
// masked crate then remove it completely.
- if let clean::ImplItem(ref i) = *item.kind &&
- (self.cache.masked_crates.contains(&item.item_id.krate())
+ if let clean::ImplItem(ref i) = *item.kind
+ && (self.cache.masked_crates.contains(&item.item_id.krate())
|| i.trait_
.as_ref()
- .map_or(false, |t| is_from_private_dep(self.tcx, self.cache, t.def_id()))
+ .is_some_and(|t| is_from_private_dep(self.tcx, self.cache, t.def_id()))
|| i.for_
.def_id(self.cache)
- .map_or(false, |d| is_from_private_dep(self.tcx, self.cache, d)))
+ .is_some_and(|d| is_from_private_dep(self.tcx, self.cache, d)))
{
return None;
}
@@ -249,9 +249,9 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
}
// Collect all the implementors of traits.
- if let clean::ImplItem(ref i) = *item.kind &&
- let Some(trait_) = &i.trait_ &&
- !i.kind.is_blanket()
+ if let clean::ImplItem(ref i) = *item.kind
+ && let Some(trait_) = &i.trait_
+ && !i.kind.is_blanket()
{
self.cache
.implementors
@@ -264,8 +264,9 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
if let Some(s) = item.name.or_else(|| {
if item.is_stripped() {
None
- } else if let clean::ImportItem(ref i) = *item.kind &&
- let clean::ImportKind::Simple(s) = i.kind {
+ } else if let clean::ImportItem(ref i) = *item.kind
+ && let clean::ImportKind::Simple(s) = i.kind
+ {
Some(s)
} else {
None
@@ -278,7 +279,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
.cache
.parent_stack
.last()
- .map_or(false, |parent| parent.is_trait_impl()) =>
+ .is_some_and(|parent| parent.is_trait_impl()) =>
{
// skip associated items in trait impls
((None, None), false)
@@ -340,7 +341,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// A crate has a module at its root, containing all items,
// which should not be indexed. The crate-item itself is
// inserted later on when serializing the search-index.
- if item.item_id.as_def_id().map_or(false, |idx| !idx.is_crate_root())
+ if item.item_id.as_def_id().is_some_and(|idx| !idx.is_crate_root())
&& let ty = item.type_()
&& (ty != ItemType::StructField
|| u16::from_str_radix(s.as_str(), 10).is_err())
@@ -357,7 +358,9 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
desc,
parent,
parent_idx: None,
- impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) = self.cache.parent_stack.last() {
+ impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) =
+ self.cache.parent_stack.last()
+ {
item_id.as_def_id()
} else {
None
@@ -366,6 +369,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
&item,
self.tcx,
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
+ parent,
self.cache,
),
aliases: item.attrs.get_doc_aliases(),
@@ -493,9 +497,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
clean::Type::Path { ref path }
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
dids.insert(path.def_id());
- if let Some(generics) = path.generics() &&
- let ty::Adt(adt, _) = self.tcx.type_of(path.def_id()).instantiate_identity().kind() &&
- adt.is_fundamental() {
+ if let Some(generics) = path.generics()
+ && let ty::Adt(adt, _) =
+ self.tcx.type_of(path.def_id()).instantiate_identity().kind()
+ && adt.is_fundamental()
+ {
for ty in generics {
if let Some(did) = ty.def_id(self.cache) {
dids.insert(did);
diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs
index def3a90c8..e80da46ad 100644
--- a/src/librustdoc/formats/item_type.rs
+++ b/src/librustdoc/formats/item_type.rs
@@ -16,6 +16,13 @@ use crate::clean;
/// Consequently, every change to this type should be synchronized to
/// the `itemTypes` mapping table in `html/static/js/search.js`.
///
+/// The search engine in search.js also uses item type numbers as a tie breaker when
+/// sorting results. Keywords and primitives are given first because we want them to be easily
+/// found by new users who don't know about advanced features like type filters. The rest are
+/// mostly in an arbitrary order, but it's easier to test the search engine when
+/// it's deterministic, and these are strictly finer-grained than language namespaces, so
+/// using the path and the item type together to sort ensures that search sorting is stable.
+///
/// In addition, code in `html::render` uses this enum to generate CSS classes, page prefixes, and
/// module headings. If you are adding to this enum and want to ensure that the sidebar also prints
/// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an
@@ -23,32 +30,34 @@ use crate::clean;
#[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)]
#[repr(u8)]
pub(crate) enum ItemType {
- Module = 0,
- ExternCrate = 1,
- Import = 2,
- Struct = 3,
- Enum = 4,
- Function = 5,
- TypeAlias = 6,
- Static = 7,
- Trait = 8,
- Impl = 9,
- TyMethod = 10,
- Method = 11,
- StructField = 12,
- Variant = 13,
- Macro = 14,
- Primitive = 15,
- AssocType = 16,
- Constant = 17,
- AssocConst = 18,
- Union = 19,
- ForeignType = 20,
- Keyword = 21,
+ Keyword = 0,
+ Primitive = 1,
+ Module = 2,
+ ExternCrate = 3,
+ Import = 4,
+ Struct = 5,
+ Enum = 6,
+ Function = 7,
+ TypeAlias = 8,
+ Static = 9,
+ Trait = 10,
+ Impl = 11,
+ TyMethod = 12,
+ Method = 13,
+ StructField = 14,
+ Variant = 15,
+ Macro = 16,
+ AssocType = 17,
+ Constant = 18,
+ AssocConst = 19,
+ Union = 20,
+ ForeignType = 21,
OpaqueTy = 22,
ProcAttribute = 23,
ProcDerive = 24,
TraitAlias = 25,
+ // This number is reserved for use in JavaScript
+ // Generic = 26,
}
impl Serialize for ItemType {
@@ -140,8 +149,7 @@ impl From<DefKind> for ItemType {
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Impl { .. }
- | DefKind::Closure
- | DefKind::Coroutine => Self::ForeignType,
+ | DefKind::Closure => Self::ForeignType,
}
}
}
diff --git a/src/librustdoc/formats/mod.rs b/src/librustdoc/formats/mod.rs
index e607a16ad..0056fb485 100644
--- a/src/librustdoc/formats/mod.rs
+++ b/src/librustdoc/formats/mod.rs
@@ -9,21 +9,6 @@ pub(crate) use renderer::{run_format, FormatRenderer};
use crate::clean::{self, ItemId};
use crate::html::render::Context;
-/// Specifies whether rendering directly implemented trait items or ones from a certain Deref
-/// impl.
-pub(crate) enum AssocItemRender<'a> {
- All,
- DerefFor { trait_: &'a clean::Path, type_: &'a clean::Type, deref_mut_: bool },
-}
-
-/// For different handling of associated items from the Deref target of a type rather than the type
-/// itself.
-#[derive(Copy, Clone, PartialEq)]
-pub(crate) enum RenderMode {
- Normal,
- ForDeref { mut_: bool },
-}
-
/// Metadata about implementations for a type or trait.
#[derive(Clone, Debug)]
pub(crate) struct Impl {
diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs
index c49f1a4d3..2535668b8 100644
--- a/src/librustdoc/formats/renderer.rs
+++ b/src/librustdoc/formats/renderer.rs
@@ -1,5 +1,4 @@
use rustc_middle::ty::TyCtxt;
-use rustc_span::Symbol;
use crate::clean;
use crate::config::RenderOptions;
@@ -68,7 +67,6 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
// Render the crate documentation
let mut work = vec![(format_renderer.make_child_renderer(), krate.module)];
- let unknown = Symbol::intern("<unknown item>");
while let Some((mut cx, item)) = work.pop() {
if item.is_mod() && T::RUN_ON_MODULE {
// modules are special because they add a namespace. We also need to
@@ -90,8 +88,10 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
cx.mod_item_out()?;
// FIXME: checking `item.name.is_some()` is very implicit and leads to lots of special
// cases. Use an explicit match instead.
- } else if item.name.is_some() && !item.is_extern_crate() {
- prof.generic_activity_with_arg("render_item", item.name.unwrap_or(unknown).as_str())
+ } else if let Some(item_name) = item.name
+ && !item.is_extern_crate()
+ {
+ prof.generic_activity_with_arg("render_item", item_name.as_str())
.run(|| cx.item(item))?;
}
}