Skip to content

Commit

Permalink
Rollup merge of rust-lang#104984 - GuillaumeGomez:remote-crate-primit…
Browse files Browse the repository at this point in the history
…ives, r=notriddle

Remove Crate::primitives field

It is a new approach to rust-lang#90447. Instead of removing primitives from everywhere (ie from `BadImplStripper`), I just removed them from the `Crate` type, allowing to reduce its size.

cc `@camelid`
r? `@notriddle`
  • Loading branch information
matthiaskrgr authored Nov 27, 2022
2 parents 86304f5 + 23c3941 commit 5ea36cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ impl From<DefId> 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<RefCell<FxHashMap<DefId, Trait>>>,
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +25,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
synth.impls
});

let prims: FxHashSet<PrimitiveType> = krate.primitives.iter().map(|p| p.1).collect();
let local_crate = ExternalCrate { crate_num: LOCAL_CRATE };
let prims: FxHashSet<PrimitiveType> =
local_crate.primitives(cx.tcx).iter().map(|p| p.1).collect();

let crate_items = {
let mut coll = ItemCollector::new();
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc/deref-to-primitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![crate_name = "foo"]

// @has 'foo/struct.Foo.html'
// @has - '//*[@id="deref-methods-i32"]' 'Methods from Deref<Target = i32>'
// @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
}
}

0 comments on commit 5ea36cf

Please sign in to comment.