Skip to content

Commit 76cd3ba

Browse files
committed
No need to store crate num twice
1 parent 90ef94e commit 76cd3ba

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/librustdoc/clean/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1717
use rustc_feature::UnstableFeatures;
1818
use rustc_hir as hir;
1919
use rustc_hir::def::{CtorKind, Res};
20-
use rustc_hir::def_id::{CrateNum, DefId};
20+
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
2121
use rustc_hir::lang_items::LangItem;
2222
use rustc_hir::Mutability;
2323
use rustc_index::vec::IndexVec;
@@ -45,7 +45,7 @@ use self::ItemKind::*;
4545
use self::SelfTy::*;
4646
use self::Type::*;
4747

48-
thread_local!(crate static MAX_DEF_ID: RefCell<FxHashMap<CrateNum, DefId>> = Default::default());
48+
thread_local!(crate static MAX_DEF_IDX: RefCell<FxHashMap<CrateNum, DefIndex>> = Default::default());
4949

5050
#[derive(Clone, Debug)]
5151
crate struct Crate {
@@ -293,8 +293,8 @@ impl Item {
293293
///
294294
/// [`next_def_id()`]: DocContext::next_def_id()
295295
crate fn is_fake(&self) -> bool {
296-
MAX_DEF_ID.with(|m| {
297-
m.borrow().get(&self.def_id.krate).map(|id| self.def_id >= *id).unwrap_or(false)
296+
MAX_DEF_IDX.with(|m| {
297+
m.borrow().get(&self.def_id.krate).map(|&idx| idx <= self.def_id.index).unwrap_or(false)
298298
})
299299
}
300300
}

src/librustdoc/core.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::{
3232
};
3333

3434
use crate::clean;
35-
use crate::clean::{AttributesExt, MAX_DEF_ID};
35+
use crate::clean::{AttributesExt, MAX_DEF_IDX};
3636
use crate::config::{Options as RustdocOptions, RenderOptions};
3737
use crate::config::{OutputFormat, RenderInfo};
3838
use crate::formats::cache::Cache;
@@ -66,7 +66,7 @@ crate struct DocContext<'tcx> {
6666
crate ct_substs: RefCell<FxHashMap<DefId, clean::Constant>>,
6767
/// Table synthetic type parameter for `impl Trait` in argument position -> bounds
6868
crate impl_trait_bounds: RefCell<FxHashMap<ImplTraitParam, Vec<clean::GenericBound>>>,
69-
crate fake_def_ids: RefCell<FxHashMap<CrateNum, DefId>>,
69+
crate fake_def_ids: RefCell<FxHashMap<CrateNum, DefIndex>>,
7070
/// Auto-trait or blanket impls processed so far, as `(self_ty, trait_def_id)`.
7171
// FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set.
7272
crate generated_synthetics: RefCell<FxHashSet<(Ty<'tcx>, DefId)>>,
@@ -142,35 +142,35 @@ impl<'tcx> DocContext<'tcx> {
142142
crate fn next_def_id(&self, crate_num: CrateNum) -> DefId {
143143
let mut fake_ids = self.fake_def_ids.borrow_mut();
144144

145-
let def_id = match fake_ids.entry(crate_num) {
145+
let def_index = match fake_ids.entry(crate_num) {
146146
Entry::Vacant(e) => {
147-
let start_def_id = {
148-
let num_def_ids = if crate_num == LOCAL_CRATE {
147+
let num_def_idx = {
148+
let num_def_idx = if crate_num == LOCAL_CRATE {
149149
self.tcx.hir().definitions().def_path_table().num_def_ids()
150150
} else {
151151
self.enter_resolver(|r| r.cstore().num_def_ids(crate_num))
152152
};
153153

154-
DefId { krate: crate_num, index: DefIndex::from_usize(num_def_ids) }
154+
DefIndex::from_usize(num_def_idx)
155155
};
156156

157-
MAX_DEF_ID.with(|m| {
158-
m.borrow_mut().insert(crate_num, start_def_id);
157+
MAX_DEF_IDX.with(|m| {
158+
m.borrow_mut().insert(crate_num, num_def_idx);
159159
});
160-
e.insert(start_def_id)
160+
e.insert(num_def_idx)
161161
}
162162
Entry::Occupied(e) => e.into_mut(),
163163
};
164-
*def_id = DefId { krate: crate_num, index: DefIndex::from(def_id.index.index() + 1) };
164+
*def_index = DefIndex::from(*def_index + 1);
165165

166-
*def_id
166+
DefId { krate: crate_num, index: *def_index }
167167
}
168168

169169
/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
170170
/// (This avoids a slice-index-out-of-bounds panic.)
171171
crate fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
172-
if MAX_DEF_ID.with(|m| {
173-
m.borrow().get(&def_id.krate).map(|id| id.index <= def_id.index).unwrap_or(false)
172+
if MAX_DEF_IDX.with(|m| {
173+
m.borrow().get(&def_id.krate).map(|&idx| idx <= def_id.index).unwrap_or(false)
174174
}) {
175175
None
176176
} else {

0 commit comments

Comments
 (0)