Skip to content

Commit 0dd2703

Browse files
zredbGuillaumeGomez
authored andcommitted
1 parent ff88b59 commit 0dd2703

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ impl ExternalCrate {
338338
}
339339

340340
/// Indicates where an external crate can be found.
341+
#[derive(Debug)]
341342
crate enum ExternalLocation {
342343
/// Remote URL root of the external crate
343344
Remote(String),

src/librustdoc/formats/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::html::render::IndexItem;
2525
/// to be a fairly large and expensive structure to clone. Instead this adheres
2626
/// to `Send` so it may be stored in an `Arc` instance and shared among the various
2727
/// rendering threads.
28-
#[derive(Default)]
28+
#[derive(Default, Debug)]
2929
crate struct Cache {
3030
/// Maps a type ID to all known implementations for that type. This is only
3131
/// recognized for intra-crate [`clean::Type::Path`]s, and is used to print

src/librustdoc/html/render/search_index.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,14 @@ fn add_generics_and_bounds_as_types<'tcx>(
248248
tcx: TyCtxt<'tcx>,
249249
recurse: usize,
250250
res: &mut Vec<TypeWithKind>,
251+
cache: &Cache,
251252
) {
252253
fn insert_ty(
253254
res: &mut Vec<TypeWithKind>,
254255
tcx: TyCtxt<'_>,
255256
ty: Type,
256257
mut generics: Vec<TypeWithKind>,
258+
cache: &Cache,
257259
) {
258260
let is_full_generic = ty.is_full_generic();
259261

@@ -347,14 +349,15 @@ fn add_generics_and_bounds_as_types<'tcx>(
347349
tcx,
348350
recurse + 1,
349351
&mut ty_generics,
352+
cache,
350353
)
351354
}
352355
_ => {}
353356
}
354357
}
355358
}
356359
}
357-
insert_ty(res, tcx, arg.clone(), ty_generics);
360+
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
358361
}
359362
// Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
360363
if let Some(bound) = generics.params.iter().find(|g| g.is_type() && g.name == arg_s) {
@@ -368,10 +371,11 @@ fn add_generics_and_bounds_as_types<'tcx>(
368371
tcx,
369372
recurse + 1,
370373
&mut ty_generics,
374+
cache,
371375
);
372376
}
373377
}
374-
insert_ty(res, tcx, arg.clone(), ty_generics);
378+
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
375379
}
376380
} else {
377381
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
@@ -382,10 +386,17 @@ fn add_generics_and_bounds_as_types<'tcx>(
382386
let mut ty_generics = Vec::new();
383387
if let Some(arg_generics) = arg.generics() {
384388
for gen in arg_generics.iter() {
385-
add_generics_and_bounds_as_types(generics, gen, tcx, recurse + 1, &mut ty_generics);
389+
add_generics_and_bounds_as_types(
390+
generics,
391+
gen,
392+
tcx,
393+
recurse + 1,
394+
&mut ty_generics,
395+
cache,
396+
);
386397
}
387398
}
388-
insert_ty(res, tcx, arg.clone(), ty_generics);
399+
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
389400
}
390401
}
391402

@@ -407,7 +418,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
407418
continue;
408419
}
409420
let mut args = Vec::new();
410-
add_generics_and_bounds_as_types(generics, &arg.type_, tcx, 0, &mut args);
421+
add_generics_and_bounds_as_types(generics, &arg.type_, tcx, 0, &mut args, cache);
411422
if !args.is_empty() {
412423
all_types.extend(args);
413424
} else {
@@ -420,7 +431,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
420431
let mut ret_types = Vec::new();
421432
match decl.output {
422433
FnRetTy::Return(ref return_type) => {
423-
add_generics_and_bounds_as_types(generics, return_type, tcx, 0, &mut ret_types);
434+
add_generics_and_bounds_as_types(generics, return_type, tcx, 0, &mut ret_types, cache);
424435
if ret_types.is_empty() {
425436
if let Some(kind) = return_type.def_id(cache).map(|did| tcx.def_kind(did).into()) {
426437
ret_types.push(TypeWithKind::from((get_index_type(return_type, vec![]), kind)));

src/librustdoc/passes/collect_trait_impls.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use super::Pass;
55
use crate::clean::*;
66
use crate::core::DocContext;
7+
use crate::formats::cache::Cache;
78
use crate::visit::DocVisitor;
89

910
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -57,14 +58,14 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
5758
}
5859
});
5960

60-
let mut cleaner = BadImplStripper { prims, items: crate_items };
61+
let mut cleaner = BadImplStripper { prims, items: crate_items, cache: &cx.cache };
6162
let mut type_did_to_deref_target: FxHashMap<DefId, &Type> = FxHashMap::default();
6263

6364
// Follow all `Deref` targets of included items and recursively add them as valid
6465
fn add_deref_target(
6566
cx: &DocContext<'_>,
6667
map: &FxHashMap<DefId, &Type>,
67-
cleaner: &mut BadImplStripper,
68+
cleaner: &mut BadImplStripper<'_>,
6869
type_did: DefId,
6970
) {
7071
if let Some(target) = map.get(&type_did) {
@@ -204,19 +205,20 @@ impl DocVisitor for ItemCollector {
204205
}
205206
}
206207

207-
struct BadImplStripper {
208+
struct BadImplStripper<'a> {
208209
prims: FxHashSet<PrimitiveType>,
209210
items: FxHashSet<ItemId>,
211+
crate cache: &'a Cache,
210212
}
211213

212-
impl BadImplStripper {
214+
impl<'a> BadImplStripper<'a> {
213215
fn keep_impl(&self, ty: &Type, is_deref: bool) -> bool {
214216
if let Generic(_) = ty {
215217
// keep impls made on generics
216218
true
217219
} else if let Some(prim) = ty.primitive_type() {
218220
self.prims.contains(&prim)
219-
} else if let Some(did) = ty.def_id(&cx.cache) {
221+
} else if let Some(did) = ty.def_id(self.cache) {
220222
is_deref || self.keep_impl_with_def_id(did.into())
221223
} else {
222224
false

src/librustdoc/passes/strip_hidden.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate const STRIP_HIDDEN: Pass = Pass {
1515
};
1616

1717
/// Strip items marked `#[doc(hidden)]`
18-
crate fn strip_hidden(krate: clean::Crate, _: &mut DocContext<'_>) -> clean::Crate {
18+
crate fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
1919
let mut retained = ItemIdSet::default();
2020

2121
// strip all #[doc(hidden)] items
@@ -25,7 +25,7 @@ crate fn strip_hidden(krate: clean::Crate, _: &mut DocContext<'_>) -> clean::Cra
2525
};
2626

2727
// strip all impls referencing stripped items
28-
let mut stripper = ImplStripper { retained: &retained };
28+
let mut stripper = ImplStripper { retained: &retained, cache: &cx.cache };
2929
stripper.fold_crate(krate)
3030
}
3131

src/librustdoc/passes/strip_private.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ crate fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clea
2929
}
3030

3131
// strip all impls referencing private items
32-
let mut stripper = ImplStripper { retained: &retained };
32+
let mut stripper = ImplStripper { retained: &retained, cache: &cx.cache };
3333
stripper.fold_crate(krate)
3434
}

src/librustdoc/passes/stripper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::mem;
55

66
use crate::clean::{self, Item, ItemIdSet};
77
use crate::fold::{strip_item, DocFolder};
8+
use crate::formats::cache::Cache;
89

910
crate struct Stripper<'a> {
1011
crate retained: &'a mut ItemIdSet,

0 commit comments

Comments
 (0)