11//! Support for inlining external documentation into the current AST.
22
3+ use std:: alloc:: Allocator ;
34use std:: iter:: once;
45use std:: sync:: Arc ;
56
@@ -38,15 +39,15 @@ use crate::formats::item_type::ItemType;
3839///
3940/// The returned value is `None` if the definition could not be inlined,
4041/// and `Some` of a vector of items if it was successfully expanded.
41- pub ( crate ) fn try_inline (
42- cx : & mut DocContext < ' _ > ,
42+ pub ( crate ) fn try_inline < A : Allocator + Copy > (
43+ cx : & mut DocContext < ' _ , A > ,
4344 res : Res ,
4445 name : Symbol ,
4546 attrs : Option < ( & [ hir:: Attribute ] , Option < LocalDefId > ) > ,
4647 visited : & mut DefIdSet ,
4748) -> Option < Vec < clean:: Item > > {
48- fn try_inline_inner (
49- cx : & mut DocContext < ' _ > ,
49+ fn try_inline_inner < A : Allocator + Copy > (
50+ cx : & mut DocContext < ' _ , A > ,
5051 kind : clean:: ItemKind ,
5152 did : DefId ,
5253 name : Symbol ,
@@ -178,8 +179,8 @@ pub(crate) fn try_inline(
178179 Some ( ret)
179180}
180181
181- pub ( crate ) fn try_inline_glob (
182- cx : & mut DocContext < ' _ > ,
182+ pub ( crate ) fn try_inline_glob < A : Allocator + Copy > (
183+ cx : & mut DocContext < ' _ , A > ,
183184 res : Res ,
184185 current_mod : LocalModDefId ,
185186 visited : & mut DefIdSet ,
@@ -266,7 +267,11 @@ pub(crate) fn get_item_path(tcx: TyCtxt<'_>, def_id: DefId, kind: ItemType) -> V
266267///
267268/// These names are used later on by HTML rendering to generate things like
268269/// source links back to the original item.
269- pub ( crate ) fn record_extern_fqn ( cx : & mut DocContext < ' _ > , did : DefId , kind : ItemType ) {
270+ pub ( crate ) fn record_extern_fqn < A : Allocator + Copy > (
271+ cx : & mut DocContext < ' _ , A > ,
272+ did : DefId ,
273+ kind : ItemType ,
274+ ) {
270275 if did. is_local ( ) {
271276 if cx. cache . exact_paths . contains_key ( & did) {
272277 return ;
@@ -284,7 +289,10 @@ pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemT
284289 }
285290}
286291
287- pub ( crate ) fn build_trait ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Trait {
292+ pub ( crate ) fn build_trait < A : Allocator + Copy > (
293+ cx : & mut DocContext < ' _ , A > ,
294+ did : DefId ,
295+ ) -> clean:: Trait {
288296 let trait_items = cx
289297 . tcx
290298 . associated_items ( did)
@@ -305,7 +313,10 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
305313 clean:: Trait { def_id : did, generics, items : trait_items, bounds : supertrait_bounds }
306314}
307315
308- fn build_trait_alias ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: TraitAlias {
316+ fn build_trait_alias < A : Allocator + Copy > (
317+ cx : & mut DocContext < ' _ , A > ,
318+ did : DefId ,
319+ ) -> clean:: TraitAlias {
309320 let generics = clean_ty_generics ( cx, did) ;
310321 let ( generics, mut bounds) = separate_self_bounds ( generics) ;
311322
@@ -318,7 +329,10 @@ fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
318329 clean:: TraitAlias { generics, bounds }
319330}
320331
321- pub ( super ) fn build_function ( cx : & mut DocContext < ' _ > , def_id : DefId ) -> Box < clean:: Function > {
332+ pub ( super ) fn build_function < A : Allocator + Copy > (
333+ cx : & mut DocContext < ' _ , A > ,
334+ def_id : DefId ,
335+ ) -> Box < clean:: Function > {
322336 let sig = cx. tcx . fn_sig ( def_id) . instantiate_identity ( ) . skip_norm_wip ( ) ;
323337 // The generics need to be cleaned before the signature.
324338 let mut generics = clean_ty_generics ( cx, def_id) ;
@@ -349,14 +363,14 @@ pub(super) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clea
349363 Box :: new ( clean:: Function { decl, generics } )
350364}
351365
352- fn build_enum ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Enum {
366+ fn build_enum < A : Allocator + Copy > ( cx : & mut DocContext < ' _ , A > , did : DefId ) -> clean:: Enum {
353367 clean:: Enum {
354368 generics : clean_ty_generics ( cx, did) ,
355369 variants : cx. tcx . adt_def ( did) . variants ( ) . iter ( ) . map ( |v| clean_variant_def ( v, cx) ) . collect ( ) ,
356370 }
357371}
358372
359- fn build_struct ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Struct {
373+ fn build_struct < A : Allocator + Copy > ( cx : & mut DocContext < ' _ , A > , did : DefId ) -> clean:: Struct {
360374 let variant = cx. tcx . adt_def ( did) . non_enum_variant ( ) ;
361375
362376 clean:: Struct {
@@ -366,16 +380,16 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
366380 }
367381}
368382
369- fn build_union ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Union {
383+ fn build_union < A : Allocator + Copy > ( cx : & mut DocContext < ' _ , A > , did : DefId ) -> clean:: Union {
370384 let variant = cx. tcx . adt_def ( did) . non_enum_variant ( ) ;
371385
372386 let generics = clean_ty_generics ( cx, did) ;
373387 let fields = variant. fields . iter ( ) . map ( |x| clean_middle_field ( x, cx) ) . collect ( ) ;
374388 clean:: Union { generics, fields }
375389}
376390
377- fn build_type_alias (
378- cx : & mut DocContext < ' _ > ,
391+ fn build_type_alias < A : Allocator + Copy > (
392+ cx : & mut DocContext < ' _ , A > ,
379393 did : DefId ,
380394 ret : & mut Vec < Item > ,
381395) -> Box < clean:: TypeAlias > {
@@ -392,8 +406,8 @@ fn build_type_alias(
392406}
393407
394408/// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport.
395- pub ( crate ) fn build_impls (
396- cx : & mut DocContext < ' _ > ,
409+ pub ( crate ) fn build_impls < A : Allocator + Copy > (
410+ cx : & mut DocContext < ' _ , A > ,
397411 did : DefId ,
398412 attrs : Option < ( & [ hir:: Attribute ] , Option < LocalDefId > ) > ,
399413 ret : & mut Vec < clean:: Item > ,
@@ -452,8 +466,8 @@ pub(crate) fn merge_attrs(
452466}
453467
454468/// Inline an `impl`, inherent or of a trait. The `did` must be for an `impl`.
455- pub ( crate ) fn build_impl (
456- cx : & mut DocContext < ' _ > ,
469+ pub ( crate ) fn build_impl < A : Allocator + Copy > (
470+ cx : & mut DocContext < ' _ , A > ,
457471 did : DefId ,
458472 attrs : Option < ( & [ hir:: Attribute ] , Option < LocalDefId > ) > ,
459473 ret : & mut Vec < clean:: Item > ,
@@ -473,7 +487,7 @@ pub(crate) fn build_impl(
473487 . is_some_and ( |stab| stab. is_unstable ( ) && stab. feature == sym:: rustc_private)
474488 } ;
475489 let document_compiler_internal = is_compiler_internal ( LOCAL_CRATE . as_def_id ( ) ) ;
476- let is_directly_public = |cx : & mut DocContext < ' _ > , did| {
490+ let is_directly_public = |cx : & mut DocContext < ' _ , A > , did| {
477491 cx. cache . effective_visibilities . is_directly_public ( tcx, did)
478492 && ( document_compiler_internal || !is_compiler_internal ( did) )
479493 } ;
@@ -665,15 +679,19 @@ pub(crate) fn build_impl(
665679 ) ) ;
666680}
667681
668- fn build_module ( cx : & mut DocContext < ' _ > , did : DefId , visited : & mut DefIdSet ) -> clean:: Module {
682+ fn build_module < A : Allocator + Copy > (
683+ cx : & mut DocContext < ' _ , A > ,
684+ did : DefId ,
685+ visited : & mut DefIdSet ,
686+ ) -> clean:: Module {
669687 let items = build_module_items ( cx, did, visited, & mut FxHashSet :: default ( ) , None , None ) ;
670688
671689 let span = clean:: Span :: new ( cx. tcx . def_span ( did) ) ;
672690 clean:: Module { items, span }
673691}
674692
675- fn build_module_items (
676- cx : & mut DocContext < ' _ > ,
693+ fn build_module_items < A : Allocator + Copy > (
694+ cx : & mut DocContext < ' _ , A > ,
677695 did : DefId ,
678696 visited : & mut DefIdSet ,
679697 inlined_names : & mut FxHashSet < ( ItemType , Symbol ) > ,
@@ -755,7 +773,10 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
755773 }
756774}
757775
758- fn build_const_item ( cx : & mut DocContext < ' _ > , def_id : DefId ) -> clean:: Constant {
776+ fn build_const_item < A : Allocator + Copy > (
777+ cx : & mut DocContext < ' _ , A > ,
778+ def_id : DefId ,
779+ ) -> clean:: Constant {
759780 let mut generics = clean_ty_generics ( cx, def_id) ;
760781 clean:: simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
761782 let ty = clean_middle_ty (
@@ -767,7 +788,11 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
767788 clean:: Constant { generics, type_ : ty, kind : clean:: ConstantKind :: Extern { def_id } }
768789}
769790
770- fn build_static ( cx : & mut DocContext < ' _ > , did : DefId , mutable : bool ) -> clean:: Static {
791+ fn build_static < A : Allocator + Copy > (
792+ cx : & mut DocContext < ' _ , A > ,
793+ did : DefId ,
794+ mutable : bool ,
795+ ) -> clean:: Static {
771796 clean:: Static {
772797 type_ : Box :: new ( clean_middle_ty (
773798 ty:: Binder :: dummy ( cx. tcx . type_of ( did) . instantiate_identity ( ) . skip_norm_wip ( ) ) ,
@@ -829,7 +854,7 @@ fn separate_self_bounds(mut g: clean::Generics) -> (clean::Generics, Vec<clean::
829854 ( g, ty_bounds)
830855}
831856
832- pub ( crate ) fn record_extern_trait ( cx : & mut DocContext < ' _ > , did : DefId ) {
857+ pub ( crate ) fn record_extern_trait < A : Allocator + Copy > ( cx : & mut DocContext < ' _ , A > , did : DefId ) {
833858 if did. is_local ( )
834859 || cx. external_traits . contains_key ( & did)
835860 || cx. active_extern_traits . contains ( & did)
0 commit comments