From 5856e408859e37c4a2173ad4f9f146b0792b5859 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 27 Nov 2022 16:31:34 +0100 Subject: [PATCH 1/2] Remove Crate::primitives field --- src/librustdoc/clean/types.rs | 3 +-- src/librustdoc/clean/utils.rs | 2 +- src/librustdoc/passes/collect_trait_impls.rs | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 340d6d7df180f..2894b19877cc7 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -115,7 +115,6 @@ impl From for ItemId { #[derive(Clone, Debug)] pub(crate) struct Crate { pub(crate) module: Item, - pub(crate) primitives: ThinVec<(DefId, PrimitiveType)>, /// Only here so that they can be filtered through the rustdoc passes. pub(crate) external_traits: Rc>>, } @@ -2572,7 +2571,7 @@ mod size_asserts { use super::*; use rustc_data_structures::static_assert_size; // tidy-alphabetical-start - static_assert_size!(Crate, 72); // frequently moved by-value + static_assert_size!(Crate, 64); // frequently moved by-value static_assert_size!(DocFragment, 32); static_assert_size!(GenericArg, 32); static_assert_size!(GenericArgs, 32); diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 35e2720fdff89..3c48dd80b6fc5 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -73,7 +73,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate { })); } - Crate { module, primitives, external_traits: cx.external_traits.clone() } + Crate { module, external_traits: cx.external_traits.clone() } } pub(crate) fn substs_to_args<'tcx>( diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 6b699c7901434..d57f981d51a84 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -8,7 +8,7 @@ use crate::formats::cache::Cache; use crate::visit::DocVisitor; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::ty::{self, DefIdTree}; use rustc_span::symbol::sym; @@ -25,7 +25,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> synth.impls }); - let prims: FxHashSet = krate.primitives.iter().map(|p| p.1).collect(); + let local_crate = ExternalCrate { crate_num: LOCAL_CRATE }; + let prims: FxHashSet = + local_crate.primitives(cx.tcx).iter().map(|p| p.1).collect(); let crate_items = { let mut coll = ItemCollector::new(); From 23c3941942ef1ea3cf2980e385235463add95460 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 27 Nov 2022 16:31:52 +0100 Subject: [PATCH 2/2] Add rustdoc test for Deref to primitive types --- src/test/rustdoc/deref-to-primitive.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/rustdoc/deref-to-primitive.rs diff --git a/src/test/rustdoc/deref-to-primitive.rs b/src/test/rustdoc/deref-to-primitive.rs new file mode 100644 index 0000000000000..527de780d4892 --- /dev/null +++ b/src/test/rustdoc/deref-to-primitive.rs @@ -0,0 +1,15 @@ +#![crate_name = "foo"] + +// @has 'foo/struct.Foo.html' +// @has - '//*[@id="deref-methods-i32"]' 'Methods from Deref' +// @has - '//*[@id="deref-methods-i32-1"]//*[@id="associatedconstant.BITS"]/h4' \ +// 'pub const BITS: u32 = 32u32' +pub struct Foo(i32); + +impl std::ops::Deref for Foo { + type Target = i32; + + fn deref(&self) -> &Self::Target { + &self.0 + } +}