Skip to content

rustdoc: Remove Crate.primitives #90447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@ impl From<DefId> for ItemId {
crate struct Crate {
crate module: Item,
crate externs: Vec<ExternalCrate>,
crate primitives: ThinVec<(DefId, PrimitiveType)>,
/// Only here so that they can be filtered through the rustdoc passes.
crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
crate collapsed: bool,
}

// `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Crate, 104);
rustc_data_structures::static_assert_size!(Crate, 96);

impl Crate {
crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol {
Expand Down
8 changes: 1 addition & 7 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
}));
}

Crate {
module,
externs,
primitives,
external_traits: cx.external_traits.clone(),
collapsed: false,
}
Crate { module, externs, external_traits: cx.external_traits.clone(), collapsed: false }
}

fn external_generic_args(
Expand Down
15 changes: 3 additions & 12 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
(synth.fold_crate(krate), synth.impls)
});

let prims: FxHashSet<PrimitiveType> = krate.primitives.iter().map(|p| p.1).collect();

let crate_items = {
let mut coll = ItemCollector::new();
krate = cx.sess().time("collect_items_for_trait_impls", || coll.fold_crate(krate));
Expand Down Expand Up @@ -51,7 +49,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
}
}

let mut cleaner = BadImplStripper { prims, items: crate_items };
let mut cleaner = BadImplStripper { items: crate_items };
let mut type_did_to_deref_target: FxHashMap<DefId, &Type> = FxHashMap::default();

// Follow all `Deref` targets of included items and recursively add them as valid
Expand All @@ -62,9 +60,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
) {
if let Some(target) = map.get(&type_did) {
debug!("add_deref_target: type {:?}, target {:?}", type_did, target);
if let Some(target_prim) = target.primitive_type() {
cleaner.prims.insert(target_prim);
} else if let Some(target_did) = target.def_id_no_primitives() {
if let Some(target_did) = target.def_id_no_primitives() {
// `impl Deref<Target = S> for S`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This in particular makes me worried we'll no longer show Deref methods if an item derefs to a primitive type. Can you add a test for that case?

if target_did == type_did {
// Avoid infinite cycles
Expand All @@ -90,9 +86,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
})
.expect("Deref impl without Target type");

if let Some(prim) = target.primitive_type() {
cleaner.prims.insert(prim);
} else if let Some(did) = target.def_id(&cx.cache) {
if let Some(did) = target.def_id(&cx.cache) {
cleaner.items.insert(did.into());
}
if let Some(for_did) = for_.def_id_no_primitives() {
Expand Down Expand Up @@ -208,7 +202,6 @@ impl DocFolder for ItemCollector {
}

struct BadImplStripper {
prims: FxHashSet<PrimitiveType>,
items: FxHashSet<ItemId>,
}

Expand All @@ -217,8 +210,6 @@ impl BadImplStripper {
if let Generic(_) = ty {
// keep impls made on generics
true
} else if let Some(prim) = ty.primitive_type() {
self.prims.contains(&prim)
} else if let Some(did) = ty.def_id_no_primitives() {
is_deref || self.keep_impl_with_def_id(did.into())
} else {
Expand Down